Skip to content

Commit

Permalink
publish docker image with versions
Browse files Browse the repository at this point in the history
  • Loading branch information
huan committed Jan 7, 2021
1 parent 5f99bb3 commit c8324d0
Show file tree
Hide file tree
Showing 4 changed files with 58 additions and 13 deletions.
31 changes: 19 additions & 12 deletions .github/workflows/docker-publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -52,18 +52,25 @@ jobs:
- name: Log into registry
run: echo "${{ secrets.CR_PAT }}" | docker login ghcr.io -u ${{ github.actor }} --password-stdin

- name: Push image
- name: Push image to ghcr.io
run: |
IMAGE_ID=ghcr.io/${{ github.repository }}
# Change all uppercase to lowercase
IMAGE_ID=$(echo $IMAGE_ID | tr '[A-Z]' '[a-z]')
# Strip git ref prefix from version
VERSION=$(echo "${{ github.ref }}" | sed -e 's,.*/\(.*\),\1,')
# Strip "v" prefix from tag name
[[ "${{ github.ref }}" == "refs/tags/"* ]] && VERSION=$(echo $VERSION | sed -e 's/^v//')
# Use Docker `latest` tag convention
[ "$VERSION" == "main" ] && VERSION=latest
IMAGE_ID=$(./scripts/image_id.sh ${{ github.repository }})
VERSION=`cat VERSION`
BRANCH=$(echo "${{ github.ref }}" | sed -e 's,.*/\(.*\),\1,')
read VERSION_TAG BRANCH_TAG <<< $(./scripts/image_tag.sh $VERSION $BRANCH)
echo IMAGE_ID=$IMAGE_ID
echo VERSION=$VERSION
docker tag $IMAGE_NAME $IMAGE_ID:$VERSION
docker push $IMAGE_ID:$VERSION
echo VERSION_TAG=$VERSION_TAG
echo BRANCH_TAG=$BRANCH_TAG
IMAGE_TAG_VERSION=$IMAGE_ID:$VERSION_TAG
docker tag $IMAGE_NAME $IMAGE_TAG_VERSION
docker push $IMAGE_TAG_VERSION
if [ -n "$BRANCH_TAG" ]; then
IMAGE_TAG_BRANCH=$IMAGE_ID:$BRANCH_TAG
docker tag $IMAGE_NAME $IMAGE_TAG_BRANCH
docker push $IMAGE_TAG_BRANCH
fi
2 changes: 1 addition & 1 deletion VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
20.1.4
20.3.0
14 changes: 14 additions & 0 deletions scripts/image_id.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
#!/usr/bin/env bash

if [ -z "$1" ]; then
>&2 echo "Usage: image_id.sh github_repository"
exit 1
fi

# `zixia/docker-apache-php56` -> `zixia/apache-php56`
IMAGE_ID=$(echo $1 | sed 's/\/docker-/\//')
# Change all uppercase to lowercase
IMAGE_ID=$(echo $IMAGE_ID | tr '[A-Z]' '[a-z]')
IMAGE_ID=ghcr.io/"$IMAGE_ID"

echo $IMAGE_ID
24 changes: 24 additions & 0 deletions scripts/image_tag.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
#!/usr/bin/env bash

if [ -z "$1" -o -z "$2" ]; then
>&2 echo "Usage: image_tag.sh <version> <branch>"
exit 1
fi

VERSION=$1
BRANCH=$2

VERSION_MAJOR=$(echo "$VERSION" | cut -d. -f1)
VERSION_MINOR=$(echo "$VERSION" | cut -d. -f2)

VERSION_TAG="${VERSION_MAJOR}.${VERSION_MINOR}"

if [ $BRANCH == 'main' -o $BRANCH == 'master' ]; then
if [ $((VERSION_MINOR % 2)) == 0 ]; then
BRANCH_TAG=latest
else
BRANCH_TAG=next
fi
fi

echo "$VERSION_TAG" "$BRANCH_TAG"

0 comments on commit c8324d0

Please sign in to comment.