1
+ name : Docker - publish multi-arch packages
2
+
3
+ # This workflow uses actions that are not certified by GitHub.
4
+ # They are provided by a third-party and are governed by
5
+ # separate terms of service, privacy policy, and support
6
+ # documentation.
7
+
8
+ on :
9
+ release :
10
+ types : [ published ]
11
+ push :
12
+ # branches: [ "python" ]
13
+ # Publish semver releases.
14
+ tags : [ 'v**.**.**' ]
15
+ workflow_dispatch :
16
+
17
+
18
+ env :
19
+ # github.repository as <account>/<repo>
20
+ IMAGE_NAME : ${{ github.repository }}
21
+
22
+
23
+ jobs :
24
+ build :
25
+
26
+ runs-on : ubuntu-latest
27
+ permissions :
28
+ contents : read
29
+ packages : write
30
+
31
+ steps :
32
+ - name : Checkout repository
33
+ uses : actions/checkout@v4
34
+
35
+ - name : Set up QEMU
36
+ uses : docker/setup-qemu-action@v3
37
+
38
+ # Set up BuildKit Docker container builder to be able to build
39
+ # multi-platform images and export cache
40
+ # https://github.com/docker/setup-buildx-action
41
+ - name : Set up Docker Buildx
42
+ uses : docker/setup-buildx-action@v3
43
+
44
+ # Login against a Docker registry except on PR
45
+ # https://github.com/docker/login-action
46
+ - name : Log into registry ghcr.io
47
+ if : github.event_name != 'pull_request'
48
+ uses : docker/login-action@v3
49
+ with :
50
+ registry : ghcr.io
51
+ username : ${{ github.actor }}
52
+ password : ${{ secrets.GITHUB_TOKEN }}
53
+
54
+ # Extract metadata (tags, labels) for Docker
55
+ # https://github.com/docker/metadata-action
56
+ - name : Extract Docker metadata
57
+ id : meta
58
+ uses : docker/metadata-action@96383f45573cb7f253c731d3b3ab81c87ef81934 # v5.0.0
59
+ with :
60
+ images : ghcr.io/${{ env.IMAGE_NAME }}
61
+
62
+ # Build and push Docker image with Buildx (don't push on PR)
63
+ # https://github.com/docker/build-push-action
64
+ - name : Build and push Docker image
65
+ id : build-and-push
66
+ uses : docker/build-push-action@v5
67
+ with :
68
+ context : .
69
+ push : ${{ github.event_name != 'pull_request' }}
70
+ tags : ${{ steps.meta.outputs.tags }}
71
+ labels : ${{ steps.meta.outputs.labels }}
72
+ cache-from : type=gha
73
+ cache-to : type=gha,mode=max
74
+ platforms : linux/amd64,linux/arm64,linux/arm/v7
75
+
76
+ # now we need to publish to a different registry
77
+ # we can use the same image name but we need to change the registry
78
+ # we can use the same tags and labels
79
+ - name : Log into registry docker.io
80
+ if : github.event_name != 'pull_request'
81
+ uses : docker/login-action@v3
82
+ with :
83
+ registry : docker.io
84
+ username : ${{ github.actor }}
85
+ password : ${{ secrets.DOCKER_HUB_KEY }}
86
+
87
+ - name : Extract Docker metadata
88
+ id : meta2
89
+ uses : docker/metadata-action@96383f45573cb7f253c731d3b3ab81c87ef81934 # v5.0.0
90
+ with :
91
+ images : docker.io/${{ env.IMAGE_NAME }}
92
+
93
+ - name : Build and push Docker image 2
94
+ id : build-and-push2
95
+ uses : docker/build-push-action@v5
96
+ with :
97
+ context : .
98
+ push : ${{ github.event_name != 'pull_request' }}
99
+ # add latest to tags
100
+ tags : ${{ steps.meta2.outputs.tags }}
101
+ labels : ${{ steps.meta2.outputs.labels }}
102
+ cache-from : type=gha
103
+ cache-to : type=gha,mode=max
104
+ platforms : linux/amd64,linux/arm64,linux/arm/v7
0 commit comments