Skip to content
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
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ ARGS:
[dockerfile=Dockerfile] Path to the Dockerfile
[build-source=.] Path to the build context
[cache=true] Use cache when building the image
[build-args.{key}] Build-time variables
[port=8080] Port to expose
[namespace-id] Container Namespace ID to deploy to
[region=fr-par] Region to target. If none is passed will use default region from the config (fr-par | nl-ams | pl-waw | all)
Expand Down
1 change: 1 addition & 0 deletions docs/commands/container.md
Original file line number Diff line number Diff line change
Expand Up @@ -351,6 +351,7 @@ scw container deploy [arg=value ...]
| dockerfile | Default: `Dockerfile` | Path to the Dockerfile |
| build-source | Default: `.` | Path to the build context |
| cache | Default: `true` | Use cache when building the image |
| build-args.{key} | | Build-time variables |
| port | Default: `8080` | Port to expose |
| namespace-id | | Container Namespace ID to deploy to |
| region | Default: `fr-par`<br />One of: `fr-par`, `nl-ams`, `pl-waw`, `all` | Region to target. If none is passed will use default region from the config |
Expand Down
7 changes: 7 additions & 0 deletions internal/namespaces/container/v1beta1/custom_deploy.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ type containerDeployRequest struct {
Dockerfile string
BuildSource string
Cache bool
BuildArgs map[string]*string

NamespaceID *string
Port uint32
Expand Down Expand Up @@ -65,6 +66,11 @@ func containerDeployCommand() *core.Command {
Short: "Use cache when building the image",
Default: core.DefaultValueSetter("true"),
},
{
Name: "build-args.{key}",
Short: "Build-time variables",
Required: false,
},
{
Name: "port",
Short: "Port to expose",
Expand Down Expand Up @@ -232,6 +238,7 @@ func DeployStepBuildImage(t *tasks.Task, data *DeployStepPackImageResponse) (*De
Dockerfile: data.Args.Dockerfile,
Tags: []string{tag},
NoCache: !data.Args.Cache,
BuildArgs: data.Args.BuildArgs,
})
if err != nil {
return nil, fmt.Errorf("could not build image: %w", errors.Unwrap(err))
Expand Down
42 changes: 41 additions & 1 deletion internal/namespaces/container/v1beta1/custom_deploy_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,14 @@ var (
FROM nginx:alpine
RUN apk add --no-cache curl git bash
COPY ./index.html /usr/share/nginx/html/index.html
EXPOSE 80
`)
nginxDockerfileWithBuildArgs = strings.TrimSpace(`
FROM nginx:alpine
RUN apk add --no-cache curl git bash
COPY ./index.html /usr/share/nginx/html/index.html
ARG TEST
RUN test -n "$TEST"
EXPOSE 80
`)
)
Expand Down Expand Up @@ -112,6 +120,38 @@ func Test_Deploy(t *testing.T) {
),
DisableParallel: true,
}))

t.Run("Build args", core.Test(&core.TestConfig{
Commands: commands,
BeforeFunc: core.BeforeFuncCombine(
func(ctx *core.BeforeFuncCtx) error {
// Create index.html
err := os.WriteFile(filepath.Join(path, "index.html"), []byte(indexHTML), 0600)
if err != nil {
return err
}
return nil
},
func(ctx *core.BeforeFuncCtx) error {
// Create Dockerfile
err := os.WriteFile(filepath.Join(path, "Dockerfile"), []byte(nginxDockerfileWithBuildArgs), 0600)
if err != nil {
return err
}
return nil
},
),
Cmd: fmt.Sprintf("scw container deploy name=%s build-source=%s port=80 build-args.TEST=thisisatest", appName, path),
Check: core.TestCheckCombine(
core.TestCheckGolden(),
core.TestCheckExitCode(0),
),
AfterFunc: core.AfterFuncCombine(
testDeleteContainersNamespaceAfter(appName),
testDeleteRegistryAfter(appName),
),
DisableParallel: true,
}))
}

func testDeleteContainersNamespaceAfter(appName string) func(*core.AfterFuncCtx) error {
Expand All @@ -137,7 +177,7 @@ func testDeleteContainersNamespaceAfter(appName string) func(*core.AfterFuncCtx)
return fmt.Errorf("namespace not found")
}

return core.ExecAfterCmd(fmt.Sprintf("scw container namespace delete %s", namespaceID))(ctx)
return core.ExecAfterCmd(fmt.Sprintf("scw container namespace delete %s --wait", namespaceID))(ctx)
}
}

Expand Down

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
🎲🎲🎲 EXIT CODE: 0 🎲🎲🎲
🟩🟩🟩 STDOUT️ 🟩🟩🟩️
Your application is now available at https://appclitestdeployponelvzngnoz-app-cli-test-deploy-poney.functions.fnc.fr-par.scw.cloud
Your application is now available at https://appclitestdeployponewm9y7zuv-app-cli-test-deploy-poney.functions.fnc.fr-par.scw.cloud

🟩🟩🟩 JSON STDOUT 🟩🟩🟩
"Your application is now available at https://appclitestdeployponelvzngnoz-app-cli-test-deploy-poney.functions.fnc.fr-par.scw.cloud\n"
"Your application is now available at https://appclitestdeployponewm9y7zuv-app-cli-test-deploy-poney.functions.fnc.fr-par.scw.cloud\n"

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
🎲🎲🎲 EXIT CODE: 0 🎲🎲🎲
🟩🟩🟩 STDOUT️ 🟩🟩🟩️
Your application is now available at https://clitestcontainerdeplattc7cav-cli-test-container-deploy.functions.fnc.fr-par.scw.cloud

🟩🟩🟩 JSON STDOUT 🟩🟩🟩
"Your application is now available at https://clitestcontainerdeplattc7cav-cli-test-container-deploy.functions.fnc.fr-par.scw.cloud\n"
Loading