Luke Policinski
2020-07-01 11:59:53 -04:00
committed by GitHub
parent 3cb254e1f5
commit 096a2b2a70

View File

@@ -1,70 +1,19 @@
name: Docker name: Publish Docker image
on: on:
push: release:
# Publish `master` as Docker `latest` image. types: [published]
branches:
- master
# Publish `v1.2.3` tags as releases.
tags:
- v*
# Run tests for any PRs.
pull_request:
env:
IMAGE_NAME: expose-server
jobs: jobs:
# Run tests. push_to_registry:
# See also https://docs.docker.com/docker-hub/builds/automated-testing/ name: Push Docker image to GitHub Packages
test:
runs-on: ubuntu-latest runs-on: ubuntu-latest
steps: steps:
- uses: actions/checkout@v2 - name: Check out the repo
uses: actions/checkout@v2
- name: Run tests - name: Push to GitHub Packages
run: | uses: docker/build-push-action@v1
docker build . --file Dockerfile with:
username: ${{ github.actor }}
# Push image to GitHub Packages. password: ${{ secrets.GITHUB_TOKEN }}
# See also https://docs.docker.com/docker-hub/builds/ registry: docker.pkg.github.com
push: repository: beyondcode/expose/expose-server
# Ensure test job passes before pushing image. tag_with_ref: true
needs: test
runs-on: ubuntu-latest
if: github.event_name == 'push'
steps:
- uses: actions/checkout@v2
- name: Build image
run: docker build . --file Dockerfile --tag $IMAGE_NAME
- name: Log into registry
run: echo "${{ secrets.GITHUB_TOKEN }}" | docker login docker.pkg.github.com -u ${{ github.actor }} --password-stdin
- name: Push image
run: |
IMAGE_ID=docker.pkg.github.com/${{ 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