Skip to content

Commit

Permalink
Migrate to Github Docker registry
Browse files Browse the repository at this point in the history
  • Loading branch information
Antoine Finkelstein authored Oct 19, 2020
1 parent 44c7454 commit ad1baa0
Showing 1 changed file with 12 additions and 22 deletions.
34 changes: 12 additions & 22 deletions .github/workflows/dockerpublish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@ name: Docker

on:
push:
# Publish `master` as Docker `latest` image.
# Publish `develop` as Docker `latest` image.
branches:
- master
- develop

# Publish `v1.2.3` tags as releases.
tags:
Expand All @@ -14,7 +14,8 @@ on:
pull_request:

env:
IMAGE_NAME: hunterio/wappalyzer-api
# TODO: Change variable to your image's name.
IMAGE_NAME: wappalyzer-api

jobs:
# Push image to GitHub Packages.
Expand All @@ -27,35 +28,24 @@ jobs:
- uses: actions/checkout@v2

- name: Build image
run: |
IMAGE_ID=$IMAGE_NAME
# Change all uppercase to lowercase
IMAGE_ID=$(echo $IMAGE_ID | tr '[A-Z]' '[a-z]')
docker build --cache-from $IMAGE_ID:latest . --file Dockerfile --tag image
run: docker build . --file Dockerfile --tag $IMAGE_NAME

- name: Log into registry
run: echo "${{ secrets.DOCKER_HUB_TOKEN }}" | docker login -u ${{ secrets.DOCKER_HUB_USERNAME }} --password-stdin
- 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.CR_PAT }}" | docker login https://ghcr.io -u ${{ github.actor }} --password-stdin

- name: Push image
- name: Push image to GitHub Container Registry
run: |
IMAGE_ID=$IMAGE_NAME
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
[ "$VERSION" == "develop" ] && VERSION=latest
echo IMAGE_ID=$IMAGE_ID
echo VERSION=$VERSION
docker tag image $IMAGE_ID:$VERSION
docker tag $IMAGE_NAME $IMAGE_ID:$VERSION
docker push $IMAGE_ID:$VERSION

0 comments on commit ad1baa0

Please sign in to comment.