Skip to content

Commit

Permalink
feat: add Docker GitHub actions
Browse files Browse the repository at this point in the history
  • Loading branch information
moul committed Oct 9, 2020
1 parent 85f4f6b commit df4c29f
Show file tree
Hide file tree
Showing 2 changed files with 68 additions and 7 deletions.
67 changes: 67 additions & 0 deletions .github/workflows/docker.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
name: Docker
on:
push:
tags: ['v*']
branches: ['master']
pull_request:
release:
types: ['published']

jobs:
docker-build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- name: Build the Docker image
run: docker build . --file Dockerfile

docker-push:
name: "Push to Registries"
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v2

- name: Build the container image
uses: docker/build-push-action@v1
with:
repository: golang-repo-template

- name: Push to GitHub Packages
uses: docker/build-push-action@v1
if: github.event_name == 'release'
with:
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
registry: docker.pkg.github.com
repository: moul/golang-repo-template/golang-repo-template
tag_with_ref: true

- name: Check Docker Hub Credentials
id: check_dockerhub_credentials
if: github.event_name == 'release'
env:
DOCKER_USERNAME: ${{ secrets.DOCKER_USERNAME }}
DOCKER_PASSWORD: ${{ secrets.DOCKER_PASSWORD }}
run: |
if [ "${DOCKER_USERNAME}" == "" ]; then
echo "Missing Username"
echo "##[set-output name=missingsecrets;]$(echo yes)"
elif [ "${DOCKER_PASSWORD}" == "" ]; then
echo "Missing Password"
echo "##[set-output name=missingsecrets;]$(echo yes)"
else
echo "All secrets present"
echo "##[set-output name=missingsecrets;]$(echo no)"
fi
- name: Push to Docker Hub
if: |
github.event_name == 'release' &&
contains(steps.check_dockerhub_credentials.outputs.missingsecrets, 'no')
uses: docker/build-push-action@v1
with:
username: ${{ secrets.DOCKER_USERNAME }}
password: ${{ secrets.DOCKER_PASSWORD }}
repository: moul/golang-repo-template
tag_with_ref: true
8 changes: 1 addition & 7 deletions .github/workflows/go.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,13 +26,7 @@ on:
- ".github/workflows/go.yml"

jobs:
docker-build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- name: Build the Docker image
run: docker build . --file Dockerfile
goreleaser:
goreleaser-dryrun:
runs-on: ubuntu-latest
steps:
- name: Checkout
Expand Down

0 comments on commit df4c29f

Please sign in to comment.