Skip to content

Commit

Permalink
Merge pull request #463 from hazelops/IZE-605-serverless-v-3-supported
Browse files Browse the repository at this point in the history
IZE-605 IZE-606 serverless v3 supported
  • Loading branch information
AutomationD authored Sep 21, 2022
2 parents e41cbab + 54e3433 commit 154274f
Show file tree
Hide file tree
Showing 4 changed files with 67 additions and 11 deletions.
1 change: 1 addition & 0 deletions internal/config/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ type Serverless struct {
Name string `mapstructure:",omitempty"`
File string `mapstructure:",omitempty"`
NodeVersion string `mapstructure:"node_version"`
ServerlessVersion string `mapstructure:"serverless_version"`
Path string `mapstructure:",omitempty"`
SLSNodeModuleCacheMount string `mapstructure:",omitempty"`
CreateDomain bool `mapstructure:"create_domain"`
Expand Down
57 changes: 47 additions & 10 deletions internal/manager/serverless/native.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,9 +54,26 @@ func (sls *Manager) runDeploy(w io.Writer) error {
if len(nvmDir) == 0 {
nvmDir = "$HOME/.nvm"
}
var command string

command := fmt.Sprintf(
`source %s/nvm.sh &&
// SLS v3 has breaking changes in syntax
if sls.App.ServerlessVersion == "3" {
command = fmt.Sprintf(
`source %s/nvm.sh &&
nvm use %s &&
npx serverless deploy \
--config=%s \
--param="service=%s" \
--region=%s \
--param="profile=%s" \
--stage=%s \
--verbose \`,
nvmDir, sls.App.NodeVersion, sls.App.File,
sls.App.Name, sls.App.AwsRegion,
sls.App.AwsProfile, sls.Project.Env)
} else {
command = fmt.Sprintf(
`source %s/nvm.sh &&
nvm use %s &&
npx serverless deploy \
--config %s \
Expand All @@ -65,9 +82,10 @@ func (sls *Manager) runDeploy(w io.Writer) error {
--region %s \
--profile %s \
--stage %s`,
nvmDir, sls.App.NodeVersion, sls.App.File,
sls.App.Name, sls.App.AwsRegion,
sls.App.AwsProfile, sls.Project.Env)
nvmDir, sls.App.NodeVersion, sls.App.File,
sls.App.Name, sls.App.AwsRegion,
sls.App.AwsProfile, sls.Project.Env)
}

cmd := exec.Command("bash", "-c", command)
cmd.Stdout = w
Expand All @@ -88,8 +106,26 @@ func (sls *Manager) runRemove(w io.Writer) error {
nvmDir = "$HOME/.nvm"
}

command := fmt.Sprintf(
`source %s/nvm.sh &&
var command string

// SLS v3 has breaking changes in syntax
if sls.App.ServerlessVersion == "3" {
command = fmt.Sprintf(
`source %s/nvm.sh &&
nvm use %s &&
npx serverless remove \
--config=%s \
--param="service=%s" \
--region=%s \
--param="profile=%s" \
--stage=%s \
--verbose \`,
nvmDir, sls.App.NodeVersion, sls.App.File,
sls.App.Name, sls.App.AwsRegion,
sls.App.AwsProfile, sls.Project.Env)
} else {
command = fmt.Sprintf(
`source %s/nvm.sh &&
nvm use %s &&
npx serverless remove \
--config %s \
Expand All @@ -98,9 +134,10 @@ func (sls *Manager) runRemove(w io.Writer) error {
--region %s \
--profile %s \
--stage %s`,
nvmDir, sls.App.NodeVersion, sls.App.File,
sls.App.Name, sls.App.AwsRegion,
sls.App.AwsProfile, sls.Project.Env)
nvmDir, sls.App.NodeVersion, sls.App.File,
sls.App.Name, sls.App.AwsRegion,
sls.App.AwsProfile, sls.Project.Env)
}

cmd := exec.Command("bash", "-c", command)
cmd.Stdout = w
Expand Down
12 changes: 11 additions & 1 deletion internal/manager/serverless/serverless.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,18 @@ func (sls *Manager) prepare() {
}

if len(sls.App.File) == 0 {
sls.App.File = "serverless.yml"
_, err := os.Stat(filepath.Join(sls.App.Path, "serverless.ts"))
if os.IsNotExist(err) {
sls.App.File = "serverless.yml"
} else {
sls.App.File = "serverless.ts"
}
}

if len(sls.App.ServerlessVersion) == 0 {
sls.App.ServerlessVersion = "2"
}

if len(sls.App.SLSNodeModuleCacheMount) == 0 {
sls.App.SLSNodeModuleCacheMount = fmt.Sprintf("%s-node-modules", sls.App.Name)
}
Expand Down
8 changes: 8 additions & 0 deletions internal/schema/ize-spec.json
Original file line number Diff line number Diff line change
Expand Up @@ -251,6 +251,10 @@
"type": "string",
"description": "(optional) Node version that will be used by nvm can be specified here that. Default is v14."
},
"serverless_version": {
"type": "string",
"description": "(optional) Serverless framework version which is used. Defines cli interface. Default is 2."
},
"create_domain" : {
"type": "boolean",
"description": "(optional) Create domain for the serverless domain manager during the deployment."
Expand Down Expand Up @@ -375,6 +379,10 @@
"type": "string",
"description": "(optional) Node version that will be used by nvm can be specified here that. Default is v14."
},
"serverless_version": {
"type": "string",
"description": "(optional) Serverless framework version which is used. Defines cli interface. Default is 2."
},
"create_domain" : {
"type": "boolean",
"description": "(optional) Create domain for the serverless domain manager during the deployment."
Expand Down

0 comments on commit 154274f

Please sign in to comment.