Skip to content

Commit

Permalink
[deploy] Improve deploy stage in Github Actions CI workflow
Browse files Browse the repository at this point in the history
The improvements are:
- Upgrade to docker/build-push-action@v2
- For PR events, run docker builds without pushing
- Use docker buildx to build multi-arch images
  • Loading branch information
joelanford committed Jan 15, 2021
1 parent 16ddc79 commit 79835c8
Showing 1 changed file with 47 additions and 15 deletions.
62 changes: 47 additions & 15 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
name: CI

on:
push:
branches: [ master ]
push: {}
pull_request:
branches: [ master ]

Expand Down Expand Up @@ -60,28 +59,61 @@ jobs:
deploy:
name: Deploy
needs: test
if: github.event_name == 'push' && github.ref == 'refs/heads/master'
runs-on: ubuntu-latest
steps:

- name: Check out code into the Go module directory
uses: actions/checkout@v2

- name: Push helm-operator image to Quay
uses: docker/build-push-action@v1
- name: Prepare
id: prep
run: |
HELM_OPERATOR_IMAGE=quay.io/joelanford/helm-operator
NGINX_OPERATOR_IMAGE=quay.io/joelanford/nginx-operator
VERSION=ci
if [[ $GITHUB_REF == refs/tags/* ]]; then
VERSION=${GITHUB_REF#refs/tags/}
elif [[ $GITHUB_REF == refs/heads/* ]]; then
VERSION=$(echo ${GITHUB_REF#refs/heads/} | sed -r 's#/+#-#g')
elif [[ $GITHUB_REF == refs/pull/* ]]; then
VERSION=pr-${{ github.event.number }}
fi
HELM_OPERATOR_TAGS="${HELM_OPERATOR_IMAGE}:${VERSION}"
NGINX_OPERATOR_TAGS="${NGINX_OPERATOR_IMAGE}:${VERSION}"
echo ::set-output name=helm-operator-tags::${HELM_OPERATOR_TAGS}
echo ::set-output name=nginx-operator-tags::${NGINX_OPERATOR_TAGS}
- name: Set up QEMU
uses: docker/setup-qemu-action@v1

- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v1

- name: Login to Quay
if: github.event_name != 'pull_request'
uses: docker/login-action@v1
with:
username: ${{ secrets.QUAY_USERNAME }}
password: ${{ secrets.QUAY_PASSWORD }}
registry: quay.io
repository: joelanford/helm-operator
tags: master

- name: Push example nginx-operator image to Quay
uses: docker/build-push-action@v1
- name: Build and push helm-operator
uses: docker/build-push-action@v2
with:
path: example/
username: ${{ secrets.QUAY_USERNAME }}
password: ${{ secrets.QUAY_PASSWORD }}
registry: quay.io
repository: joelanford/nginx-operator
tags: latest
context: .
file: ./Dockerfile
platforms: linux/amd64,linux/arm64,linux/ppc64le,linux/s390x
push: github.event_name != 'pull_request'
tags: ${{ steps.prep.outputs.helm-operator-tags }}

- name: Build and push example nginx-operator
uses: docker/build-push-action@v2
with:
context: ./example/
file: ./Dockerfile
platforms: linux/amd64,linux/arm64,linux/ppc64le,linux/s390x
push: github.event_name != 'pull_request'
tags: ${{ steps.prep.outputs.nginx-operator-tags }}

0 comments on commit 79835c8

Please sign in to comment.