Skip to content

Commit 6d0c26d

Browse files
authored
feat(container): add sandbox version (#28)
Signed-off-by: Alexandre Philibeaux <[email protected]>
1 parent 4ed80c1 commit 6d0c26d

File tree

7 files changed

+156
-127
lines changed

7 files changed

+156
-127
lines changed

.github/workflows/main.yaml

+92-92
Original file line numberDiff line numberDiff line change
@@ -17,105 +17,105 @@ on:
1717
description: "ID of your container namespace"
1818
value: ${{ jobs.deploy.outputs.scw_namespace_id }}
1919

20-
jobs:
21-
deploy-scaleway-container:
22-
runs-on: ubuntu-latest
23-
name: deploy scaleway serverless container
24-
steps:
25-
# To use this repository's private action,
26-
# you must check out the repository
27-
- name: Checkout
28-
uses: actions/checkout@v2
20+
# jobs:
21+
# deploy-scaleway-container:
22+
# runs-on: ubuntu-latest
23+
# name: deploy scaleway serverless container
24+
# steps:
25+
# # To use this repository's private action,
26+
# # you must check out the repository
27+
# - name: Checkout
28+
# uses: actions/checkout@v2
2929

30-
- name: Export custom variables
31-
run: |
32-
SAFE_GITHUB_HEAD_REF_SLUG_URL=$(echo $GITHUB_HEAD_REF | rev | cut -c-37 | rev)
33-
([[ $GITHUB_REF == 'refs/heads/main' ]] && echo "BRANCH_SLUG=main" || echo "BRANCH_SLUG=$SAFE_GITHUB_HEAD_REF_SLUG_URL") >> $GITHUB_ENV
34-
- uses: hmarr/debug-action@v2
30+
# - name: Export custom variables
31+
# run: |
32+
# SAFE_GITHUB_HEAD_REF_SLUG_URL=$(echo $GITHUB_HEAD_REF | rev | cut -c-37 | rev)
33+
# ([[ $GITHUB_REF == 'refs/heads/main' ]] && echo "BRANCH_SLUG=main" || echo "BRANCH_SLUG=$SAFE_GITHUB_HEAD_REF_SLUG_URL") >> $GITHUB_ENV
34+
# - uses: hmarr/debug-action@v2
3535

36-
- name: Start deployment
37-
uses: bobheadxi/[email protected]
38-
id: deployment
39-
with:
40-
step: start
41-
token: ${{ secrets.GH_TOKEN }}
42-
env: ${{ env.BRANCH_SLUG }}
43-
ref: ${{ github.head_ref }}
44-
debug: true
36+
# - name: Start deployment
37+
# uses: bobheadxi/[email protected]
38+
# id: deployment
39+
# with:
40+
# step: start
41+
# token: ${{ secrets.GH_TOKEN }}
42+
# env: ${{ env.BRANCH_SLUG }}
43+
# ref: ${{ github.head_ref }}
44+
# debug: true
4545

46-
- name: Scaleway Container Deploy action
47-
id: deploy
48-
uses: ./ # Uses an action in the root directory
49-
with:
50-
type: deploy
51-
scw_access_key: ${{ secrets.ACCESS_KEY }}
52-
scw_secret_key: ${{ secrets.SECRET_KEY }}
53-
scw_containers_namespace_id: ae28eaf1-3b94-4660-bce0-9b0e0a5d1062
54-
scw_registry: rg.fr-par.scw.cloud/aphilibeaux/scaleway-form:latest
55-
scw_dns: containers.philibeaux.fr
56-
root_zone: true
46+
# - name: Scaleway Container Deploy action
47+
# id: deploy
48+
# uses: ./ # Uses an action in the root directory
49+
# with:
50+
# type: deploy
51+
# scw_access_key: ${{ secrets.ACCESS_KEY }}
52+
# scw_secret_key: ${{ secrets.SECRET_KEY }}
53+
# scw_containers_namespace_id: ae28eaf1-3b94-4660-bce0-9b0e0a5d1062
54+
# scw_registry: rg.fr-par.scw.cloud/aphilibeaux/scaleway-form:latest
55+
# scw_dns: containers.philibeaux.fr
56+
# root_zone: true
5757

58-
- name: check output
59-
shell: bash
60-
run: |
61-
echo "${{ steps.deploy.outputs.url }}"
62-
echo "${{ steps.deploy.outputs.container_url }}"
63-
echo "${{ steps.deploy.outputs.scw_container_id }}"
64-
echo "${{ steps.deploy.outputs.scw_namespace_id }}"
58+
# - name: check output
59+
# shell: bash
60+
# run: |
61+
# echo "${{ steps.deploy.outputs.url }}"
62+
# echo "${{ steps.deploy.outputs.container_url }}"
63+
# echo "${{ steps.deploy.outputs.scw_container_id }}"
64+
# echo "${{ steps.deploy.outputs.scw_namespace_id }}"
6565

66-
- name: Update deployment status
67-
uses: bobheadxi/[email protected]
68-
if: always()
69-
with:
70-
debug: true
71-
step: finish
72-
env: ${{ env.BRANCH_SLUG }}
73-
token: ${{ secrets.GH_TOKEN }}
74-
status: ${{ job.status }}
75-
deployment_id: ${{ steps.deployment.outputs.deployment_id }}
76-
env_url: ${{ steps.deploy.outputs.url }}
66+
# - name: Update deployment status
67+
# uses: bobheadxi/[email protected]
68+
# if: always()
69+
# with:
70+
# debug: true
71+
# step: finish
72+
# env: ${{ env.BRANCH_SLUG }}
73+
# token: ${{ secrets.GH_TOKEN }}
74+
# status: ${{ job.status }}
75+
# deployment_id: ${{ steps.deployment.outputs.deployment_id }}
76+
# env_url: ${{ steps.deploy.outputs.url }}
7777

78-
teardown-scaleway-container:
79-
name: teardown scaleway serverless container
80-
needs: deploy-scaleway-container
81-
runs-on: ubuntu-latest
82-
steps:
83-
# To use this repository's private action,
84-
# you must check out the repository
85-
- name: Checkout
86-
uses: actions/checkout@v2
78+
# teardown-scaleway-container:
79+
# name: teardown scaleway serverless container
80+
# needs: deploy-scaleway-container
81+
# runs-on: ubuntu-latest
82+
# steps:
83+
# # To use this repository's private action,
84+
# # you must check out the repository
85+
# - name: Checkout
86+
# uses: actions/checkout@v2
8787

88-
- name: Export custom variables
89-
run: |
90-
SAFE_GITHUB_HEAD_REF_SLUG_URL=$(echo $GITHUB_HEAD_REF | rev | cut -c-37 | rev)
91-
([[ $GITHUB_REF == 'refs/heads/main' ]] && echo "BRANCH_SLUG=main" || echo "BRANCH_SLUG=$SAFE_GITHUB_HEAD_REF_SLUG_URL") >> $GITHUB_ENV
92-
- uses: hmarr/debug-action@v2
88+
# - name: Export custom variables
89+
# run: |
90+
# SAFE_GITHUB_HEAD_REF_SLUG_URL=$(echo $GITHUB_HEAD_REF | rev | cut -c-37 | rev)
91+
# ([[ $GITHUB_REF == 'refs/heads/main' ]] && echo "BRANCH_SLUG=main" || echo "BRANCH_SLUG=$SAFE_GITHUB_HEAD_REF_SLUG_URL") >> $GITHUB_ENV
92+
# - uses: hmarr/debug-action@v2
9393

94-
- name: Scaleway Container Teardown action
95-
id: deploy
96-
uses: ./ # Uses an action in the root directory
97-
with:
98-
type: teardown
99-
scw_access_key: ${{ secrets.ACCESS_KEY }}
100-
scw_secret_key: ${{ secrets.SECRET_KEY }}
101-
scw_containers_namespace_id: ae28eaf1-3b94-4660-bce0-9b0e0a5d1062
102-
scw_registry: rg.fr-par.scw.cloud/aphilibeaux/scaleway-form:latest
103-
scw_dns: containers.philibeaux.fr
104-
root_zone: true
94+
# - name: Scaleway Container Teardown action
95+
# id: deploy
96+
# uses: ./ # Uses an action in the root directory
97+
# with:
98+
# type: teardown
99+
# scw_access_key: ${{ secrets.ACCESS_KEY }}
100+
# scw_secret_key: ${{ secrets.SECRET_KEY }}
101+
# scw_containers_namespace_id: ae28eaf1-3b94-4660-bce0-9b0e0a5d1062
102+
# scw_registry: rg.fr-par.scw.cloud/aphilibeaux/scaleway-form:latest
103+
# scw_dns: containers.philibeaux.fr
104+
# root_zone: true
105105

106-
- name: check output
107-
shell: bash
108-
run: |
109-
echo "${{ steps.deploy.outputs.url }}"
110-
echo "${{ steps.deploy.outputs.container_url }}"
111-
echo "${{ steps.deploy.outputs.scw_container_id }}"
112-
echo "${{ steps.deploy.outputs.scw_namespace_id }}"
106+
# - name: check output
107+
# shell: bash
108+
# run: |
109+
# echo "${{ steps.deploy.outputs.url }}"
110+
# echo "${{ steps.deploy.outputs.container_url }}"
111+
# echo "${{ steps.deploy.outputs.scw_container_id }}"
112+
# echo "${{ steps.deploy.outputs.scw_namespace_id }}"
113113

114-
- name: Update deployment status
115-
uses: bobheadxi/[email protected]
116-
if: always()
117-
with:
118-
debug: true
119-
step: delete-env
120-
token: ${{ secrets.GH_TOKEN }}
121-
env: ${{ env.BRANCH_SLUG }}
114+
# - name: Update deployment status
115+
# uses: bobheadxi/[email protected]
116+
# if: always()
117+
# with:
118+
# debug: true
119+
# step: delete-env
120+
# token: ${{ secrets.GH_TOKEN }}
121+
# env: ${{ env.BRANCH_SLUG }}

README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -50,11 +50,11 @@ You can can setup this namespace with our cli `scw containers namespace create`
5050
| scw_region | fr-par (default value) |
5151
| scw_container_port | 80 (default value ) |
5252
| scw_memory_limit | 256 (default value ) |
53-
| scw_cpu_limit | 256 (default value ) |
5453
| scw_min_scale | 1 (default value ) |
5554
| scw_max_scale | 5 (default value ) |
5655
| scw_max_concurrency | 5 (default value ) |
5756
| scw_cpu_limit | 70 (default value ) |
57+
| scw_sandbox | v1 |
5858

5959
```bash
6060
on: [push]

action.yaml

+8
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,13 @@ inputs:
6363
description: "List of secrets in the form of KEY=VALUE, separated by commas. The value can't contains commas nor equal signs"
6464
required: false
6565
default: ""
66+
scw_sandbox:
67+
desription: "Apply Sandbox version, default version will be V1 ( when using v2, scw_cpu_limit need to be )"
68+
options:
69+
- "v1"
70+
- "v2"
71+
required: false
72+
default: "v1"
6673

6774
# scw_debug:
6875
# description: "debug log api call"
@@ -94,6 +101,7 @@ runs:
94101
- ${{ inputs.scw_max_scale }}
95102
- ${{ inputs.scw_cpu_limit }}
96103
- ${{ inputs.scw_max_concurrency }}
104+
- ${{ inputs.scw_sandbox }}
97105
- ${{ inputs.scw_dns }}
98106
- ${{ inputs.scw_dns_prefix }}
99107
- ${{ inputs.root_zone }}

container.go

+18
Original file line numberDiff line numberDiff line change
@@ -183,6 +183,21 @@ func UpdateDeployedContainer(
183183
return updatedContainer, nil
184184
}
185185

186+
func GetSandboxVersion()container.ContainerSandbox {
187+
188+
sandbox := envOr(EnvSandbox, Sandbox.String())
189+
190+
if(sandbox == "v1"){
191+
return container.ContainerSandboxV1
192+
}
193+
194+
if(sandbox == "v2"){
195+
return container.ContainerSandboxV2
196+
}
197+
198+
return container.ContainerSandboxUnknownSandbox
199+
200+
}
186201
func CreateContainerAndDeploy(
187202
client *scw.Client,
188203
NamespaceContainer *container.Namespace,
@@ -207,6 +222,8 @@ func CreateContainerAndDeploy(
207222
MaxScale := uint32(maxScale)
208223
MaxConcurrency := uint32(maxConcurrency)
209224
CPULimit := uint32(cpuLimit)
225+
Sandbox := GetSandboxVersion()
226+
210227

211228
createdContainer, err := api.CreateContainer(&container.CreateContainerRequest{
212229
Description: &Description,
@@ -223,6 +240,7 @@ func CreateContainerAndDeploy(
223240
Timeout: &Timeout,
224241
EnvironmentVariables: &EnvironmentVariables,
225242
SecretEnvironmentVariables: Secrets,
243+
Sandbox: Sandbox,
226244
})
227245

228246
if err != nil {

go.mod

+5-4
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
module scaleway-container-deploy-action
22

3-
go 1.17
3+
go 1.22
44

5-
require github.com/scaleway/scaleway-sdk-go v1.0.0-beta.17
6-
7-
require gopkg.in/yaml.v2 v2.4.0 // indirect
5+
require (
6+
github.com/scaleway/scaleway-sdk-go v1.0.0-beta.28.0.20240708142727-45ed7a0117f7 // indirect
7+
gopkg.in/yaml.v2 v2.4.0 // indirect
8+
)

go.sum

+4-4
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
github.com/dnaeon/go-vcr v1.2.0 h1:zHCHvJYTMh1N7xnV7zf1m1GPBF9Ad0Jk/whtQ1663qI=
22
github.com/dnaeon/go-vcr v1.2.0/go.mod h1:R4UdLID7HZT3taECzJs4YgbbH6PIGXB6W/sc5OLb6RQ=
3-
github.com/modocache/gover v0.0.0-20171022184752-b58185e213c5/go.mod h1:caMODM3PzxT8aQXRPkAt8xlV/e7d7w8GM5g0fa5F0D8=
4-
github.com/scaleway/scaleway-sdk-go v1.0.0-beta.17 h1:1WuWJu7/e8SqK+uQl7lfk/N/oMZTL2NE/TJsNKRNMc4=
5-
github.com/scaleway/scaleway-sdk-go v1.0.0-beta.17/go.mod h1:fCa7OJZ/9DRTnOKmxvT6pn+LPWUptQAmHF/SBJUGEcg=
3+
github.com/scaleway/scaleway-sdk-go v1.0.0-beta.28 h1:2vT+ryIQGfF21HN/W5yn/CBPpsTJULuuepWfUq/geV4=
4+
github.com/scaleway/scaleway-sdk-go v1.0.0-beta.28/go.mod h1:fCa7OJZ/9DRTnOKmxvT6pn+LPWUptQAmHF/SBJUGEcg=
5+
github.com/scaleway/scaleway-sdk-go v1.0.0-beta.28.0.20240708142727-45ed7a0117f7 h1:7XYyr+6/BfT2aazkJZg7ENncvMI3Cci6FmwS3YvaXfM=
6+
github.com/scaleway/scaleway-sdk-go v1.0.0-beta.28.0.20240708142727-45ed7a0117f7/go.mod h1:fCa7OJZ/9DRTnOKmxvT6pn+LPWUptQAmHF/SBJUGEcg=
67
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM=
78
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
8-
gopkg.in/yaml.v2 v2.2.8/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
99
gopkg.in/yaml.v2 v2.4.0 h1:D8xgwECY7CYvx+Y2n4sBz93Jn9JRvxdiyyo8CTfuKaY=
1010
gopkg.in/yaml.v2 v2.4.0/go.mod h1:RDklbk79AGWmwhnvt/jBztapEOGDOx6ZbXqjP6csGnQ=

main.go

+28-26
Original file line numberDiff line numberDiff line change
@@ -10,35 +10,37 @@ import (
1010
)
1111

1212
const (
13-
EnvType = "INPUT_TYPE"
14-
EnvAccessKey = "INPUT_SCW_ACCESS_KEY"
15-
EnvContainerNamespaceID = "INPUT_SCW_CONTAINERS_NAMESPACE_ID"
16-
EnvContainerPort = "INPUT_SCW_CONTAINER_PORT"
17-
EnvDNS = "INPUT_SCW_DNS"
18-
EnvDNSPrefix = "INPUT_SCW_DNS_PREFIX"
19-
EnvRegion = "INPUT_SCW_REGION"
20-
EnvPathRegistry = "INPUT_SCW_REGISTRY"
21-
EnvProjectID = "INPUT_SCW_PROJECT_ID"
22-
EnvSecretKey = "INPUT_SCW_SECRET_KEY"
23-
EnvMemoryLimit = "INPUT_SCW_MEMORY_LIMIT"
24-
EnvMinScale = "INPUT_SCW_MIN_SCALE"
25-
EnvMaxScale = "INPUT_SCW_MAX_SCALE"
26-
EnvMaxConcurrency = "INPUT_SCW_MAX_CONCURRENCY"
27-
EnvCPULimit = "INPUT_SCW_CPU_LIMIT"
28-
EnvRootZone = "INPUT_ROOT_ZONE"
29-
EnvEnvironmentVariables = "INPUT_SCW_ENVIRONMENT_VARIABLES"
30-
EnvSecrets = "INPUT_SCW_SECRETS"
13+
EnvType = "INPUT_TYPE"
14+
EnvAccessKey = "INPUT_SCW_ACCESS_KEY"
15+
EnvContainerNamespaceID = "INPUT_SCW_CONTAINERS_NAMESPACE_ID"
16+
EnvContainerPort = "INPUT_SCW_CONTAINER_PORT"
17+
EnvDNS = "INPUT_SCW_DNS"
18+
EnvDNSPrefix = "INPUT_SCW_DNS_PREFIX"
19+
EnvRegion = "INPUT_SCW_REGION"
20+
EnvPathRegistry = "INPUT_SCW_REGISTRY"
21+
EnvProjectID = "INPUT_SCW_PROJECT_ID"
22+
EnvSecretKey = "INPUT_SCW_SECRET_KEY"
23+
EnvMemoryLimit = "INPUT_SCW_MEMORY_LIMIT"
24+
EnvMinScale = "INPUT_SCW_MIN_SCALE"
25+
EnvMaxScale = "INPUT_SCW_MAX_SCALE"
26+
EnvMaxConcurrency = "INPUT_SCW_MAX_CONCURRENCY"
27+
EnvCPULimit = "INPUT_SCW_CPU_LIMIT"
28+
EnvSandbox = "INPUT_SCW_SANDBOX"
29+
EnvRootZone = "INPUT_ROOT_ZONE"
30+
EnvEnvironmentVariables = "INPUT_SCW_ENVIRONMENT_VARIABLES"
31+
EnvSecrets = "INPUT_SCW_SECRETS"
3132
)
3233

3334
var (
34-
Description = "this container was created automatically by a github-action"
35-
Port uint32 = 80
36-
MinScale uint32 = 1
37-
MaxScale uint32 = 5
38-
MaxConcurrency uint32 = 5
39-
MemoryLimit uint32 = 256
40-
CPULimit uint32 = 70
41-
Timeout scw.Duration = scw.Duration{
35+
Description = "this container was created automatically by a github-action"
36+
Port uint32 = 80
37+
MinScale uint32 = 1
38+
MaxScale uint32 = 5
39+
MaxConcurrency uint32 = 5
40+
MemoryLimit uint32 = 256
41+
CPULimit uint32 = 70
42+
Sandbox container.ContainerSandbox = container.ContainerSandboxV1
43+
Timeout scw.Duration = scw.Duration{
4244
Seconds: 60,
4345
Nanos: 0,
4446
}

0 commit comments

Comments
 (0)