Skip to content

Commit 7493d83

Browse files
authored
Merge branch 'master' into dev
2 parents 60cc188 + d05d9b6 commit 7493d83

File tree

1 file changed

+44
-31
lines changed

1 file changed

+44
-31
lines changed

.github/workflows/docker.yml

+44-31
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
11
name: Build and publish Docker image
22

3-
on:
3+
on:
44
push:
55
tags:
66
- v*
7+
workflow_dispatch:
78

89
workflow_dispatch:
910

@@ -26,48 +27,60 @@ jobs:
2627
path: ./out/
2728
key: ${{ github.sha }}
2829

29-
push:
30-
runs-on: ubuntu-latest
30+
docker:
3131
needs: [build]
32+
runs-on: ubuntu-latest
3233
permissions:
3334
packages: write
3435
contents: read
35-
3636
steps:
37-
- uses: actions/checkout@v3
37+
- name: Checkout
38+
uses: actions/checkout@v2
3839
- uses: actions/cache@v2
3940
id: restore-build
4041
with:
4142
path: ./out/
4243
key: ${{ github.sha }}
43-
44+
- name: Docker meta
45+
id: meta
46+
uses: docker/metadata-action@v4
47+
with:
48+
# list of Docker images to use as base name for tags
49+
images: |
50+
ajnart/mhp
51+
ghcr.io/ajnart/mhp
52+
# generate Docker tags based on the following events/attributes
53+
tags: |
54+
type=schedule
55+
type=ref,event=branch
56+
type=ref,event=pr
57+
type=semver,pattern={{version}}
58+
type=semver,pattern={{major}}.{{minor}}
59+
type=semver,pattern={{major}}
60+
type=sha
4461
- name: Set up QEMU
4562
uses: docker/setup-qemu-action@v2
46-
4763
- name: Set up Docker Buildx
4864
uses: docker/setup-buildx-action@v2
65+
- name: Login to DockerHub
66+
if: github.event_name != 'pull_request'
67+
uses: docker/login-action@v2
68+
with:
69+
username: ${{ secrets.DOCKERHUB_USERNAME }}
70+
password: ${{ secrets.DOCKERHUB_TOKEN }}
71+
- name: Login to GHCR
72+
if: github.event_name != 'pull_request'
73+
uses: docker/login-action@v2
74+
with:
75+
registry: ghcr.io
76+
username: ${{ github.repository_owner }}
77+
password: ${{ secrets.GITHUB_TOKEN }}
4978

50-
- name: Build image
51-
run: docker buildx build --platform linux/arm/v7,linux/amd64,linux/arm64 . --tag $IMAGE_NAME --label "runnumber=${GITHUB_RUN_ID}"
52-
53-
- name: Log in to registry
54-
55-
run: echo "${{ secrets.GITHUB_TOKEN }}" | docker login ghcr.io -u $ --password-stdin
56-
- name: Push image
57-
run: |
58-
IMAGE_ID=ghcr.io/${{ github.repository_owner }}/$IMAGE_NAME
59-
60-
# Change all uppercase to lowercase
61-
IMAGE_ID=$(echo $IMAGE_ID | tr '[A-Z]' '[a-z]')
62-
# Strip git ref prefix from version
63-
VERSION=$(echo "${{ github.ref }}" | sed -e 's,.*/\(.*\),\1,')
64-
# Strip "v" prefix from tag name
65-
[[ "${{ github.ref }}" == "refs/tags/"* ]] && VERSION=$(echo $VERSION | sed -e 's/^v//')
66-
# Use Docker `latest` tag convention
67-
[ "$VERSION" == "master" ] && VERSION=latest
68-
echo IMAGE_ID=$IMAGE_ID
69-
echo VERSION=$VERSION
70-
docker tag $IMAGE_NAME $IMAGE_ID:$VERSION
71-
docker push $IMAGE_ID:$VERSION
72-
docker tag $IMAGE_NAME $IMAGE_ID:latest
73-
docker push $IMAGE_ID:latest
79+
- name: Build and push
80+
uses: docker/build-push-action@v3
81+
with:
82+
platforms: linux/amd64,linux/arm64,linux/arm/v7
83+
context: .
84+
push: ${{ github.event_name != 'pull_request' }}
85+
tags: ${{ steps.meta.outputs.tags }}
86+
labels: ${{ steps.meta.outputs.labels }}

0 commit comments

Comments
 (0)