Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

IZE-605 IZE-606 serverless v3 supported #463

Merged
merged 3 commits into from
Sep 21, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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