Skip to content

Commit 8cb51c2

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 626b652 commit 8cb51c2

File tree

4 files changed

+16
-5
lines changed

4 files changed

+16
-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/version.txt | tr -d '\n')" >> $GITHUB_ENV
2324
- uses: docker/build-push-action@v5 # Using v5 for latest features
2425
with:
2526
context: ./src/xcp_ng_dev/
2627
file: ./src/xcp_ng_dev/files/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/version.txt | tr -d '\n')" >> $GITHUB_ENV
4951
- uses: docker/build-push-action@v5 # Using v5 for latest features
5052
with:
5153
context: ./src/xcp_ng_dev/
5254
file: ./src/xcp_ng_dev/files/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/version.txt | tr -d '\n')" >> $GITHUB_ENV
7477
# - uses: docker/build-push-action@v5 # Using v5 for latest features
7578
# with:
7679
# context: ./src/xcp_ng_dev/
7780
# file: ./src/xcp_ng_dev/files/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

src/xcp_ng_dev/build.sh

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

88+
version=`cat ./files/version.txt | tr -d '\n'`
89+
8890
"$RUNNER" build \
8991
--platform "$PLATFORM" \
90-
-t ghcr.io/xcp-ng/xcp-ng-build-env:${1} \
92+
-t ghcr.io/xcp-ng/xcp-ng-build-env:${1}-${version} \
9193
--build-arg XCP_NG_BRANCH=${1} \
9294
--ulimit nofile=1024 \
9395
-f $DOCKERFILE .

src/xcp_ng_dev/cli.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
import sys
1616
import uuid
1717
import argcomplete
18+
from pathlib import Path
1819

1920
CONTAINER_PREFIX = "ghcr.io/xcp-ng/xcp-ng-build-env"
2021

@@ -38,6 +39,10 @@ def is_podman(runner):
3839
return True
3940
return False
4041

42+
def read_version():
43+
with open(Path(__file__).parent / 'files/version.txt') as f:
44+
return f.read().strip()
45+
4146
def add_common_args(parser):
4247
parser.add_argument('branch',
4348
help='The version of XCP-ng to prepare for the build. For example, 8.3.')
@@ -225,7 +230,7 @@ def container(args):
225230
docker_args += ["--ulimit", "nofile=%s" % DEFAULT_ULIMIT_NOFILE]
226231

227232
# exec "docker run"
228-
docker_args += ["%s:%s" % (CONTAINER_PREFIX, branch),
233+
docker_args += ["%s:%s-%s" % (CONTAINER_PREFIX, branch, read_version()),
229234
"/usr/local/bin/init-container.sh"]
230235
print("Launching docker with args %s" % docker_args, file=sys.stderr)
231236
return subprocess.call(docker_args)

src/xcp_ng_dev/files/version.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
1

0 commit comments

Comments
 (0)