Skip to content

Commit

Permalink
chore: setup ghcr publishing
Browse files Browse the repository at this point in the history
  • Loading branch information
targos authored Jun 23, 2021
1 parent daced64 commit 5518f32
Showing 1 changed file with 48 additions and 0 deletions.
48 changes: 48 additions & 0 deletions .github/workflows/dockerimage.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
name: Docker Image CI

on:
push:
tags:
- v*

env:
REGISTRY: ghcr.io
IMAGE_NAME: ${{ github.repository }}

jobs:
build:
name: Build and push image to registry
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2

- name: Build image
run: docker build . --tag $IMAGE_NAME --label "runnumber=${GITHUB_RUN_ID}"

- name: Log in to registry
run: echo "${{ secrets.GITHUB_TOKEN }}" | docker login $REGISTRY -u ${{ github.actor }} --password-stdin

- name: Push image
run: |
IMAGE_ID="${REGISTRY}/${IMAGE_NAME}"
# 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//')
VERSION_START=${VERSION%%.*}
echo IMAGE_ID=$IMAGE_ID
echo VERSION=$VERSION
# Push latest
docker tag $IMAGE_NAME $IMAGE_ID:latest
docker push $IMAGE_ID:latest
# Push full version
docker tag $IMAGE_NAME $IMAGE_ID:$VERSION
docker push $IMAGE_ID:$VERSION
# Push short version
docker tag $IMAGE_NAME $IMAGE_ID:$VERSION_START
docker push $IMAGE_ID:$VERSION_START

0 comments on commit 5518f32

Please sign in to comment.