Add docker image publish github workflow

This commit is contained in:
Victor Antonovich 2024-03-27 16:38:59 +03:00
parent a5239439e3
commit 9cee2351f4
3 changed files with 64 additions and 2 deletions

View File

@ -1,4 +1,4 @@
name: mbusd
name: build
on:
push:

62
.github/workflows/docker-publish.yml vendored Normal file
View File

@ -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 }}

View File

@ -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