From df4c29fc5d3cd53879f4c258ec04b3d38dfaab4e Mon Sep 17 00:00:00 2001 From: Manfred Touron <94029+moul@users.noreply.github.com> Date: Sat, 10 Oct 2020 00:36:09 +0200 Subject: [PATCH] feat: add Docker GitHub actions --- .github/workflows/docker.yml | 67 ++++++++++++++++++++++++++++++++++++ .github/workflows/go.yml | 8 +---- 2 files changed, 68 insertions(+), 7 deletions(-) create mode 100644 .github/workflows/docker.yml diff --git a/.github/workflows/docker.yml b/.github/workflows/docker.yml new file mode 100644 index 00000000..2641070b --- /dev/null +++ b/.github/workflows/docker.yml @@ -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 diff --git a/.github/workflows/go.yml b/.github/workflows/go.yml index d7f0bbd7..7da3520d 100644 --- a/.github/workflows/go.yml +++ b/.github/workflows/go.yml @@ -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