create github action for docker image creation and publication

This commit is contained in:
Abigail Gold 2020-02-25 20:53:31 -05:00 committed by GitHub
parent 1c649aacc2
commit 6b04ab59d1
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 76 additions and 0 deletions

76
.github/workflows/docker.yml vendored Normal file
View File

@ -0,0 +1,76 @@
name: Docker
on:
push:
# Publish `master` as Docker `dev` image.
branches:
- master
# Publish `v1.2.3` tags as releases and as `latest`.
tags:
- v*
env:
IMAGE_NAME: qrm2
jobs:
# Push image to GitHub Package Registry.
# See also https://docs.docker.com/docker-hub/builds/
push:
runs-on: ubuntu-latest
if: github.event_name == 'push'
steps:
- uses: actions/checkout@v2
- name: Build image
run: docker build . --file Dockerfile
- name: Log into Github Package Registry
run: echo "${{ secrets.GITHUB_TOKEN }}" | docker login docker.pkg.github.com -u ${{ github.actor }} --password-stdin
- name: Push image to Github Package Registry
run: |
IMAGE_ID=docker.pkg.github.com/${{ github.repository }}/$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//')
[ "$VERSION" == "master" ] && VERSION=dev
echo IMAGE_ID=$IMAGE_ID
echo VERSION=$VERSION
docker tag image $IMAGE_ID:$VERSION
# use Docker `latest` convention for versioned releases
[[ "$VERSION" != "dev" ]] && docker tag image $IMAGE_ID:latest
docker push $IMAGE_ID:$VERSION
- name: Log out of Github Package Registry
run: docker logout docker.pkg.github.com
- name: Log into Docker Hub
run: echo "${{ secrets.DOCKER_PASSWORD }}" | docker login -u ${{ secrets.DOCKER_USERNAME }} --password-stdin
- name: Push image to Docker Hub
run: |
IMAGE_ID=${{ secrets.DOCKER_USERNAME }}/$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//')
[ "$VERSION" == "master" ] && VERSION=dev
echo IMAGE_ID=$IMAGE_ID
echo VERSION=$VERSION
docker tag image $IMAGE_ID:$VERSION
# use Docker `latest` convention for versioned releases
[[ "$VERSION" != "dev" ]] && docker tag image $IMAGE_ID:latest
docker push $IMAGE_ID:$VERSION