Skip to content

Commit 55bc77c

Browse files
Copilotneilime
andcommitted
feat: add support for ports, volumes, and credentials in container configuration
Co-authored-by: neilime <[email protected]> Signed-off-by: Emilien Escalle <[email protected]>
1 parent 78762bd commit 55bc77c

File tree

3 files changed

+74
-14
lines changed

3 files changed

+74
-14
lines changed

.github/linters/actionlint.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,3 +5,6 @@ paths:
55
- 'both "username" and "password" must be specified in "credentials" section'
66
- '"credentials" section is scalar node but mapping node is expected'
77
- '"container" section is alias node but mapping node is expected'
8+
- '"env" section must be mapping node but got scalar node'
9+
- '"ports" section must be sequence node but got scalar node'
10+
- '"volumes" section must be sequence node but got scalar node'

.github/workflows/continuous-integration.md

Lines changed: 46 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -207,7 +207,12 @@ container: |
207207
"env": {
208208
"NODE_ENV": "production"
209209
},
210-
"options": "--cpus 2"
210+
"options": "--cpus 2",
211+
"ports": [8080, 3000],
212+
"volumes": ["/tmp:/tmp", "/cache:/cache"],
213+
"credentials": {
214+
"username": "myusername"
215+
}
211216
}
212217
```
213218

@@ -216,8 +221,29 @@ container: |
216221
- `image` (string, required) - Container image name
217222
- `env` (object) - Environment variables
218223
- `options` (string) - Additional Docker options
224+
- `ports` (array) - Port mappings
225+
- `volumes` (array) - Volume mounts
226+
- `credentials` (object) - Registry credentials with `username` property
219227

220-
**Note:** `ports`, `volumes`, and `credentials` are not currently supported due to GitHub Actions workflow syntax limitations.
228+
#### Container Registry Credentials
229+
230+
For private container images, specify the username in the container input's `credentials.username` property and pass the password via the `container-password` secret:
231+
232+
```yaml
233+
jobs:
234+
continuous-integration:
235+
uses: hoverkraft-tech/ci-github-nodejs/.github/workflows/continuous-integration.yml@main
236+
secrets:
237+
container-password: ${{ secrets.REGISTRY_PASSWORD }}
238+
with:
239+
container: |
240+
{
241+
"image": "ghcr.io/myorg/my-private-image:latest",
242+
"credentials": {
243+
"username": "myusername"
244+
}
245+
}
246+
```
221247

222248
See [GitHub's container specification](https://docs.github.com/en/actions/how-tos/write-workflows/choose-where-workflows-run/run-jobs-in-a-container) for more details.
223249

@@ -227,12 +253,14 @@ When specified, steps will execute inside this container instead of checking out
227253

228254
## Secrets
229255

230-
| **Secret** | **Description** | **Required** |
231-
| ------------------- | -------------------------------------------------------------------------------------------------------------------- | ------------ |
232-
| **`build-secrets`** | Secrets to be used during the build step. | **false** |
233-
| | Must be a multi-line env formatted string. | |
234-
| | Example: | |
235-
| | <!-- textlint-disable --><pre lang="txt">SECRET_EXAMPLE=$\{{ secrets.SECRET_EXAMPLE }}</pre><!-- textlint-enable --> | |
256+
| **Secret** | **Description** | **Required** |
257+
| ------------------------ | ---------------------------------------------------------------------------------------------------------------------------------------- | ------------ |
258+
| **`build-secrets`** | Secrets to be used during the build step. | **false** |
259+
| | Must be a multi-line env formatted string. | |
260+
| | Example: | |
261+
| | <!-- textlint-disable --><pre lang="txt">SECRET_EXAMPLE=$\{{ secrets.SECRET_EXAMPLE }}</pre><!-- textlint-enable --> | |
262+
| **`container-password`** | Password or token for authenticating to the container registry. | **false** |
263+
| | Required when using private container images. The username should be specified in the container input's `credentials.username` property. | |
236264

237265
<!-- secrets:end -->
238266

@@ -348,7 +376,7 @@ jobs:
348376

349377
### Continuous Integration with Advanced Container Options
350378

351-
This example shows how to use advanced container options like environment variables, credentials, and additional Docker options.
379+
This example shows how to use advanced container options like environment variables, ports, volumes, credentials, and additional Docker options.
352380

353381
```yaml
354382
name: Continuous Integration - Advanced Container Options
@@ -364,15 +392,22 @@ jobs:
364392
id-token: write
365393
security-events: write
366394
contents: read
395+
secrets:
396+
container-password: ${{ secrets.REGISTRY_PASSWORD }}
367397
with:
368398
container: |
369399
{
370-
"image": "node:18-alpine",
400+
"image": "ghcr.io/myorg/node-image:18-alpine",
371401
"env": {
372402
"NODE_ENV": "production",
373403
"CI": "true"
374404
},
375-
"options": "--cpus 2 --memory 4g"
405+
"options": "--cpus 2 --memory 4g",
406+
"ports": [3000, 8080],
407+
"volumes": ["/tmp:/tmp", "/cache:/workspace/cache"],
408+
"credentials": {
409+
"username": "myusername"
410+
}
376411
}
377412
# When using container mode, code-ql and dependency-review are typically disabled
378413
# as they require repository checkout

