Skip to content

Commit

Permalink
Merge branch 'main' into feat/goreleaser
Browse files Browse the repository at this point in the history
  • Loading branch information
spatocode authored Sep 26, 2023
2 parents 4622241 + 8c1a908 commit 914c96d
Show file tree
Hide file tree
Showing 12 changed files with 106 additions and 51 deletions.
30 changes: 28 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,31 @@
# Jerm

Jerm deploys serverless apps to the cloud
Jerm is an open source tool that helps you deploy serverless apps seamlessly across all clouds.

Note: Still under early development.
## Quickstart

This guide will get you up and running in a few minutes.

### Install

To install Jerm run

```
$ go install github.com/spatocode/jerm/cmd/jerm@latest
```

### Usage

Deploy your app

```
$ jerm deploy
```

## Contributing

Jerm is still under early development and all contributions are welcomed.

## License

Jerm is licensed under the [BSD-3-Clause license](https://github.com/spatocode/jerm/blob/main/LICENSE)
3 changes: 3 additions & 0 deletions cloud/aws/access.go
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,9 @@ func (i *IAM) getIAMRole() (*iamTypes.Role, error) {
if errors.As(err, &nseErr) {
log.Debug("IAM role not found. creating new IAM role ...")
resp, err := i.createIAMRole()
if err != nil {
return nil, err
}
return resp.Role, err
}
return nil, err
Expand Down
4 changes: 4 additions & 0 deletions cloud/aws/apigateway.go
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,10 @@ func (a *ApiGateway) getRestApis() ([]*string, error) {
resp, err := apiGatewayClient.GetRestApis(context.TODO(), &apigateway.GetRestApisInput{
Limit: aws.Int32(500),
})
if err != nil {
return nil, err
}

for _, item := range resp.Items {
if *item.Name == a.config.GetFunctionName() {
apiIds = append(apiIds, item.Id)
Expand Down
1 change: 1 addition & 0 deletions cloud/aws/handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package aws

const (
awsLambdaHandler = `
import sys
import json
import io
import logging
Expand Down
10 changes: 5 additions & 5 deletions cloud/aws/lambda.go
Original file line number Diff line number Diff line change
Expand Up @@ -105,16 +105,16 @@ func (l *Lambda) Build() (string, error) {
}()

handler, err := r.Build(l.config)
dir := filepath.Dir(handler)
if err != nil {
return "", err
}

dir := filepath.Dir(handler)

if l.config.Lambda.Handler == "" {
err := l.CreateFunctionEntry(handler)
return dir, err
err = l.CreateFunctionEntry(handler)
}
return dir, nil
return dir, err
}

func (l *Lambda) Invoke(command string) error {
Expand All @@ -126,7 +126,7 @@ func (l *Lambda) Invoke(command string) error {
func (l *Lambda) invokeLambdaFunction(payload []byte) error {
client := lambda.NewFromConfig(l.awsConfig)
out, err := client.Invoke(context.TODO(), &lambda.InvokeInput{
FunctionName: &l.config.Name,
FunctionName: aws.String(l.config.GetFunctionName()),
InvocationType: lambdaTypes.InvocationTypeRequestResponse,
LogType: lambdaTypes.LogTypeTail,
Payload: payload,
Expand Down
11 changes: 3 additions & 8 deletions cmd/deploy.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import (

"github.com/spatocode/jerm"
"github.com/spatocode/jerm/cloud/aws"
"github.com/spatocode/jerm/config"
"github.com/spatocode/jerm/internal/log"
)

Expand All @@ -19,14 +18,10 @@ var deployCmd = &cobra.Command{
Run: func(cmd *cobra.Command, args []string) {
jerm.Verbose(cmd)

cfg, err := jerm.ReadConfig(jerm.DefaultConfigFile)
cfg, err := jerm.Configure(jerm.DefaultConfigFile)
if err != nil {
c := config.Config{}
cfg, err = c.PromptConfig()
if err != nil {
log.PrintError(err.Error())
return
}
log.PrintError(err.Error())
return
}

p, err := jerm.New(cfg)
Expand Down
15 changes: 5 additions & 10 deletions cmd/logs.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,6 @@ Copyright © 2023 Ekene Izukanne <[email protected]>
package cmd

import (
"errors"
"os"

"github.com/spf13/cobra"

"github.com/spatocode/jerm"
Expand All @@ -22,21 +19,19 @@ var statusCmd = &cobra.Command{
Run: func(cmd *cobra.Command, args []string) {
jerm.Verbose(cmd)

config, err := jerm.ReadConfig(jerm.DefaultConfigFile)
cfg, err := jerm.Configure(jerm.DefaultConfigFile)
if err != nil {
var pErr *os.PathError
if !errors.As(err, &pErr) {
log.PrintError(err.Error())
}
log.PrintError(err.Error())
return
}

p, err := jerm.New(config)
p, err := jerm.New(cfg)
if err != nil {
log.PrintError(err.Error())
return
}

platform, err := aws.NewLambda(config)
platform, err := aws.NewLambda(cfg)
if err != nil {
log.PrintError(err.Error())
return
Expand Down
10 changes: 3 additions & 7 deletions cmd/manage.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@ Copyright © 2023 Ekene Izukanne <[email protected]>
package cmd

import (
"errors"
"os"
"strings"

"github.com/spf13/cobra"
Expand All @@ -27,12 +25,10 @@ var manageCmd = &cobra.Command{
return
}

cfg, err := jerm.ReadConfig(jerm.DefaultConfigFile)
cfg, err := jerm.Configure(jerm.DefaultConfigFile)
if err != nil {
var pErr *os.PathError
if !errors.As(err, &pErr) {
log.PrintError(err.Error())
}
log.PrintError(err.Error())
return
}

platform, err := aws.NewLambda(cfg)
Expand Down
15 changes: 5 additions & 10 deletions cmd/rollback.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,6 @@ Copyright © 2023 Ekene Izukanne <[email protected]>
package cmd

import (
"errors"
"os"

"github.com/spf13/cobra"

"github.com/spatocode/jerm"
Expand All @@ -23,21 +20,19 @@ var rollbackCmd = &cobra.Command{
steps, _ := cmd.Flags().GetInt("steps")
jerm.Verbose(cmd)

config, err := jerm.ReadConfig(jerm.DefaultConfigFile)
cfg, err := jerm.Configure(jerm.DefaultConfigFile)
if err != nil {
var pErr *os.PathError
if !errors.As(err, &pErr) {
log.PrintError(err.Error())
}
log.PrintError(err.Error())
return
}

p, err := jerm.New(config)
p, err := jerm.New(cfg)
if err != nil {
log.PrintError(err.Error())
return
}

platform, err := aws.NewLambda(config)
platform, err := aws.NewLambda(cfg)
if err != nil {
log.PrintError(err.Error())
return
Expand Down
13 changes: 5 additions & 8 deletions cmd/undeploy.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ Copyright © 2023 Ekene Izukanne <[email protected]>
package cmd

import (
"errors"
"os"

"github.com/spf13/cobra"
Expand All @@ -23,21 +22,19 @@ var undeployCmd = &cobra.Command{
Run: func(cmd *cobra.Command, args []string) {
jerm.Verbose(cmd)

config, err := jerm.ReadConfig(jerm.DefaultConfigFile)
cfg, err := jerm.Configure(jerm.DefaultConfigFile)
if err != nil {
var pErr *os.PathError
if !errors.As(err, &pErr) {
log.PrintError(err.Error())
}
log.PrintError(err.Error())
return
}

p, err := jerm.New(config)
p, err := jerm.New(cfg)
if err != nil {
log.PrintError(err.Error())
return
}

platform, err := aws.NewLambda(config)
platform, err := aws.NewLambda(cfg)
if err != nil {
log.PrintError(err.Error())
return
Expand Down
20 changes: 19 additions & 1 deletion jerm.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ import (
type Config config.Config

const (
Version = "0.0.2"
Version = "0.1.2"
DefaultConfigFile = "jerm.json"
ArchiveFile = "jerm.zip"
)
Expand Down Expand Up @@ -213,10 +213,28 @@ func (p *Project) archivePackage(archivePath, dir string) (int64, error) {
}

info, err := archive.Stat()
if err != nil {
return 0, err
}

return info.Size(), err
}

// Configure sets up Jerm using jerm.json configuration file.
// If the configuration file is not found, it prompts the user for setup.
func Configure(configFile string) (*config.Config, error) {
cfg, err := ReadConfig(configFile)
if err != nil {
c := &config.Config{}
c, err = c.PromptConfig()
if err != nil {
return nil, err
}
return c, err
}
return cfg, err
}

func Verbose(cmd *cobra.Command) {
verbose, _ := cmd.Flags().GetBool("verbose")
if verbose {
Expand Down
25 changes: 25 additions & 0 deletions jerm_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
package jerm

import (
"testing"

"github.com/stretchr/testify/assert"
)

func TestJermConfigure(t *testing.T) {
assert := assert.New(t)
role := "arn:aws:iam::269360183919:role/bodystats-dev-JermTestLambdaServiceExecutionRole"
c, err := Configure("assets/tests/jerm.json")
assert.Nil(err)
assert.Equal("bodystats", c.Name)
assert.Equal("dev", c.Stage)
assert.Equal(512, c.Lambda.Memory)
assert.Equal("jerm-1699348021", c.Bucket)
assert.Equal("us-west-2", c.Region)
assert.Equal(role, c.Lambda.Role)
assert.Equal("python3.11", c.Lambda.Runtime)
assert.Equal(false, c.Lambda.KeepWarm)
assert.Equal("/home/ubuntu/bodystats", c.Dir)
assert.Equal(30, c.Lambda.Timeout)
assert.Equal("bodyie", c.Entry)
}

0 comments on commit 914c96d

Please sign in to comment.