1
1
name : Build and publish Docker image
2
2
3
- on :
3
+ on :
4
4
push :
5
5
tags :
6
6
- v*
7
+ workflow_dispatch :
7
8
8
9
workflow_dispatch :
9
10
@@ -26,48 +27,60 @@ jobs:
26
27
path : ./out/
27
28
key : ${{ github.sha }}
28
29
29
- push :
30
- runs-on : ubuntu-latest
30
+ docker :
31
31
needs : [build]
32
+ runs-on : ubuntu-latest
32
33
permissions :
33
34
packages : write
34
35
contents : read
35
-
36
36
steps :
37
- - uses : actions/checkout@v3
37
+ - name : Checkout
38
+ uses : actions/checkout@v2
38
39
- uses : actions/cache@v2
39
40
id : restore-build
40
41
with :
41
42
path : ./out/
42
43
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
44
61
- name : Set up QEMU
45
62
uses : docker/setup-qemu-action@v2
46
-
47
63
- name : Set up Docker Buildx
48
64
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 }}
49
78
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