.github/workflows/continuous-integration.yml

Lines changed: 25 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -99,12 +99,16 @@ on:
9999
"env": {
100100
"NODE_ENV": "production"
101101
},
102-
"options": "--cpus 2"
102+
"options": "--cpus 2",
103+
"ports": [8080, 3000],
104+
"volumes": ["/tmp:/tmp", "/cache:/cache"],
105+
"credentials": {
106+
"username": "myusername"
107+
}
103108
}
104109
```
105110
106-
Supported properties: image (required), env (object), options (string).
107-
Note: ports, volumes, and credentials are not currently supported due to GitHub Actions limitations.
111+
Supported properties: image (required), env (object), options (string), ports (array), volumes (array), credentials (object with username).
108112
109113
See https://docs.github.com/en/actions/how-tos/write-workflows/choose-where-workflows-run/run-jobs-in-a-container
110114
@@ -143,7 +147,10 @@ jobs:
143147
permissions: {}
144148
outputs:
145149
container-image: ${{ steps.parse.outputs.container-image }}
150+
container-env: ${{ steps.parse.outputs.container-env }}
146151
container-options: ${{ steps.parse.outputs.container-options }}
152+
container-ports: ${{ steps.parse.outputs.container-ports }}
153+
container-volumes: ${{ steps.parse.outputs.container-volumes }}
147154
container-username: ${{ steps.parse.outputs.container-username }}
148155
steps:
149156
- id: parse
@@ -191,10 +198,22 @@ jobs:
191198
}
192199
core.setOutput('container-image', container.image);
193200
201+
if (container.env) {
202+
core.setOutput('container-env', JSON.stringify(container.env));
203+
}
204+
194205
if (container.options) {
195206
core.setOutput('container-options', container.options);
196207
}
197208
209+
if (container.ports) {
210+
core.setOutput('container-ports', JSON.stringify(container.ports));
211+
}
212+
213+
if (container.volumes) {
214+
core.setOutput('container-volumes', JSON.stringify(container.volumes));
215+
}
216+
198217
if (container.credentials?.username) {
199218
core.setOutput('container-username', container.credentials.username);
200219
if (!process.env.CONTAINER_PASSWORD) {
@@ -233,7 +252,10 @@ jobs:
233252
needs: prepare
234253
container: &container-setup
235254
image: ${{ needs.prepare.outputs.container-image || '' }}
255+
env: ${{ fromJSON(needs.prepare.outputs.container-env || '{}') }}
236256
options: ${{ needs.prepare.outputs.container-options || ' ' }}
257+
ports: ${{ fromJSON(needs.prepare.outputs.container-ports || '[]') }}
258+
volumes: ${{ fromJSON(needs.prepare.outputs.container-volumes || '[]') }}
237259
credentials: ${{ fromJSON(needs.prepare.outputs.container-username && format('{{"username":{0},"password":{1}}}',toJSON(needs.prepare.outputs.container-username),toJSON(secrets.container-password)) || '{}') }}
238260
permissions:
239261
contents: read

0 commit comments

Comments
 (0)