Skip to content

Commit

Permalink
Add docker build/push github action
Browse files Browse the repository at this point in the history
Signed-off-by: Pawel Sarbinowski <[email protected]>
  • Loading branch information
Pawel Sarbinowski committed Apr 11, 2022
1 parent 06d3368 commit a554a95
Showing 1 changed file with 59 additions and 0 deletions.
59 changes: 59 additions & 0 deletions .github/workflows/docker.yml
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit a554a95

Please sign in to comment.