Skip to content

Commit

Permalink
Also push container to GHCR
Browse files Browse the repository at this point in the history
  • Loading branch information
greboid authored Apr 3, 2021
1 parent 36be61b commit 19fd18e
Showing 1 changed file with 17 additions and 12 deletions.
29 changes: 17 additions & 12 deletions .github/workflows/docker-publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,7 @@ on:
tags:
- v*
env:
IMAGE_NAME: mdbot/wiki
IMAGE_MIRROR: repo.treescale.com/greboid/wiki
IMAGE_NAME: wiki

jobs:
push:
Expand All @@ -17,33 +16,39 @@ jobs:
steps:
- uses: actions/checkout@v2

- name: Log into registry
- name: Log into registry (docker hub)
run: echo "${{ secrets.DOCKER_HUB_TOKEN }}" | docker login -u "${{ secrets.DOCKER_HUB_USER }}" --password-stdin

- name: Build image
run: docker build . --tag $IMAGE_NAME

- name: Push image
- name: Push image (docker hub)
run: |
IMAGE_ID=${{ github.repository_owner }}/$IMAGE_NAME
# 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" == "master" ] && VERSION=latest
docker tag $IMAGE_NAME $IMAGE_NAME:$VERSION
docker push $IMAGE_NAME:$VERSION
docker tag $IMAGE_NAME $IMAGE_ID:$VERSION
docker push $IMAGE_ID:$VERSION
- name: Log into registry (mirror)
run: echo "${{ secrets.REG_HUB_TOKEN }}" | docker login repo.treescale.com -u "${{ secrets.REG_HUB_USER }}" --password-stdin
- name: Log into registry (ghcr.io)
run: echo "${{ secrets.GITHUB_TOKEN }}" | docker login ghcr.io -u ${{ github.actor }} --password-stdin

- name: Push image (mirror)
run: |
- name: Push image (ghcr.io)
run: |
IMAGE_ID=ghcr.io/${{ github.repository_owner }}/$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//')
# Use Docker `latest` tag convention
[ "$VERSION" == "master" ] && VERSION=latest
docker tag $IMAGE_NAME IMAGE_MIRROR:$VERSION
docker push IMAGE_MIRROR:$VERSION
docker tag $IMAGE_NAME $IMAGE_ID:$VERSION
docker push $IMAGE_ID:$VERSION

0 comments on commit 19fd18e

Please sign in to comment.