Skip to content

Commit 51ff63b

Browse files
Copilotneilime
andcommitted
refactor: move container username from secret to input property
Co-authored-by: neilime <[email protected]>
1 parent aa92201 commit 51ff63b

File tree

2 files changed

+40
-25
lines changed

2 files changed

+40
-25
lines changed

.github/workflows/continuous-integration.md

Lines changed: 28 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -207,7 +207,10 @@ container: |
207207
"env": {
208208
"NODE_ENV": "production"
209209
},
210-
"options": "--cpus 2"
210+
"options": "--cpus 2",
211+
"credentials": {
212+
"username": "myusername"
213+
}
211214
}
212215
```
213216

@@ -216,22 +219,28 @@ container: |
216219
- `image` (string, required) - Container image name
217220
- `env` (object) - Environment variables
218221
- `options` (string) - Additional Docker options
222+
- `credentials` (object) - Registry credentials with `username` property
219223

220224
**Note:** `ports` and `volumes` are not currently supported due to GitHub Actions workflow syntax limitations.
221225

222226
#### Container Registry Credentials
223227

224-
For private container images, use the `container-registry-username` and `container-registry-password` secrets:
228+
For private container images, specify the username in the container input's `credentials.username` property and pass the password via the `container-registry-password` secret:
225229

226230
```yaml
227231
jobs:
228232
continuous-integration:
229233
uses: hoverkraft-tech/ci-github-nodejs/.github/workflows/continuous-integration.yml@main
230234
secrets:
231-
container-registry-username: ${{ secrets.REGISTRY_USERNAME }}
232235
container-registry-password: ${{ secrets.REGISTRY_PASSWORD }}
233236
with:
234-
container: "ghcr.io/myorg/my-private-image:latest"
237+
container: |
238+
{
239+
"image": "ghcr.io/myorg/my-private-image:latest",
240+
"credentials": {
241+
"username": "myusername"
242+
}
243+
}
235244
```
236245

237246
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.
@@ -242,16 +251,14 @@ When specified, steps will execute inside this container instead of checking out
242251

243252
## Secrets
244253

245-
| **Secret** | **Description** | **Required** |
246-
| --------------------------------- | -------------------------------------------------------------------------------------------------------------------- | ------------ |
247-
| **`build-secrets`** | Secrets to be used during the build step. | **false** |
248-
| | Must be a multi-line env formatted string. | |
249-
| | Example: | |
250-
| | <!-- textlint-disable --><pre lang="txt">SECRET_EXAMPLE=$\{{ secrets.SECRET_EXAMPLE }}</pre><!-- textlint-enable --> | |
251-
| **`container-registry-username`** | Username for authenticating to the container registry. | **false** |
252-
| | Required when using private container images. | |
253-
| **`container-registry-password`** | Password or token for authenticating to the container registry. | **false** |
254-
| | Required when using private container images. | |
254+
| **Secret** | **Description** | **Required** |
255+
| --------------------------------- | ---------------------------------------------------------------------------------------------------------------------------------------- | ------------ |
256+
| **`build-secrets`** | Secrets to be used during the build step. | **false** |
257+
| | Must be a multi-line env formatted string. | |
258+
| | Example: | |
259+
| | <!-- textlint-disable --><pre lang="txt">SECRET_EXAMPLE=$\{{ secrets.SECRET_EXAMPLE }}</pre><!-- textlint-enable --> | |
260+
| **`container-registry-password`** | Password or token for authenticating to the container registry. | **false** |
261+
| | Required when using private container images. The username should be specified in the container input's `credentials.username` property. | |
255262

256263
<!-- secrets:end -->
257264

@@ -367,7 +374,7 @@ jobs:
367374

368375
### Continuous Integration with Advanced Container Options
369376

370-
This example shows how to use advanced container options like environment variables and additional Docker options.
377+
This example shows how to use advanced container options like environment variables, credentials, and additional Docker options.
371378

372379
```yaml
373380
name: Continuous Integration - Advanced Container Options
@@ -383,14 +390,19 @@ jobs:
383390
id-token: write
384391
security-events: write
385392
contents: read
393+
secrets:
394+
container-registry-password: ${{ secrets.REGISTRY_PASSWORD }}
386395
with:
387396
container: |
388397
{
389-
"image": "node:18-alpine",
398+
"image": "ghcr.io/myorg/node-image:18-alpine",
390399
"env": {
391400
"NODE_ENV": "production",
392401
"CI": "true"
393402
},
403+
"credentials": {
404+
"username": "myusername"
405+
},
394406
"options": "--cpus 2 --memory 4g"
395407
}
396408
# When using container mode, code-ql and dependency-review are typically disabled

