Skip to content

Commit 169e0c4

Browse files
authored
Rework Container CI (#7)
1 parent a653d00 commit 169e0c4

File tree

6 files changed

+37
-22
lines changed

6 files changed

+37
-22
lines changed

.github/workflows/ci.yaml

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
name: 'Validate DevContainer'
2-
description: 'This workflow is checking that updates do not break stuff. If on main branch, publish to latest tag.'
2+
description: 'This workflow is checking that updates do not break stuff. If on main branch, publish to "latest" tag.'
33
on:
44
pull_request:
55
push:
@@ -34,6 +34,9 @@ jobs:
3434
- name: Check, Build, Test
3535
uses: devcontainers/ci@v0.3
3636
with:
37+
# The .devcontainer is never published as pre-built container.
38+
# We want to only use it for building and testing the actual container, which resides in src/s-core-devcontainer.
39+
push: "never"
3740
runCmd: |
3841
# Check
3942
pre-commit run --show-diff-on-failure --color=always --all-files || exit -1
@@ -47,10 +50,12 @@ jobs:
4750
# Upload devcontainer from src/s-core-devcontainer
4851
- name: Publish
4952
uses: devcontainers/ci@v0.3
53+
if: github.ref == 'refs/heads/main'
5054
with:
51-
cacheFrom: ghcr.io/eclipse-score/devcontainer
52-
imageName: ghcr.io/eclipse-score/devcontainer
53-
# publish latest from main branch; tags are handled in release workflow
54-
imageTag: latest
55-
refFilterForPush: 'refs/heads/main'
56-
subFolder: src/s-core-devcontainer
55+
# We do not use the push feature of devcontainers/ci here, since that would push the wrong container.
56+
# Instead, we use the publish script which pushes the correct container (residing in src/s-core-devcontainer).
57+
push: "never"
58+
runCmd: |
59+
# manually login to ghcr.io for publishing
60+
echo "${{ secrets.GITHUB_TOKEN }}" | docker login ghcr.io -u ${{ github.actor }} --password-stdin
61+
./scripts/publish.sh "latest"

.github/workflows/release.yaml

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,9 @@ jobs:
2929
- name: Check, Build, Test
3030
uses: devcontainers/ci@v0.3
3131
with:
32+
# The .devcontainer is never published as pre-built container.
33+
# We want to only use it for building and testing the actual container, which resides in src/s-core-devcontainer.
34+
push: "never"
3235
runCmd: |
3336
# Check
3437
pre-commit run --show-diff-on-failure --color=always --all-files || exit -1
@@ -43,7 +46,9 @@ jobs:
4346
- name: Publish
4447
uses: devcontainers/ci@v0.3
4548
with:
46-
imageName: ghcr.io/eclipse-score/devcontainer
47-
cacheFrom: ghcr.io/eclipse-score/devcontainer
48-
imageTag: ${{ github.ref_name }}
49-
subFolder: src/s-core-devcontainer
49+
# We do not use the push feature of devcontainers/ci here, since that would push the wrong container.
50+
# Instead, we use the publish script which pushes the correct container (residing in src/s-core-devcontainer).
51+
push: "never"
52+
runCmd: |
53+
# Note: "${{ github.ref_name }}" will be the tag name, e.g., "1.0.0"
54+
./scripts/publish.sh "${{ github.ref_name }}"

README.md

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ They are used by the CI, but especially the build and test scripts can be run al
9191
````console
9292
$ ./scripts/build.sh
9393
[... build output..]
94-
{"outcome":"success","imageName":["vsc-s-core-devcontainer-209943ec6ff795f57b20cdf85a70c904d1e3b4a329d1e01c79f0ffea615c6e40-features"]}
94+
{"outcome":"success","imageName":["ghcr.io/eclipse-score/devcontainer"]}
9595

9696
$ ./scripts/test.sh
9797
[... test output...]
@@ -112,16 +112,15 @@ So in order to execute `S-CORE DevContainer` on your host (and test it as part o
112112

113113
* export this newly built S-CORE DevContainer image
114114
* import the image on your host machine
115-
* use the image name in the `.devcontainer/devcontainer.json` of the targeted S-CORE module
115+
* use the image name and tag `latest` in the `.devcontainer/devcontainer.json` of the targeted S-CORE module
116116

117117
Concretely, this can be done as follows:
118118

119-
* Run `docker save <imageName> > export.img` in `Development Container A`.
120-
For example, given above build output, this would be `docker save vsc-s-core-devcontainer-209943ec6ff795f57b20cdf85a70c904d1e3b4a329d1e01c79f0ffea615c6e40-features > export.img`
119+
* Run `docker save "ghcr.io/eclipse-score/devcontainer" > export.img` in `Development Container A`.
121120
* On your **host machine** (!!), open a console and run `docker load < /path/to/export.img`.
122-
* In the working copy of the targeted S-CORE module, edit the file `.devcontainer/devcontainer.json` and change the `"image": "..."` entry to `"image": "<imageName>"`.
123-
Given above build output, this would be `"image": "vsc-s-core-devcontainer-209943ec6ff795f57b20cdf85a70c904d1e3b4a329d1e01c79f0ffea615c6e40-features"`.
121+
* In the working copy of the targeted S-CORE module, edit the file `.devcontainer/devcontainer.json` and change the `"image": "..."` entry to `"image": "ghcr.io/eclipse-score/devcontainer:latest"` (if not already set like this).
124122
The Visual Studio Code instance related to the targeted S-CORE module will now ask you to rebuild the DevContainer.
123+
If not, press <kbd>Ctrl</kbd> + <kbd>Shift</kbd> + <kbd>p</kbd> and run from there "Dev Containers: Rebuilt Container Without Cache".
125124
Do so, and you have a running instance of `S-CORE DevContainer` related to the targeted S-CORE module.
126125

127126
### Version Pinning

scripts/build.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
#!/usr/bin/env bash
22
set -euxo pipefail
33

4-
devcontainer build --workspace-folder src/s-core-devcontainer
4+
devcontainer build --workspace-folder src/s-core-devcontainer --image-name ghcr.io/eclipse-score/devcontainer:latest --cache-from ghcr.io/eclipse-score/devcontainer

scripts/publish.sh

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
#!/usr/bin/env bash
2+
set -euxo pipefail
3+
4+
TAG="${1:-latest}"
5+
6+
if [[ "$TAG" != "latest" ]]; then
7+
docker tag "ghcr.io/eclipse-score/devcontainer:latest" "ghcr.io/eclipse-score/devcontainer:${TAG}"
8+
fi
9+
10+
docker push "ghcr.io/eclipse-score/devcontainer:${TAG}"

scripts/test.sh

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,6 @@ devcontainer up \
1515
--workspace-folder "${PROJECT_DIR}/src/${IMAGE}/" \
1616
--remove-existing-container
1717

18-
CONTAINER_ID=$(docker container ls --filter "label=${ID_LABEL}" --quiet)
19-
IMAGE_NAME=$(docker container inspect --format '{{ .Config.Image }}' "${CONTAINER_ID}")
20-
IMAGE_ID=$(docker image ls --filter "reference=${IMAGE_NAME}" --quiet)
21-
2218
# Run actual test
2319
echo "(*) Running test..."
2420
devcontainer exec --workspace-folder "${PROJECT_DIR}/src/${IMAGE}" --id-label "${ID_LABEL}" \

0 commit comments

Comments
 (0)