diff --git a/.github/workflows/docker.yml b/.github/workflows/docker.yml index bd92760..3cd02d6 100644 --- a/.github/workflows/docker.yml +++ b/.github/workflows/docker.yml @@ -20,12 +20,13 @@ jobs: registry: ghcr.io username: ${{ github.actor }} # Uses the GitHub user/org name that triggered the workflow password: ${{ secrets.GITHUB_TOKEN }} # Automatically provided by GitHub + - run: echo "VERSION=$(cat ./src/xcp_ng_dev/files/protocol-version.txt | tr -d '\n')" >> $GITHUB_ENV - uses: docker/build-push-action@v5 # Using v5 for latest features with: - context: ./src/xcp_ng_dev/ - file: ./src/xcp_ng_dev/files/Dockerfile-8.x + context: ./container + file: ./container/Dockerfile-8.x push: ${{ github.ref == 'refs/heads/master' }} - tags: ghcr.io/${{ github.repository }}:8.2 + tags: ghcr.io/${{ github.repository }}:8.2-${{ env.VERSION }} cache-from: type=gha,scope=${{ github.ref_name }}-82 # Cache layers to speed up builds cache-to: type=gha,mode=max,scope=${{ github.ref_name }}-82 # Store layers in cache for future builds build-args: | @@ -46,12 +47,13 @@ jobs: registry: ghcr.io username: ${{ github.actor }} # Uses the GitHub user/org name that triggered the workflow password: ${{ secrets.GITHUB_TOKEN }} # Automatically provided by GitHub + - run: echo "VERSION=$(cat ./src/xcp_ng_dev/files/protocol-version.txt | tr -d '\n')" >> $GITHUB_ENV - uses: docker/build-push-action@v5 # Using v5 for latest features with: - context: ./src/xcp_ng_dev/ - file: ./src/xcp_ng_dev/files/Dockerfile-8.x + context: ./container + file: ./container/Dockerfile-8.x push: ${{ github.ref == 'refs/heads/master' }} - tags: ghcr.io/${{ github.repository }}:8.3 + tags: ghcr.io/${{ github.repository }}:8.3-${{ env.VERSION }} cache-from: type=gha,scope=${{ github.ref_name }}-83 # Cache layers to speed up builds cache-to: type=gha,mode=max,scope=${{ github.ref_name }}-83 # Store layers in cache for future builds platforms: | @@ -71,13 +73,14 @@ jobs: # registry: ghcr.io # username: ${{ github.actor }} # Uses the GitHub user/org name that triggered the workflow # password: ${{ secrets.GITHUB_TOKEN }} # Automatically provided by GitHub + # - run: echo "VERSION=$(cat ./src/xcp_ng_dev/files/protocol-version.txt | tr -d '\n')" >> $GITHUB_ENV # - uses: docker/build-push-action@v5 # Using v5 for latest features # with: - # context: ./src/xcp_ng_dev/ - # file: ./src/xcp_ng_dev/files/Dockerfile-9.x + # context: ./container + # file: ./container/Dockerfile-9.x # platforms: | # linux/amd64/v2 # push: ${{ github.ref == 'refs/heads/master' }} - # tags: ghcr.io/${{ github.repository }}:9.0 + # tags: ghcr.io/${{ github.repository }}:9.0-${{ env.VERSION }} # cache-from: type=gha,scope=${{ github.ref_name }}-90 # Cache layers to speed up builds # cache-to: type=gha,mode=max,scope=${{ github.ref_name }}-90 # Store layers in cache for future builds diff --git a/src/xcp_ng_dev/files/Dockerfile-8.x b/container/Dockerfile-8.x similarity index 100% rename from src/xcp_ng_dev/files/Dockerfile-8.x rename to container/Dockerfile-8.x diff --git a/src/xcp_ng_dev/files/Dockerfile-9.x b/container/Dockerfile-9.x similarity index 100% rename from src/xcp_ng_dev/files/Dockerfile-9.x rename to container/Dockerfile-9.x diff --git a/src/xcp_ng_dev/build.sh b/container/build.sh similarity index 87% rename from src/xcp_ng_dev/build.sh rename to container/build.sh index 30f64a8..4abe67b 100755 --- a/src/xcp_ng_dev/build.sh +++ b/container/build.sh @@ -71,12 +71,12 @@ ALMA_VERSION= CENTOS_VERSION= case "$1" in 9.*) - DOCKERFILE=files/Dockerfile-9.x + DOCKERFILE=Dockerfile-9.x ALMA_VERSION=10.0 : ${PLATFORM:=linux/amd64/v2} ;; 8.*) - DOCKERFILE=files/Dockerfile-8.x + DOCKERFILE=Dockerfile-8.x : ${PLATFORM:=linux/amd64} ;; *) @@ -85,9 +85,12 @@ case "$1" in ;; esac +version_data=$(cat ../src/xcp_ng_dev/files/protocol-version.txt) +version=$(echo "$version_data" | tr -d '\n') + "$RUNNER" build \ --platform "$PLATFORM" \ - -t ghcr.io/xcp-ng/xcp-ng-build-env:${1} \ + -t ghcr.io/xcp-ng/xcp-ng-build-env:${1}-${version} \ --build-arg XCP_NG_BRANCH=${1} \ --ulimit nofile=1024 \ -f $DOCKERFILE . diff --git a/src/xcp_ng_dev/files/Alma10-devel.repo b/container/files/Alma10-devel.repo similarity index 100% rename from src/xcp_ng_dev/files/Alma10-devel.repo rename to container/files/Alma10-devel.repo diff --git a/src/xcp_ng_dev/files/CentOS-Vault.repo.in b/container/files/CentOS-Vault.repo.in similarity index 100% rename from src/xcp_ng_dev/files/CentOS-Vault.repo.in rename to container/files/CentOS-Vault.repo.in diff --git a/src/xcp_ng_dev/files/entrypoint.sh b/container/files/entrypoint.sh similarity index 100% rename from src/xcp_ng_dev/files/entrypoint.sh rename to container/files/entrypoint.sh diff --git a/src/xcp_ng_dev/files/init-container.sh b/container/files/init-container.sh similarity index 100% rename from src/xcp_ng_dev/files/init-container.sh rename to container/files/init-container.sh diff --git a/src/xcp_ng_dev/files/rpmmacros b/container/files/rpmmacros similarity index 100% rename from src/xcp_ng_dev/files/rpmmacros rename to container/files/rpmmacros diff --git a/src/xcp_ng_dev/files/xcp-ng-8.99.repo b/container/files/xcp-ng-8.99.repo similarity index 100% rename from src/xcp_ng_dev/files/xcp-ng-8.99.repo rename to container/files/xcp-ng-8.99.repo diff --git a/src/xcp_ng_dev/files/xcp-ng.repo.7.x.in b/container/files/xcp-ng.repo.7.x.in similarity index 100% rename from src/xcp_ng_dev/files/xcp-ng.repo.7.x.in rename to container/files/xcp-ng.repo.7.x.in diff --git a/src/xcp_ng_dev/files/xcp-ng.repo.8.x.in b/container/files/xcp-ng.repo.8.x.in similarity index 100% rename from src/xcp_ng_dev/files/xcp-ng.repo.8.x.in rename to container/files/xcp-ng.repo.8.x.in diff --git a/src/xcp_ng_dev/files/yum.conf.xs b/container/files/yum.conf.xs similarity index 100% rename from src/xcp_ng_dev/files/yum.conf.xs rename to container/files/yum.conf.xs diff --git a/pyproject.toml b/pyproject.toml index 646665b..f9ae8db 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -12,7 +12,6 @@ dependencies = [ [project.scripts] xcp-ng-dev = "xcp_ng_dev.cli:main" -xcp-ng-dev-env-create = "xcp_ng_dev.cli:build" [project.urls] Homepage = "https://github.com/xcp-ng/xcp-ng-build-env/" diff --git a/src/xcp_ng_dev/cli.py b/src/xcp_ng_dev/cli.py index 642d543..b63c65b 100755 --- a/src/xcp_ng_dev/cli.py +++ b/src/xcp_ng_dev/cli.py @@ -13,6 +13,8 @@ import subprocess import shutil import sys +from pathlib import Path + import argcomplete CONTAINER_PREFIX = "ghcr.io/xcp-ng/xcp-ng-build-env" @@ -37,6 +39,10 @@ def is_podman(runner): return True return False +def read_version(): + with open(Path(__file__).parent / 'files/protocol-version.txt') as f: + return f.read().strip() + def add_common_args(parser): group = parser.add_argument_group("common arguments") group.add_argument('-n', '--no-exit', action='store_true', @@ -235,7 +241,7 @@ def container(args): pass # exec "docker run" - docker_args += [f"{CONTAINER_PREFIX}:{args.container_version}", + docker_args += [f"{CONTAINER_PREFIX}:{args.container_version}-{read_version()}", "/usr/local/bin/init-container.sh"] print("Launching docker with args %s" % docker_args, file=sys.stderr) return subprocess.call(docker_args) @@ -252,10 +258,5 @@ def main(): sys.exit(return_code) -def build(): - bargs = [os.path.join(os.path.dirname(__file__), 'build.sh')] + sys.argv[1:] - return_code = subprocess.call(bargs) - sys.exit(return_code) - if __name__ == "__main__": main() diff --git a/src/xcp_ng_dev/files/protocol-version.txt b/src/xcp_ng_dev/files/protocol-version.txt new file mode 100644 index 0000000..d00491f --- /dev/null +++ b/src/xcp_ng_dev/files/protocol-version.txt @@ -0,0 +1 @@ +1 diff --git a/test/test.sh b/test/test.sh index 34327fd..9250a36 100755 --- a/test/test.sh +++ b/test/test.sh @@ -4,7 +4,7 @@ set -eux TARGET_XCP_NG_VERSION="8.2" -xcp-ng-dev-env-create "$TARGET_XCP_NG_VERSION" +./container/build.sh "$TARGET_XCP_NG_VERSION" REPOS=xcp-emu-manager