1
+ name : Docker Image CI
2
+
3
+ on :
4
+ push :
5
+ branches : [ '*' ]
6
+
7
+ env :
8
+ IMAGE_NAME : rusty
9
+
10
+ jobs :
11
+ # Push image to GitHub Packages.
12
+ # See also https://docs.docker.com/docker-hub/builds/
13
+ build-linux :
14
+ runs-on : ${{ matrix.config.os }}
15
+ strategy :
16
+ matrix :
17
+ config :
18
+ - {
19
+ os : " ubuntu-latest" ,
20
+ version : " linux" ,
21
+ arch : " x86_64"
22
+ }
23
+ permissions :
24
+ packages : write
25
+ contents : read
26
+
27
+ steps :
28
+ - uses : actions/checkout@v3
29
+
30
+ - name : Build image
31
+ shell : bash
32
+ run : docker buildx build . --platform ${{matrix.config.version}}/${{matrix.config.arch}} --file Dockerfile --tag $IMAGE_NAME
33
+
34
+ - name : Log in to registry
35
+ if : ${{ github.event_name != 'pull_request' }}
36
+ # This is where you will update the PAT to GITHUB_TOKEN
37
+ run : echo "${{ secrets.GITHUB_TOKEN }}" | docker login ghcr.io -u ${{ github.actor }} --password-stdin
38
+
39
+ - name : Push image
40
+ shell : bash
41
+ if : ${{ github.event_name != 'pull_request' }}
42
+ run : |
43
+ IMAGE_ID=ghcr.io/${{ github.repository_owner }}/$IMAGE_NAME
44
+
45
+ # Extract branch name
46
+ BRANCH_NAME=$(echo "${{ github.ref }}" | sed -e 's,.*/\(.*\),\1,')
47
+
48
+ # Append branch name to image ID
49
+ IMAGE_ID=$IMAGE_ID-$BRANCH_NAME
50
+
51
+ # Change all uppercase to lowercase
52
+ IMAGE_ID=$(echo $IMAGE_ID | tr '[A-Z]' '[a-z]')
53
+
54
+ # Strip git ref prefix from version
55
+ VERSION=$(echo "${{ github.ref }}" | sed -e 's,.*/\(.*\),\1,')
56
+
57
+ # Use Docker `latest` tag convention
58
+ [ "$VERSION" == "main" ] && VERSION=latest
59
+ #Add the platform to the version
60
+ VERSION=$VERSION-${{ matrix.config.arch }}
61
+ echo IMAGE_ID=$IMAGE_ID
62
+ echo VERSION=$VERSION
63
+ docker tag $IMAGE_NAME $IMAGE_ID:$VERSION
64
+ docker push $IMAGE_ID:$VERSION
65
+
66
+ push-multiplatform :
67
+ name : Push multi platform
68
+ needs : build-linux
69
+ runs-on : ubuntu-latest
70
+ if : ${{ github.event_name != 'pull_request' }}
71
+ steps :
72
+ - name : Log in to registry
73
+ if : ${{ github.event_name != 'pull_request' }}
74
+ # This is where you will update the PAT to GITHUB_TOKEN
75
+ run : echo "${{ secrets.GITHUB_TOKEN }}" | docker login ghcr.io -u ${{ github.actor }} --password-stdin
76
+
77
+ - name : Get images
78
+ shell : bash
79
+ run : |
80
+ IMAGE_ID=ghcr.io/${{ github.repository_owner }}/$IMAGE_NAME
81
+
82
+ # Change all uppercase to lowercase
83
+ IMAGE_ID=$(echo $IMAGE_ID | tr '[A-Z]' '[a-z]')
84
+ # Strip git ref prefix from version
85
+ VERSION=$(echo "${{ github.ref }}" | sed -e 's,.*/\(.*\),\1,')
86
+ # Strip "v" prefix from tag name
87
+ [[ "${{ github.ref }}" == "refs/tags/"* ]] && VERSION=$(echo $VERSION | sed -e 's/^v//')
88
+ # Use Docker `latest` tag convention
89
+ [ "$VERSION" == "main" ] && VERSION=latest
90
+ docker manifest create $IMAGE_ID:$VERSION $IMAGE_ID:$VERSION-arm64 $IMAGE_ID:$VERSION-x86_64
91
+ docker manifest push $IMAGE_ID:$VERSION
0 commit comments