.github/workflows/continuous-integration.yml

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -126,15 +126,11 @@ on:
126126
SECRET_EXAMPLE=$\{{ secrets.SECRET_EXAMPLE }}
127127
```
128128
required: false
129-
container-registry-username:
130-
description: |
131-
Username for authenticating to the container registry.
132-
Required when using private container images.
133-
required: false
134129
container-registry-password:
135130
description: |
136131
Password or token for authenticating to the container registry.
137132
Required when using private container images.
133+
The username should be specified in the container input's credentials.username property.
138134
required: false
139135
outputs:
140136
build-artifact-id:
@@ -180,6 +176,13 @@ jobs:
180176
config.env = container.env;
181177
}
182178
179+
// Add credentials username if provided
180+
if (container.credentials && container.credentials.username) {
181+
config.credentials = {
182+
username: container.credentials.username
183+
};
184+
}
185+
183186
// Merge user options with default --user root:root
184187
if (container.options) {
185188
config.options = `${config.options} ${container.options}`;
@@ -226,7 +229,7 @@ jobs:
226229
env: ${{ inputs.container != '' && fromJSON(needs.parse-container.outputs.config).env || null }}
227230
options: ${{ inputs.container != '' && fromJSON(needs.parse-container.outputs.config).options || null }}
228231
credentials:
229-
username: ${{ secrets.container-registry-username }}
232+
username: ${{ inputs.container != '' && fromJSON(needs.parse-container.outputs.config).credentials.username || null }}
230233
password: ${{ secrets.container-registry-password }}
231234
needs: parse-container
232235
if: ${{ always() && !cancelled() && !failure() }}
@@ -350,7 +353,7 @@ jobs:
350353
env: ${{ inputs.container != '' && fromJSON(needs.parse-container.outputs.config).env || null }}
351354
options: ${{ inputs.container != '' && fromJSON(needs.parse-container.outputs.config).options || null }}
352355
credentials:
353-
username: ${{ secrets.container-registry-username }}
356+
username: ${{ inputs.container != '' && fromJSON(needs.parse-container.outputs.config).credentials.username || null }}
354357
password: ${{ secrets.container-registry-password }}
355358
needs:
356359
- parse-container
@@ -412,7 +415,7 @@ jobs:
412415
env: ${{ inputs.container != '' && fromJSON(needs.parse-container.outputs.config).env || null }}
413416
options: ${{ inputs.container != '' && fromJSON(needs.parse-container.outputs.config).options || null }}
414417
credentials:
415-
username: ${{ secrets.container-registry-username }}
418+
username: ${{ inputs.container != '' && fromJSON(needs.parse-container.outputs.config).credentials.username || null }}
416419
password: ${{ secrets.container-registry-password }}
417420
needs:
418421
- parse-container
@@ -464,7 +467,7 @@ jobs:
464467
env: ${{ inputs.container != '' && fromJSON(needs.parse-container.outputs.config).env || null }}
465468
options: ${{ inputs.container != '' && fromJSON(needs.parse-container.outputs.config).options || null }}
466469
credentials:
467-
username: ${{ secrets.container-registry-username }}
470+
username: ${{ inputs.container != '' && fromJSON(needs.parse-container.outputs.config).credentials.username || null }}
468471
password: ${{ secrets.container-registry-password }}
469472
needs:
470473
- parse-container

0 commit comments

Comments
 (0)