Skip to content

Commit

Permalink
Merge pull request #18 from idrop/package-to-ghcr
Browse files Browse the repository at this point in the history
Package to GHCR
  • Loading branch information
idrop authored Feb 11, 2021
2 parents 3d340cd + e7fca15 commit 7b7fbdb
Showing 1 changed file with 48 additions and 0 deletions.
48 changes: 48 additions & 0 deletions .github/workflows/ghcr-package.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
name: Publish container image to ghcr.io

on:
release:
types: [published]

env:
# TODO: Change variable to your image's name.
IMAGE_NAME: cloudwatch-metrics

jobs:
# Push image to GitHub Packages.
# See also https://docs.docker.com/docker-hub/builds/
ghr_push:
runs-on: ubuntu-latest
if: github.event_name == 'release'

steps:
- uses: actions/checkout@v2

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

- name: Log into GitHub Container Registry
# TODO: Create a PAT with `read:packages` and `write:packages` scopes and save it as an Actions secret `CR_PAT`
run: echo "${{ secrets.GHCR_PAT }}" | docker login https://ghcr.io -u ${{ github.actor }} --password-stdin

- name: Push image to GitHub Container Registry
run: |
IMAGE_ID=ghcr.io/${{ github.repository }}/$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
echo IMAGE_ID=$IMAGE_ID
echo VERSION=$VERSION
docker tag $IMAGE_NAME $IMAGE_ID:$VERSION
docker push $IMAGE_ID:$VERSION

0 comments on commit 7b7fbdb

Please sign in to comment.