Skip to content

Commit

Permalink
Add docker image publish github workflow
Browse files Browse the repository at this point in the history
  • Loading branch information
3cky committed Mar 27, 2024
1 parent a523943 commit 9cee235
Show file tree
Hide file tree
Showing 3 changed files with 64 additions and 2 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/build.yml
@@ -1,4 +1,4 @@
name: mbusd
name: build

on:
push:
Expand Down
62 changes: 62 additions & 0 deletions .github/workflows/docker-publish.yml
@@ -0,0 +1,62 @@
name: docker publish

on:
workflow_run:
workflows: [ 'build' ]
types: [ completed ]
branches: [ 'master' ]
tags: [ 'v*' ]

env:
PLATFORMS: linux/amd64,linux/arm64,linux/arm/v7
# github.repository as <account>/<repo>
IMAGE_NAME: ${{ github.repository }}

jobs:
build:
runs-on: ubuntu-latest
if: ${{ github.event.workflow_run.conclusion == 'success' }}
steps:
- name: Checkout repository
uses: actions/checkout@v4

- name: Set up QEMU
uses: docker/setup-qemu-action@v3

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

- name: Login to Docker Hub
if: github.event_name != 'pull_request'
uses: docker/login-action@v3
with:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_TOKEN }}

# Extract metadata (tags, labels) for Docker
# https://github.com/docker/metadata-action
- name: Extract Docker metadata
id: meta
uses: docker/metadata-action@v5
with:
images: ${{ env.IMAGE_NAME }}
tags: |
type=ref,event=branch
type=ref,event=pr
type=semver,pattern={{version}}
type=semver,pattern={{major}}.{{minor}}
type=sha
# Build and push Docker image with Buildx (don't push on PR)
# https://github.com/docker/build-push-action
- name: Build and push Docker image
id: build-and-push
uses: docker/build-push-action@v5
with:
context: .
platforms: ${{ env.PLATFORMS }}
push: ${{ github.event_name != 'pull_request' }}
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
cache-from: type=gha,scope=${{ env.IMAGE_NAME }}
cache-to: type=gha,mode=max,scope=${{ env.IMAGE_NAME }}
2 changes: 1 addition & 1 deletion Dockerfile
@@ -1,4 +1,4 @@
FROM alpine:latest AS build
FROM --platform=$BUILDPLATFORM alpine:latest AS build
RUN apk add --no-cache alpine-sdk cmake linux-headers
COPY . /mbusd
WORKDIR /mbusd/build
Expand Down

0 comments on commit 9cee235

Please sign in to comment.