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 @@ -24,6 +24,7 @@ ARGS:
[secret-environment-variables.{index}.key]
[secret-environment-variables.{index}.value]
[http-option=enabled] Configure how HTTP and HTTPS requests are handled (unknown_http_option | enabled | redirected)
[deploy=true] Deploy container after creation
[region=fr-par] Region to target. If none is passed will use default region from the config (fr-par | nl-ams | pl-waw)

FLAGS:
Expand Down
1 change: 1 addition & 0 deletions docs/commands/container.md
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ scw container container create [arg=value ...]
| secret-environment-variables.{index}.key | | |
| secret-environment-variables.{index}.value | | |
| http-option | Default: `enabled`<br />One of: `unknown_http_option`, `enabled`, `redirected` | Configure how HTTP and HTTPS requests are handled |
| deploy | Default: `true` | Deploy container after creation |
| region | Default: `fr-par`<br />One of: `fr-par`, `nl-ams`, `pl-waw` | Region to target. If none is passed will use default region from the config |


Expand Down
32 changes: 32 additions & 0 deletions internal/namespaces/container/v1beta1/custom_container.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package container

import (
"context"
"reflect"
"time"

"github.com/fatih/color"
Expand Down Expand Up @@ -45,6 +46,37 @@ func containerContainerDeployBuilder(command *core.Command) *core.Command {
}

func containerContainerCreateBuilder(command *core.Command) *core.Command {
// Add an interceptor that will deploy container after it was created
type CustomCreateContainerRequest struct {
*container.CreateContainerRequest
Deploy bool `json:"deploy"`
}

command.ArgSpecs.AddBefore("region", &core.ArgSpec{
Name: "deploy",
Short: "Deploy container after creation",
Required: false,
Default: core.DefaultValueSetter("true"),
})

command.ArgsType = reflect.TypeOf(CustomCreateContainerRequest{})

command.AddInterceptors(func(ctx context.Context, argsI interface{}, runner core.CommandRunner) (interface{}, error) {
args := argsI.(*CustomCreateContainerRequest)
resI, err := runner(ctx, args.CreateContainerRequest)
if err != nil {
return resI, err
}

c := resI.(*container.Container)
containerAPI := container.NewAPI(core.ExtractClient(ctx))

return containerAPI.DeployContainer(&container.DeployContainerRequest{
Region: c.Region,
ContainerID: c.ID,
}, scw.WithContext(ctx))
})

command.WaitFunc = waitForContainer
return command
}
Expand Down
44 changes: 44 additions & 0 deletions internal/namespaces/container/v1beta1/custom_container_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
package container

import (
"fmt"
"testing"

"github.com/alecthomas/assert"
"github.com/scaleway/scaleway-cli/v2/internal/core"
container "github.com/scaleway/scaleway-sdk-go/api/container/v1beta1"
)

func createNamespace(metaKey string) core.BeforeFunc {
return core.ExecStoreBeforeCmd(metaKey, "scw container namespace create -w")
}

func deleteNamespace(metaKey string) core.AfterFunc {
return func(ctx *core.AfterFuncCtx) error {
return core.ExecAfterCmd("scw container namespace delete {{ ." + metaKey + ".ID }}")(ctx)
}
}

func Test_Create(t *testing.T) {
commands := GetCommands()

t.Run("Simple", core.Test(&core.TestConfig{
Commands: commands,
BeforeFunc: core.BeforeFuncCombine(
createNamespace("Namespace"),
),
Cmd: fmt.Sprintf("scw container container create namespace-id={{ .Namespace.ID }} name=%s deploy=true", core.GetRandomName("test")),
Check: core.TestCheckCombine(
func(t *testing.T, ctx *core.CheckFuncCtx) {
c := ctx.Result.(*container.Container)
assert.Equal(t, container.ContainerStatusPending, c.Status)
},
core.TestCheckExitCode(0),
core.TestCheckGolden(),
),
AfterFunc: core.AfterFuncCombine(
deleteNamespace("Namespace"),
),
DisableParallel: true,
}))
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,201 @@
---
version: 1
interactions:
- request:
body: '{"id":"550f7065-ee73-4399-a32b-49b179950b57","name":"cli-cns-silly-shirley","environment_variables":{},"organization_id":"ee7bd9e1-9cbd-4724-b2f4-19e50f3cf38b","project_id":"ee7bd9e1-9cbd-4724-b2f4-19e50f3cf38b","status":"pending","registry_namespace_id":"","error_message":null,"registry_endpoint":"","description":"","secret_environment_variables":[],"region":"fr-par"}'
form: {}
headers:
Content-Type:
- application/json
User-Agent:
- scaleway-sdk-go/v1.0.0-beta.7+dev (go1.20.1; linux; amd64) cli-e2e-test
url: https://api.scaleway.com/containers/v1beta1/regions/fr-par/namespaces
method: POST
response:
body: '{"id":"550f7065-ee73-4399-a32b-49b179950b57","name":"cli-cns-silly-shirley","environment_variables":{},"organization_id":"ee7bd9e1-9cbd-4724-b2f4-19e50f3cf38b","project_id":"ee7bd9e1-9cbd-4724-b2f4-19e50f3cf38b","status":"pending","registry_namespace_id":"","error_message":null,"registry_endpoint":"","description":"","secret_environment_variables":[],"region":"fr-par"}'
headers:
Content-Length:
- "371"
Content-Security-Policy:
- default-src 'none'; frame-ancestors 'none'
Content-Type:
- application/json
Date:
- Tue, 13 Jun 2023 13:04:17 GMT
Server:
- Scaleway API-Gateway
Strict-Transport-Security:
- max-age=63072000
X-Content-Type-Options:
- nosniff
X-Frame-Options:
- DENY
X-Request-Id:
- deffd039-a6a2-4f09-ace8-0ffd84edd7e9
status: 200 OK
code: 200
duration: ""
- request:
body: '{"id":"550f7065-ee73-4399-a32b-49b179950b57","name":"cli-cns-silly-shirley","environment_variables":{},"organization_id":"ee7bd9e1-9cbd-4724-b2f4-19e50f3cf38b","project_id":"ee7bd9e1-9cbd-4724-b2f4-19e50f3cf38b","status":"pending","registry_namespace_id":"","error_message":null,"registry_endpoint":"","description":"","secret_environment_variables":[],"region":"fr-par"}'
form: {}
headers:
User-Agent:
- scaleway-sdk-go/v1.0.0-beta.7+dev (go1.20.1; linux; amd64) cli-e2e-test
url: https://api.scaleway.com/containers/v1beta1/regions/fr-par/namespaces/550f7065-ee73-4399-a32b-49b179950b57
method: GET
response:
body: '{"id":"550f7065-ee73-4399-a32b-49b179950b57","name":"cli-cns-silly-shirley","environment_variables":{},"organization_id":"ee7bd9e1-9cbd-4724-b2f4-19e50f3cf38b","project_id":"ee7bd9e1-9cbd-4724-b2f4-19e50f3cf38b","status":"pending","registry_namespace_id":"","error_message":null,"registry_endpoint":"","description":"","secret_environment_variables":[],"region":"fr-par"}'
headers:
Content-Length:
- "371"
Content-Security-Policy:
- default-src 'none'; frame-ancestors 'none'
Content-Type:
- application/json
Date:
- Tue, 13 Jun 2023 13:04:17 GMT
Server:
- Scaleway API-Gateway
Strict-Transport-Security:
- max-age=63072000
X-Content-Type-Options:
- nosniff
X-Frame-Options:
- DENY
X-Request-Id:
- 0a4495de-a6a4-4758-a1d1-4e719ad70440
status: 200 OK
code: 200
duration: ""
- request:
body: '{"id":"550f7065-ee73-4399-a32b-49b179950b57","name":"cli-cns-silly-shirley","environment_variables":{},"organization_id":"ee7bd9e1-9cbd-4724-b2f4-19e50f3cf38b","project_id":"ee7bd9e1-9cbd-4724-b2f4-19e50f3cf38b","status":"ready","registry_namespace_id":"27885dea-fa5e-455b-b90b-2c67553a344b","error_message":null,"registry_endpoint":"rg.fr-par.scw.cloud/funcscwclicnssillyshirleyusnp0hk3","description":"","secret_environment_variables":[],"region":"fr-par"}'
form: {}
headers:
User-Agent:
- scaleway-sdk-go/v1.0.0-beta.7+dev (go1.20.1; linux; amd64) cli-e2e-test
url: https://api.scaleway.com/containers/v1beta1/regions/fr-par/namespaces/550f7065-ee73-4399-a32b-49b179950b57
method: GET
response:
body: '{"id":"550f7065-ee73-4399-a32b-49b179950b57","name":"cli-cns-silly-shirley","environment_variables":{},"organization_id":"ee7bd9e1-9cbd-4724-b2f4-19e50f3cf38b","project_id":"ee7bd9e1-9cbd-4724-b2f4-19e50f3cf38b","status":"ready","registry_namespace_id":"27885dea-fa5e-455b-b90b-2c67553a344b","error_message":null,"registry_endpoint":"rg.fr-par.scw.cloud/funcscwclicnssillyshirleyusnp0hk3","description":"","secret_environment_variables":[],"region":"fr-par"}'
headers:
Content-Length:
- "458"
Content-Security-Policy:
- default-src 'none'; frame-ancestors 'none'
Content-Type:
- application/json
Date:
- Tue, 13 Jun 2023 13:04:23 GMT
Server:
- Scaleway API-Gateway
Strict-Transport-Security:
- max-age=63072000
X-Content-Type-Options:
- nosniff
X-Frame-Options:
- DENY
X-Request-Id:
- 989d3d6a-2cd2-4ac9-843c-7935b5b90cef
status: 200 OK
code: 200
duration: ""
- request:
body: '{"id":"eff8830f-5f3b-4e42-a2f0-8e4a77ec4cb0","name":"cli-test-kind-herschel","namespace_id":"550f7065-ee73-4399-a32b-49b179950b57","status":"created","environment_variables":{},"min_scale":0,"max_scale":5,"memory_limit":256,"cpu_limit":140,"timeout":"300s","error_message":null,"privacy":"public","description":"","registry_image":"rg.fr-par.scw.cloud/funcscwclicnssillyshirleyusnp0hk3/cli-test-kind-herschel:latest","max_concurrency":50,"domain_name":"clicnssillyshirleyusnp0hk3-cli-test-kind-herschel.functions.fnc.fr-par.scw.cloud","protocol":"http1","port":8080,"secret_environment_variables":[],"http_option":"enabled","region":"fr-par"}'
form: {}
headers:
Content-Type:
- application/json
User-Agent:
- scaleway-sdk-go/v1.0.0-beta.7+dev (go1.20.1; linux; amd64) cli-e2e-test
url: https://api.scaleway.com/containers/v1beta1/regions/fr-par/containers
method: POST
response:
body: '{"id":"eff8830f-5f3b-4e42-a2f0-8e4a77ec4cb0","name":"cli-test-kind-herschel","namespace_id":"550f7065-ee73-4399-a32b-49b179950b57","status":"created","environment_variables":{},"min_scale":0,"max_scale":5,"memory_limit":256,"cpu_limit":140,"timeout":"300s","error_message":null,"privacy":"public","description":"","registry_image":"rg.fr-par.scw.cloud/funcscwclicnssillyshirleyusnp0hk3/cli-test-kind-herschel:latest","max_concurrency":50,"domain_name":"clicnssillyshirleyusnp0hk3-cli-test-kind-herschel.functions.fnc.fr-par.scw.cloud","protocol":"http1","port":8080,"secret_environment_variables":[],"http_option":"enabled","region":"fr-par"}'
headers:
Content-Length:
- "642"
Content-Security-Policy:
- default-src 'none'; frame-ancestors 'none'
Content-Type:
- application/json
Date:
- Tue, 13 Jun 2023 13:04:23 GMT
Server:
- Scaleway API-Gateway
Strict-Transport-Security:
- max-age=63072000
X-Content-Type-Options:
- nosniff
X-Frame-Options:
- DENY
X-Request-Id:
- 7eb50852-2517-423d-adb5-5ed6f925945e
status: 200 OK
code: 200
duration: ""
- request:
body: '{"id":"eff8830f-5f3b-4e42-a2f0-8e4a77ec4cb0","name":"cli-test-kind-herschel","namespace_id":"550f7065-ee73-4399-a32b-49b179950b57","status":"pending","environment_variables":{},"min_scale":0,"max_scale":5,"memory_limit":256,"cpu_limit":140,"timeout":"300s","error_message":null,"privacy":"public","description":"","registry_image":"rg.fr-par.scw.cloud/funcscwclicnssillyshirleyusnp0hk3/cli-test-kind-herschel:latest","max_concurrency":50,"domain_name":"clicnssillyshirleyusnp0hk3-cli-test-kind-herschel.functions.fnc.fr-par.scw.cloud","protocol":"http1","port":8080,"secret_environment_variables":[],"http_option":"enabled","region":"fr-par"}'
form: {}
headers:
Content-Type:
- application/json
User-Agent:
- scaleway-sdk-go/v1.0.0-beta.7+dev (go1.20.1; linux; amd64) cli-e2e-test
url: https://api.scaleway.com/containers/v1beta1/regions/fr-par/containers/eff8830f-5f3b-4e42-a2f0-8e4a77ec4cb0/deploy
method: POST
response:
body: '{"id":"eff8830f-5f3b-4e42-a2f0-8e4a77ec4cb0","name":"cli-test-kind-herschel","namespace_id":"550f7065-ee73-4399-a32b-49b179950b57","status":"pending","environment_variables":{},"min_scale":0,"max_scale":5,"memory_limit":256,"cpu_limit":140,"timeout":"300s","error_message":null,"privacy":"public","description":"","registry_image":"rg.fr-par.scw.cloud/funcscwclicnssillyshirleyusnp0hk3/cli-test-kind-herschel:latest","max_concurrency":50,"domain_name":"clicnssillyshirleyusnp0hk3-cli-test-kind-herschel.functions.fnc.fr-par.scw.cloud","protocol":"http1","port":8080,"secret_environment_variables":[],"http_option":"enabled","region":"fr-par"}'
headers:
Content-Length:
- "642"
Content-Security-Policy:
- default-src 'none'; frame-ancestors 'none'
Content-Type:
- application/json
Date:
- Tue, 13 Jun 2023 13:04:23 GMT
Server:
- Scaleway API-Gateway
Strict-Transport-Security:
- max-age=63072000
X-Content-Type-Options:
- nosniff
X-Frame-Options:
- DENY
X-Request-Id:
- 46c4743b-6f0b-4e4f-8ce6-e96863efce7e
status: 200 OK
code: 200
duration: ""
- request:
body: '{"id":"550f7065-ee73-4399-a32b-49b179950b57","name":"cli-cns-silly-shirley","environment_variables":{},"organization_id":"ee7bd9e1-9cbd-4724-b2f4-19e50f3cf38b","project_id":"ee7bd9e1-9cbd-4724-b2f4-19e50f3cf38b","status":"deleting","registry_namespace_id":"27885dea-fa5e-455b-b90b-2c67553a344b","error_message":null,"registry_endpoint":"rg.fr-par.scw.cloud/funcscwclicnssillyshirleyusnp0hk3","description":"","secret_environment_variables":[],"region":"fr-par"}'
form: {}
headers:
User-Agent:
- scaleway-sdk-go/v1.0.0-beta.7+dev (go1.20.1; linux; amd64) cli-e2e-test
url: https://api.scaleway.com/containers/v1beta1/regions/fr-par/namespaces/550f7065-ee73-4399-a32b-49b179950b57
method: DELETE
response:
body: '{"id":"550f7065-ee73-4399-a32b-49b179950b57","name":"cli-cns-silly-shirley","environment_variables":{},"organization_id":"ee7bd9e1-9cbd-4724-b2f4-19e50f3cf38b","project_id":"ee7bd9e1-9cbd-4724-b2f4-19e50f3cf38b","status":"deleting","registry_namespace_id":"27885dea-fa5e-455b-b90b-2c67553a344b","error_message":null,"registry_endpoint":"rg.fr-par.scw.cloud/funcscwclicnssillyshirleyusnp0hk3","description":"","secret_environment_variables":[],"region":"fr-par"}'
headers:
Content-Length:
- "461"
Content-Security-Policy:
- default-src 'none'; frame-ancestors 'none'
Content-Type:
- application/json
Date:
- Tue, 13 Jun 2023 13:04:23 GMT
Server:
- Scaleway API-Gateway
Strict-Transport-Security:
- max-age=63072000
X-Content-Type-Options:
- nosniff
X-Frame-Options:
- DENY
X-Request-Id:
- 0beec01d-efd0-4ce3-ae32-2ffa2692bf26
status: 200 OK
code: 200
duration: ""
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
🎲🎲🎲 EXIT CODE: 0 🎲🎲🎲
🟩🟩🟩 STDOUT️ 🟩🟩🟩️
ID eff8830f-5f3b-4e42-a2f0-8e4a77ec4cb0
Name cli-test-kind-herschel
NamespaceID 550f7065-ee73-4399-a32b-49b179950b57
Status pending
MinScale 0
MaxScale 5
MemoryLimit 256
CPULimit 140
Timeout 5 minutes
Privacy public
Description -
RegistryImage rg.fr-par.scw.cloud/funcscwclicnssillyshirleyusnp0hk3/cli-test-kind-herschel:latest
MaxConcurrency 50
DomainName clicnssillyshirleyusnp0hk3-cli-test-kind-herschel.functions.fnc.fr-par.scw.cloud
Protocol http1
Port 8080
HTTPOption enabled
Region fr-par
🟩🟩🟩 JSON STDOUT 🟩🟩🟩
{
"id": "eff8830f-5f3b-4e42-a2f0-8e4a77ec4cb0",
"name": "cli-test-kind-herschel",
"namespace_id": "550f7065-ee73-4399-a32b-49b179950b57",
"status": "pending",
"environment_variables": {},
"min_scale": 0,
"max_scale": 5,
"memory_limit": 256,
"cpu_limit": 140,
"timeout": "300.000000000s",
"error_message": null,
"privacy": "public",
"description": "",
"registry_image": "rg.fr-par.scw.cloud/funcscwclicnssillyshirleyusnp0hk3/cli-test-kind-herschel:latest",
"max_concurrency": 50,
"domain_name": "clicnssillyshirleyusnp0hk3-cli-test-kind-herschel.functions.fnc.fr-par.scw.cloud",
"protocol": "http1",
"port": 8080,
"secret_environment_variables": [],
"http_option": "enabled",
"region": "fr-par"
}