From d6d626619ee72cc119cddd56cdb4fac0068d0a9c Mon Sep 17 00:00:00 2001 From: Sven-Hendrik Haase Date: Mon, 19 Oct 2020 22:34:24 +0200 Subject: [PATCH] Refactor to use BUILD_VERSION instead of BUILD_DATE --- .gitlab-ci.yml | 120 +++++++++++++++++++++++-------------------------- ci/release.py | 14 +++--- 2 files changed, 64 insertions(+), 70 deletions(-) diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index 8d52872..6a28c45 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -18,7 +18,7 @@ lint: .rootfs: stage: rootfs before_script: - - echo "BUILD_DATE=$(date +%Y%m%d).$CI_JOB_ID" > build.env + - echo "BUILD_VERSION=$(date +%Y%m%d).$CI_JOB_ID" > build.env - pacman -Syu --noconfirm make devtools fakechroot fakeroot artifacts: paths: @@ -117,7 +117,7 @@ image:base:secure: --whitelist-var-run="false" --context $CI_PROJECT_DIR/output --dockerfile $CI_PROJECT_DIR/output/Dockerfile.base - --destination $CI_REGISTRY_IMAGE:base-$CI_COMMIT_REF_SLUG + --destination $CI_REGISTRY_IMAGE:base image:base-devel:secure: extends: .image @@ -133,31 +133,49 @@ image:base-devel:secure: --whitelist-var-run="false" --context $CI_PROJECT_DIR/output --dockerfile $CI_PROJECT_DIR/output/Dockerfile.base-devel - --destination $CI_REGISTRY_IMAGE:base-devel-$CI_COMMIT_REF_SLUG + --destination $CI_REGISTRY_IMAGE:base-devel + +.test: + script: + - pacman -Sy + - pacman -Qqk + - pacman -Syu --noconfirm docker grep + - docker -v + - id -u http + - locale | grep -q UTF-8 test:base: + extends: .test stage: test image: $CI_REGISTRY_IMAGE:base-$CI_COMMIT_REF_SLUG dependencies: [] - script: - - pacman -Sy - - pacman -Qqk - - pacman -Syu --noconfirm docker grep - - docker -v - - id -u http - - locale | grep -q UTF-8 test:base-devel: + extends: .test stage: test image: $CI_REGISTRY_IMAGE:base-devel-$CI_COMMIT_REF_SLUG dependencies: [] - script: - - pacman -Sy - - pacman -Qqk - - pacman -Syu --noconfirm docker grep - - docker -v - - id -u http - - locale | grep -q UTF-8 + after_script: + - gcc -v + - g++ -v + - make -v + +test:base:secure: + extends: .test + stage: test + tags: + - secure + image: $CI_REGISTRY_IMAGE:base + dependencies: [] + +test:base-devel:secure: + extends: .test + stage: test + tags: + - secure + image: $CI_REGISTRY_IMAGE:base-devel + dependencies: [] + after_script: - gcc -v - g++ -v - make -v @@ -176,52 +194,28 @@ release: script: - python ci/release.py -# Publish base to the Arch Linux group namespace: https://hub.docker.com/r/archlinux/archlinux:base -# publish:org:base: -# stage: publish -# image: -# name: gcr.io/go-containerregistry/crane:debug -# entrypoint: [""] -# needs: -# - job: "test:base" -# artifacts: true -# tags: -# - secure -# variables: -# GIT_STRATEGY: none -# before_script: -# - crane auth login -u $CI_REGISTRY_USER -p $CI_REGISTRY_PASSWORD $CI_REGISTRY -# - crane auth login -u $SOME_TECHNICAL_DOCKER_HUB_USER -p $SOME_TECHNICAL_DOCKER_HUB_PASSWORD archlinux/archlinux -# script: -# - crane cp $CI_REGISTRY_IMAGE:base-$CI_COMMIT_REF_SLUG archlinux/archlinux:base -# - crane tag archlinux/archlinux:base latest -# - crane tag archlinux/archlinux:base base-$BUILD_DATE -# only: -# variables: -# - $SCHEDULED_PUBLISH == "TRUE" - -# Publish base-devel to the Arch Linux group namespace: https://hub.docker.com/r/archlinux/archlinux:base-devel -# publish:org:base-devel: -# stage: publish -# image: -# name: gcr.io/go-containerregistry/crane:debug -# entrypoint: [""] -# needs: -# - job: "test:base-devel" -# artifacts: true -# tags: -# - secure -# variables: -# GIT_STRATEGY: none -# before_script: -# - crane auth login -u $CI_REGISTRY_USER -p $CI_REGISTRY_PASSWORD $CI_REGISTRY -# - crane auth login -u $SOME_TECHNICAL_DOCKER_HUB_USER -p $SOME_TECHNICAL_DOCKER_HUB_PASSWORD archlinux/archlinux -# script: -# - crane cp $CI_REGISTRY_IMAGE:base-devel-$CI_COMMIT_REF_SLUG archlinux/archlinux:base-devel -# - crane tag archlinux/archlinux:base-devel base-devel-$BUILD_DATE -# only: -# variables: -# - $SCHEDULED_PUBLISH == "TRUE" +# Publish base to the Arch Linux group namespace: https://hub.docker.com/r/archlinux/archlinux +publish:base: + stage: publish + tags: + - secure + image: + name: gcr.io/go-containerregistry/crane:debug + entrypoint: [""] + variables: + GIT_STRATEGY: none + before_script: + - echo $CI_REGISTRY_PASSWORD | crane auth login -u $CI_REGISTRY_USER --password-stdin $CI_REGISTRY + - cat $DOCKER_ACCESS_TOKEN | crane auth login -u $DOCKER_USERNAME --password-stdin index.docker.io + script: + - crane cp $CI_REGISTRY_IMAGE:base archlinux/archlinux:base + - crane tag archlinux/archlinux:base latest + - crane tag archlinux/archlinux:base base-$BUILD_VERSION + - crane cp $CI_REGISTRY_IMAGE:base-devel archlinux/archlinux:base-devel + - crane tag archlinux/archlinux:base-devel base-devel-$BUILD_VERSION + only: + variables: + - $SCHEDULED_PUBLISH == "TRUE" # Publish to the official Docker namespace: https://hub.docker.com/_/archlinux # publish:official: diff --git a/ci/release.py b/ci/release.py index 7a44d79..120c843 100755 --- a/ci/release.py +++ b/ci/release.py @@ -5,7 +5,7 @@ Should only be called from GitLab CI! Required env vars: - GITLAB_PROJECT_TOKEN - - BUILD_DATE + - BUILD_VERSION - CI_PROJECT_ID - CI_PROJECT_URL """ @@ -16,14 +16,14 @@ from pathlib import Path import gitlab token = os.environ['GITLAB_PROJECT_TOKEN'] -build_date = os.environ['BUILD_DATE'] +build_version = os.environ['BUILD_VERSION'] project_id = os.environ['CI_PROJECT_ID'] project_url = os.environ['CI_PROJECT_URL'] def upload(name): print(f"Uploading {name}.tar.xz") - filename = f"{name}-{build_date}.tar.xz" + filename = f"{name}-{build_version}.tar.xz" uploaded_url = project.upload( filename, filepath=f"output/{name}.tar.xz" )["url"] @@ -49,7 +49,7 @@ if __name__ == "__main__": print("Templating Dockerfiles") data = { "branch": "add-base-devel-tags", - "commit_message": f"Release {build_date}", + "commit_message": f"Release {build_version}", "actions": [ { "action": "update", @@ -68,9 +68,9 @@ if __name__ == "__main__": print("Creating release") release = project.releases.create( { - "name": f"Release {build_date}", - "tag_name": build_date, - "description": f"Release {build_date}", + "name": f"Release {build_version}", + "tag_name": build_version, + "description": f"Release {build_version}", "ref": "add-base-devel-tags", "assets": { "links": [