From a554a952bcdc7c26c3095297e498f83f3a817634 Mon Sep 17 00:00:00 2001 From: Pawel Sarbinowski Date: Mon, 11 Apr 2022 09:54:10 +0100 Subject: [PATCH] Add docker build/push github action Signed-off-by: Pawel Sarbinowski --- .github/workflows/docker.yml | 59 ++++++++++++++++++++++++++++++++++++ 1 file changed, 59 insertions(+) create mode 100644 .github/workflows/docker.yml diff --git a/.github/workflows/docker.yml b/.github/workflows/docker.yml new file mode 100644 index 0000000..56dedd4 --- /dev/null +++ b/.github/workflows/docker.yml @@ -0,0 +1,59 @@ +name: Publish Docker +on: push +jobs: + build: + runs-on: ubuntu-latest + steps: + - name: Checkout + uses: actions/checkout@v2 + + - name: Set base image env + run: | + echo "BASE_IMAGE=ghcr.io/marshallwace/prometheus-ucs-exporter" >> $GITHUB_ENV + + - name: Set up QEMU + uses: docker/setup-qemu-action@v1 + + - name: Set up Docker buildx + uses: docker/setup-buildx-action@v1 + + - name: Cache Docker layers + uses: actions/cache@v2 + with: + path: /tmp/.buildx-cache + key: ${{ runner.os }}-buildx-${{ github.sha }} + restore-keys: | + ${{ runner.os }}-buildx- + + - name: Login to ghcr.io + uses: docker/login-action@v1 + with: + registry: ghcr.io + username: mwam-ci + password: ${{ secrets.CR_PAT }} + + - name: Build and Push latest + uses: docker/build-push-action@v2 + with: + context: . + file: ./Dockerfile + platforms: linux/amd64,linux/arm64 + tags: ${{ env.BASE_IMAGE }}:latest + push: ${{ github.event_name != 'pull_request' && github.ref == 'refs/heads/master' }} + cache-to: type=local,dest=/tmp/.buildx-cache + + - name: Set tagged image env + if: "startsWith(github.ref, 'refs/tags/v')" + run: | + echo "TAGGED_IMAGE=${BASE_IMAGE}:${GITHUB_REF#refs/tags/v}" >> $GITHUB_ENV + + - name: Build and Push tag + uses: docker/build-push-action@v2 + if: "startsWith(github.ref, 'refs/tags/v')" + with: + context: . + file: ./Dockerfile + platforms: linux/amd64,linux/arm64 + tags: ${{ env.TAGGED_IMAGE }} + push: ${{ github.event_name != 'pull_request' }} + cache-from: type=local,src=/tmp/.buildx-cache