Skip to content

Commit 8cd9978

Browse files
committed
Add a version in the image tag
so we can change the interface used to communicate with the container. Using an image tag allows to automatically download the expected image on the developer's computer in case of update. In the future, if we distribute tagged versions of xcp-ng-dev (on pypi for example), we might want to use that version instead. Signed-off-by: Gaëtan Lehmann <[email protected]>
1 parent 6dac1c8 commit 8cd9978

File tree

4 files changed

+18
-5
lines changed

4 files changed

+18
-5
lines changed

.github/workflows/docker.yml

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,12 +20,13 @@ jobs:
2020
registry: ghcr.io
2121
username: ${{ github.actor }} # Uses the GitHub user/org name that triggered the workflow
2222
password: ${{ secrets.GITHUB_TOKEN }} # Automatically provided by GitHub
23+
- run: echo "VERSION=$(cat ./src/xcp_ng_dev/files/protocol-version.txt | tr -d '\n')" >> $GITHUB_ENV
2324
- uses: docker/build-push-action@v5 # Using v5 for latest features
2425
with:
2526
context: ./container
2627
file: ./container/Dockerfile-8.x
2728
push: ${{ github.ref == 'refs/heads/master' }}
28-
tags: ghcr.io/${{ github.repository }}:8.2
29+
tags: ghcr.io/${{ github.repository }}:8.2-${{ env.VERSION }}
2930
cache-from: type=gha,scope=${{ github.ref_name }}-82 # Cache layers to speed up builds
3031
cache-to: type=gha,mode=max,scope=${{ github.ref_name }}-82 # Store layers in cache for future builds
3132
build-args: |
@@ -46,12 +47,13 @@ jobs:
4647
registry: ghcr.io
4748
username: ${{ github.actor }} # Uses the GitHub user/org name that triggered the workflow
4849
password: ${{ secrets.GITHUB_TOKEN }} # Automatically provided by GitHub
50+
- run: echo "VERSION=$(cat ./src/xcp_ng_dev/files/protocol-version.txt | tr -d '\n')" >> $GITHUB_ENV
4951
- uses: docker/build-push-action@v5 # Using v5 for latest features
5052
with:
5153
context: ./container
5254
file: ./container/Dockerfile-8.x
5355
push: ${{ github.ref == 'refs/heads/master' }}
54-
tags: ghcr.io/${{ github.repository }}:8.3
56+
tags: ghcr.io/${{ github.repository }}:8.3-${{ env.VERSION }}
5557
cache-from: type=gha,scope=${{ github.ref_name }}-83 # Cache layers to speed up builds
5658
cache-to: type=gha,mode=max,scope=${{ github.ref_name }}-83 # Store layers in cache for future builds
5759
platforms: |
@@ -71,13 +73,14 @@ jobs:
7173
# registry: ghcr.io
7274
# username: ${{ github.actor }} # Uses the GitHub user/org name that triggered the workflow
7375
# password: ${{ secrets.GITHUB_TOKEN }} # Automatically provided by GitHub
76+
# - run: echo "VERSION=$(cat ./src/xcp_ng_dev/files/protocol-version.txt | tr -d '\n')" >> $GITHUB_ENV
7477
# - uses: docker/build-push-action@v5 # Using v5 for latest features
7578
# with:
7679
# context: ./container
7780
# file: ./container/Dockerfile-9.x
7881
# platforms: |
7982
# linux/amd64/v2
8083
# push: ${{ github.ref == 'refs/heads/master' }}
81-
# tags: ghcr.io/${{ github.repository }}:9.0
84+
# tags: ghcr.io/${{ github.repository }}:9.0-${{ env.VERSION }}
8285
# cache-from: type=gha,scope=${{ github.ref_name }}-90 # Cache layers to speed up builds
8386
# cache-to: type=gha,mode=max,scope=${{ github.ref_name }}-90 # Store layers in cache for future builds

container/build.sh

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,9 +85,12 @@ case "$1" in
8585
;;
8686
esac
8787

88+
version_data=$(cat ../src/xcp_ng_dev/files/protocol-version.txt)
89+
version=$(echo "$version_data" | tr -d '\n')
90+
8891
"$RUNNER" build \
8992
--platform "$PLATFORM" \
90-
-t ghcr.io/xcp-ng/xcp-ng-build-env:${1} \
93+
-t ghcr.io/xcp-ng/xcp-ng-build-env:${1}-${version} \
9194
--build-arg XCP_NG_BRANCH=${1} \
9295
--ulimit nofile=1024 \
9396
-f $DOCKERFILE .

src/xcp_ng_dev/cli.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@
1313
import subprocess
1414
import shutil
1515
import sys
16+
from pathlib import Path
17+
1618
import argcomplete
1719

1820
CONTAINER_PREFIX = "ghcr.io/xcp-ng/xcp-ng-build-env"
@@ -37,6 +39,10 @@ def is_podman(runner):
3739
return True
3840
return False
3941

42+
def read_version():
43+
with open(Path(__file__).parent / 'files/protocol-version.txt') as f:
44+
return f.read().strip()
45+
4046
def add_common_args(parser):
4147
group = parser.add_argument_group("common arguments")
4248
group.add_argument('-n', '--no-exit', action='store_true',
@@ -240,7 +246,7 @@ def container(args):
240246
pass
241247

242248
# exec "docker run"
243-
docker_args += [f"{CONTAINER_PREFIX}:{args.container_version}",
249+
docker_args += [f"{CONTAINER_PREFIX}:{args.container_version}-{read_version()}",
244250
"/usr/local/bin/init-container.sh"]
245251
print("Launching docker with args %s" % docker_args, file=sys.stderr)
246252
return subprocess.call(docker_args)
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
1

0 commit comments

Comments
 (0)