From 1ddc0549a231346d043754fbceed380bde0ec952 Mon Sep 17 00:00:00 2001 From: Xuan Hu Date: Wed, 31 Jan 2024 10:45:33 +0000 Subject: [PATCH] Add container-publish for GitLab CI/CD. --- .gitlab/workflows/release.yml | 48 +++++++++++++++++++++++++++++++++++ 1 file changed, 48 insertions(+) diff --git a/.gitlab/workflows/release.yml b/.gitlab/workflows/release.yml index 1be468bb..1409a0b3 100644 --- a/.gitlab/workflows/release.yml +++ b/.gitlab/workflows/release.yml @@ -23,6 +23,54 @@ release-publish: script: - echo "Running the release job." stage: release +container-publish: + image: docker:latest + needs: + - release-publish + parallel: + matrix: + - PYTHON_VERSION: + - '3.8' + - '3.9' + - '3.10' + - '3.11' + - '3.12' + rules: + - if: $CI_COMMIT_TAG =~ /^v?(0|[1-9][0-9]*)\.(0|[1-9][0-9]*)\.(0|[1-9][0-9]*)(-?(a|b|rc)(0|[1-9][0-9]*)?)?$/ + script: + - docker login -u ${CI_REGISTRY_USER} -p ${CI_REGISTRY_PASSWORD} ${CI_REGISTRY} + - docker context create builder + - docker buildx create builder --name container --driver docker-container --use + - docker buildx inspect --bootstrap --builder container + - | + docker buildx build . \ + --build-arg PYTHON_VERSION=${PYTHON_VERSION} \ + --cache-from type=registry,ref=${CI_REGISTRY_IMAGE}:build-cache-dev-py${PYTHON_VERSION} \ + --cache-to type=registry,ref=${CI_REGISTRY_IMAGE}:build-cache-dev-py${PYTHON_VERSION},mode=max \ + --file .devcontainer/Dockerfile \ + --provenance false \ + --push \ + --tag ${CI_REGISTRY_IMAGE}:dev-py${PYTHON_VERSION} \ + --tag ${CI_REGISTRY_IMAGE}:dev-py${PYTHON_VERSION}-${CI_COMMIT_TAG} \ + --target dev + - | + docker buildx build . \ + --build-arg PDM_BUILD_SCM_VERSION=${CI_COMMIT_TAG} \ + --build-arg PYTHON_VERSION=${PYTHON_VERSION} \ + --cache-from type=registry,ref=${CI_REGISTRY_IMAGE}:build-cache-dev-py${PYTHON_VERSION} \ + --file .devcontainer/Dockerfile \ + --provenance false \ + --push \ + --tag ${CI_REGISTRY_IMAGE}:prod-py${PYTHON_VERSION} \ + --tag ${CI_REGISTRY_IMAGE}:prod-py${PYTHON_VERSION}-${CI_COMMIT_TAG} \ + --target prod + services: + - docker:dind + stage: release + variables: + DOCKER_TLS_CERTDIR: /certs + PYTHON_VERSION: ${PYTHON_VERSION} + SOURCE_DATE_EPOCH: 0 package-publish: needs: - release-publish