Skip to content

Commit

Permalink
Docker - publish image to github container registry
Browse files Browse the repository at this point in the history
  • Loading branch information
zdenekdrahos committed May 8, 2022
1 parent 193382e commit cbcebca
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 9 deletions.
11 changes: 4 additions & 7 deletions .docker/build-image
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,9 @@
# CI_GIT_REF=<refs/heads/feature-branch|refs/tags/v...> 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=""
Expand Down Expand Up @@ -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"
Expand All @@ -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
}

Expand Down
5 changes: 3 additions & 2 deletions .github/workflows/docker.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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

0 comments on commit cbcebca

Please sign in to comment.