From 75b72d1f03f14ec18d028d78776ce138f9ee80b3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Zdene=CC=8Ck=20Drahos=CC=8C?= Date: Sun, 8 May 2022 09:07:27 +0200 Subject: [PATCH] Docker - publish image to github container registry https://docs.github.com/en/packages/working-with-a-github-packages-registry/working-with-the-container-registry https://docs.github.com/en/actions/publishing-packages/publishing-docker-images --- .docker/build-image | 11 ++++------- .github/workflows/docker.yml | 5 +++-- 2 files changed, 7 insertions(+), 9 deletions(-) diff --git a/.docker/build-image b/.docker/build-image index 793302d..195f768 100755 --- a/.docker/build-image +++ b/.docker/build-image @@ -3,8 +3,9 @@ # CI_GIT_REF= CI_COMMIT_SHA=$(git rev-parse --short HEAD) .docker/build-image APP_DIR="./" -DOCKER_REPO="zdenekdrahos/phpqa" +DOCKER_REPO="EdgedesignCZ/phpqa" DOCKER_FILE=".docker/Dockerfile" +DOCKER_REGISTRY=${DOCKER_REGISTRY:-"ghcr.io"} DOCKER_TAG="" GIT_VERSION="" GIT_TAG="" @@ -37,7 +38,7 @@ load_docker_variables () { echo "PHP version $PHP_VERSION not supported" exit 1 fi - DOCKER_TAG="$DOCKER_REPO:$GIT_VERSION-php$PHP_VERSION" + DOCKER_TAG="$DOCKER_REGISTRY/$DOCKER_REPO:$GIT_VERSION-php$PHP_VERSION" echo "Dockefile: $DOCKER_FILE" echo "Build vars: COMPOSER_VERSION=$COMPOSER_VERSION UPDATE_COMPOSER=$UPDATE_COMPOSER" @@ -55,11 +56,7 @@ build_docker_image () { --build-arg "UPDATE_COMPOSER=$UPDATE_COMPOSER" docker run --rm -t $DOCKER_TAG sh -c "php --version && composer --version && composer outdated --direct --all && phpqa tools" - if [ -z "$GIT_TAG" ]; then - echo "Docker image is published only if the current build is for a git tag" - exit 0 - fi - docker login --username $DOCKER_USER --password $DOCKER_TOKEN + docker login --username $DOCKER_USER --password $DOCKER_TOKEN $DOCKER_REGISTRY time docker push $DOCKER_TAG } diff --git a/.github/workflows/docker.yml b/.github/workflows/docker.yml index 6c02e91..9b0fb6d 100644 --- a/.github/workflows/docker.yml +++ b/.github/workflows/docker.yml @@ -21,8 +21,9 @@ jobs: env: CI_GIT_REF: ${{ github.ref }} CI_COMMIT_SHA: ${{ github.sha }} - DOCKER_USER: ${{ secrets.DOCKER_USER }} - DOCKER_TOKEN: ${{ secrets.DOCKER_TOKEN }} + DOCKER_USER: ${{ github.actor }} + DOCKER_TOKEN: ${{ secrets.GITHUB_TOKEN }} + DOCKER_REGISTRY: ghcr.io run: | PHP_VERSION=7.2 .docker/build-image PHP_VERSION=8.1 .docker/build-image