|
1 | | -name: Docker |
2 | | - |
3 | | -# thanks to https://github.com/sredevopsorg/multi-arch-docker-github-workflow |
4 | | - |
5 | | -on: |
6 | | - push: |
7 | | - branches: ["main"] |
8 | | - tags: ["v*.*.*"] |
9 | | - pull_request: |
10 | | - branches: ["main"] |
11 | | - workflow_dispatch: |
12 | | -env: |
13 | | - GHCR_IMAGE: ghcr.io/c4illin/convertx |
14 | | - IMAGE_NAME: ${{ github.repository }} |
15 | | - DOCKERHUB_USERNAME: c4illin |
16 | | - |
17 | | -concurrency: |
18 | | - group: ${{ github.workflow }}-${{ github.ref }} |
19 | | - cancel-in-progress: true |
20 | | - |
21 | | -jobs: |
22 | | - # The build job builds the Docker image for each platform specified in the matrix. |
23 | | - build: |
24 | | - strategy: |
25 | | - fail-fast: false |
26 | | - matrix: |
27 | | - platform: |
28 | | - - linux/amd64 |
29 | | - - linux/arm64 |
30 | | - |
31 | | - permissions: |
32 | | - contents: write |
33 | | - packages: write |
34 | | - attestations: write |
35 | | - checks: write |
36 | | - actions: read |
37 | | - |
38 | | - runs-on: ${{ matrix.platform == 'linux/amd64' && 'ubuntu-24.04' || matrix.platform == 'linux/arm64' && 'ubuntu-24.04-arm' }} |
39 | | - |
40 | | - name: Build Docker image for ${{ matrix.platform }} |
41 | | - |
42 | | - steps: |
43 | | - - name: Prepare environment for current platform |
44 | | - # This step sets up the environment for the current platform being built. |
45 | | - # It replaces the '/' character in the platform name with '-' and sets it as an environment variable. |
46 | | - # This is useful for naming artifacts and other resources that cannot contain '/'. |
47 | | - # The environment variable PLATFORMS_PAIR will be used later in the workflow. |
48 | | - id: prepare |
49 | | - run: | |
50 | | - platform=${{ matrix.platform }} |
51 | | - echo "PLATFORM_PAIR=${platform//\//-}" >> $GITHUB_ENV |
52 | | -
|
53 | | - - name: Checkout repository |
54 | | - uses: actions/checkout@v4 |
55 | | - |
56 | | - - name: Docker meta default |
57 | | - id: meta |
58 | | - uses: docker/metadata-action@v5 |
59 | | - with: |
60 | | - images: ${{ env.GHCR_IMAGE }} |
61 | | - |
62 | | - - name: Set up Docker Buildx |
63 | | - |
64 | | - with: |
65 | | - platforms: ${{ matrix.platform }} |
66 | | - |
67 | | - - name: Login to GitHub Container Registry |
68 | | - # here we only login to ghcr.io since the this only pushes internal images |
69 | | - |
70 | | - with: |
71 | | - registry: ghcr.io |
72 | | - username: ${{ github.actor }} |
73 | | - password: ${{ secrets.GITHUB_TOKEN }} |
74 | | - |
75 | | - - name: Build and push by digest |
76 | | - id: build |
77 | | - |
78 | | - env: |
79 | | - DOCKER_BUILDKIT: 1 |
80 | | - with: |
81 | | - context: . |
82 | | - platforms: ${{ matrix.platform }} |
83 | | - labels: ${{ steps.meta.outputs.labels }} |
84 | | - annotations: ${{ steps.meta.outputs.annotations }} |
85 | | - outputs: type=image,name=${{ env.GHCR_IMAGE }},push-by-digest=true,name-canonical=true,push=true,oci-mediatypes=true |
86 | | - cache-from: type=gha,scope=${{ matrix.platform }} |
87 | | - cache-to: type=gha,mode=max,scope=${{ matrix.platform }} |
88 | | - |
89 | | - - name: Export digest |
90 | | - run: | |
91 | | - mkdir -p /tmp/digests |
92 | | - digest="${{ steps.build.outputs.digest }}" |
93 | | - touch "/tmp/digests/${digest#sha256:}" |
94 | | -
|
95 | | - - name: Upload digest |
96 | | - uses: actions/upload-artifact@v4 |
97 | | - with: |
98 | | - name: digests-${{ env.PLATFORM_PAIR }} |
99 | | - path: /tmp/digests/* |
100 | | - if-no-files-found: error |
101 | | - retention-days: 1 |
102 | | - |
103 | | - merge: |
104 | | - name: Merge Docker manifests |
105 | | - runs-on: ubuntu-latest |
106 | | - |
107 | | - permissions: |
108 | | - attestations: write |
109 | | - contents: read |
110 | | - packages: write |
111 | | - |
112 | | - needs: |
113 | | - - build |
114 | | - steps: |
115 | | - - name: Download digests |
116 | | - uses: actions/download-artifact@v4 |
117 | | - with: |
118 | | - path: /tmp/digests |
119 | | - pattern: digests-* |
120 | | - merge-multiple: true |
121 | | - |
122 | | - - name: Extract Docker metadata |
123 | | - id: meta |
124 | | - uses: docker/metadata-action@v5 |
125 | | - with: |
126 | | - images: | |
127 | | - ${{ env.GHCR_IMAGE }} |
128 | | - ${{ env.IMAGE_NAME }} |
129 | | -
|
130 | | - - name: Set up Docker Buildx |
131 | | - uses: docker/setup-buildx-action@v3 |
132 | | - |
133 | | - - name: Login to GitHub Container Registry |
134 | | - uses: docker/login-action@v3 |
135 | | - with: |
136 | | - registry: ghcr.io |
137 | | - username: ${{ github.actor }} |
138 | | - password: ${{ secrets.GITHUB_TOKEN }} |
139 | | - |
140 | | - - name: Login to Docker Hub |
141 | | - uses: docker/login-action@v3 |
142 | | - with: |
143 | | - username: ${{ env.DOCKERHUB_USERNAME }} |
144 | | - password: ${{ secrets.DOCKERHUB_TOKEN }} |
145 | | - |
146 | | - - name: Get execution timestamp with RFC3339 format |
147 | | - id: timestamp |
148 | | - run: | |
149 | | - echo "timestamp=$(date -u +"%Y-%m-%dT%H:%M:%SZ")" >> $GITHUB_OUTPUT |
150 | | -
|
151 | | - - name: Create manifest list and push |
152 | | - working-directory: /tmp/digests |
153 | | - run: | |
154 | | - docker buildx imagetools create \ |
155 | | - $(jq -cr '.tags | map("-t " + .) | join(" ")' <<< "$DOCKER_METADATA_OUTPUT_JSON") \ |
156 | | - --annotation='index:org.opencontainers.image.description=${{ github.event.repository.description }}' \ |
157 | | - --annotation='index:org.opencontainers.image.created=${{ steps.timestamp.outputs.timestamp }}' \ |
158 | | - --annotation='index:org.opencontainers.image.url=${{ github.event.repository.url }}' \ |
159 | | - --annotation='index:org.opencontainers.image.source=${{ github.event.repository.url }}' \ |
160 | | - $(printf '${{ env.GHCR_IMAGE }}@sha256:%s ' *) |
161 | | -
|
162 | | - - name: Inspect image |
163 | | - run: | |
164 | | - docker buildx imagetools inspect '${{ env.GHCR_IMAGE }}:${{ steps.meta.outputs.version }}' |
| 1 | +name: Docker |
| 2 | + |
| 3 | +# thanks to https://github.com/sredevopsorg/multi-arch-docker-github-workflow |
| 4 | + |
| 5 | +on: |
| 6 | + push: |
| 7 | + branches: ["main"] |
| 8 | + tags: ["v*.*.*"] |
| 9 | + pull_request: |
| 10 | + branches: ["main"] |
| 11 | + workflow_dispatch: |
| 12 | +env: |
| 13 | + GHCR_IMAGE: ghcr.io/c4illin/convertx |
| 14 | + IMAGE_NAME: ${{ github.repository }} |
| 15 | + DOCKERHUB_USERNAME: c4illin |
| 16 | + |
| 17 | +concurrency: |
| 18 | + group: ${{ github.workflow }}-${{ github.ref }} |
| 19 | + cancel-in-progress: true |
| 20 | + |
| 21 | +jobs: |
| 22 | + # The build job builds the Docker image for each platform specified in the matrix. |
| 23 | + build: |
| 24 | + strategy: |
| 25 | + fail-fast: false |
| 26 | + matrix: |
| 27 | + platform: |
| 28 | + - linux/amd64 |
| 29 | + - linux/arm64 |
| 30 | + |
| 31 | + permissions: |
| 32 | + contents: write |
| 33 | + packages: write |
| 34 | + attestations: write |
| 35 | + checks: write |
| 36 | + actions: read |
| 37 | + |
| 38 | + runs-on: ${{ matrix.platform == 'linux/amd64' && 'ubuntu-24.04' || matrix.platform == 'linux/arm64' && 'ubuntu-24.04-arm' }} |
| 39 | + |
| 40 | + name: Build Docker image for ${{ matrix.platform }} |
| 41 | + |
| 42 | + steps: |
| 43 | + - name: Prepare environment for current platform |
| 44 | + # This step sets up the environment for the current platform being built. |
| 45 | + # It replaces the '/' character in the platform name with '-' and sets it as an environment variable. |
| 46 | + # This is useful for naming artifacts and other resources that cannot contain '/'. |
| 47 | + # The environment variable PLATFORMS_PAIR will be used later in the workflow. |
| 48 | + id: prepare |
| 49 | + run: | |
| 50 | + platform=${{ matrix.platform }} |
| 51 | + echo "PLATFORM_PAIR=${platform//\//-}" >> $GITHUB_ENV |
| 52 | +
|
| 53 | + - name: Checkout repository |
| 54 | + uses: actions/checkout@v4 |
| 55 | + |
| 56 | + - name: Docker meta default |
| 57 | + id: meta |
| 58 | + uses: docker/metadata-action@v5 |
| 59 | + with: |
| 60 | + images: ${{ env.GHCR_IMAGE }} |
| 61 | + |
| 62 | + - name: Set up Docker Buildx |
| 63 | + |
| 64 | + with: |
| 65 | + platforms: ${{ matrix.platform }} |
| 66 | + |
| 67 | + - name: Login to GitHub Container Registry |
| 68 | + # here we only login to ghcr.io since the this only pushes internal images |
| 69 | + |
| 70 | + with: |
| 71 | + registry: ghcr.io |
| 72 | + username: ${{ github.actor }} |
| 73 | + password: ${{ secrets.GITHUB_TOKEN }} |
| 74 | + |
| 75 | + - name: Build and push by digest |
| 76 | + id: build |
| 77 | + |
| 78 | + env: |
| 79 | + DOCKER_BUILDKIT: 1 |
| 80 | + with: |
| 81 | + context: . |
| 82 | + platforms: ${{ matrix.platform }} |
| 83 | + labels: ${{ steps.meta.outputs.labels }} |
| 84 | + annotations: ${{ steps.meta.outputs.annotations }} |
| 85 | + outputs: type=image,name=${{ env.GHCR_IMAGE }},push-by-digest=true,name-canonical=true,push=true,oci-mediatypes=true |
| 86 | + cache-from: type=gha,scope=${{ matrix.platform }} |
| 87 | + cache-to: type=gha,mode=max,scope=${{ matrix.platform }} |
| 88 | + |
| 89 | + - name: Export digest |
| 90 | + run: | |
| 91 | + mkdir -p /tmp/digests |
| 92 | + digest="${{ steps.build.outputs.digest }}" |
| 93 | + touch "/tmp/digests/${digest#sha256:}" |
| 94 | +
|
| 95 | + - name: Upload digest |
| 96 | + uses: actions/upload-artifact@v4 |
| 97 | + with: |
| 98 | + name: digests-${{ env.PLATFORM_PAIR }} |
| 99 | + path: /tmp/digests/* |
| 100 | + if-no-files-found: error |
| 101 | + retention-days: 1 |
| 102 | + |
| 103 | + merge: |
| 104 | + name: Merge Docker manifests |
| 105 | + runs-on: ubuntu-latest |
| 106 | + |
| 107 | + permissions: |
| 108 | + attestations: write |
| 109 | + contents: read |
| 110 | + packages: write |
| 111 | + |
| 112 | + needs: |
| 113 | + - build |
| 114 | + steps: |
| 115 | + - name: Download digests |
| 116 | + uses: actions/download-artifact@v4 |
| 117 | + with: |
| 118 | + path: /tmp/digests |
| 119 | + pattern: digests-* |
| 120 | + merge-multiple: true |
| 121 | + |
| 122 | + - name: Extract Docker metadata |
| 123 | + id: meta |
| 124 | + uses: docker/metadata-action@v5 |
| 125 | + with: |
| 126 | + images: | |
| 127 | + ${{ env.GHCR_IMAGE }} |
| 128 | + ${{ env.IMAGE_NAME }} |
| 129 | +
|
| 130 | + - name: Set up Docker Buildx |
| 131 | + uses: docker/setup-buildx-action@v3 |
| 132 | + |
| 133 | + - name: Login to GitHub Container Registry |
| 134 | + uses: docker/login-action@v3 |
| 135 | + with: |
| 136 | + registry: ghcr.io |
| 137 | + username: ${{ github.actor }} |
| 138 | + password: ${{ secrets.GITHUB_TOKEN }} |
| 139 | + |
| 140 | + - name: Login to Docker Hub |
| 141 | + uses: docker/login-action@v3 |
| 142 | + with: |
| 143 | + username: ${{ env.DOCKERHUB_USERNAME }} |
| 144 | + password: ${{ secrets.DOCKERHUB_TOKEN }} |
| 145 | + |
| 146 | + - name: Get execution timestamp with RFC3339 format |
| 147 | + id: timestamp |
| 148 | + run: | |
| 149 | + echo "timestamp=$(date -u +"%Y-%m-%dT%H:%M:%SZ")" >> $GITHUB_OUTPUT |
| 150 | +
|
| 151 | + - name: Create manifest list and push |
| 152 | + working-directory: /tmp/digests |
| 153 | + run: | |
| 154 | + docker buildx imagetools create \ |
| 155 | + $(jq -cr '.tags | map("-t " + .) | join(" ")' <<< "$DOCKER_METADATA_OUTPUT_JSON") \ |
| 156 | + --annotation='index:org.opencontainers.image.description=${{ github.event.repository.description }}' \ |
| 157 | + --annotation='index:org.opencontainers.image.created=${{ steps.timestamp.outputs.timestamp }}' \ |
| 158 | + --annotation='index:org.opencontainers.image.url=${{ github.event.repository.url }}' \ |
| 159 | + --annotation='index:org.opencontainers.image.source=${{ github.event.repository.url }}' \ |
| 160 | + $(printf '${{ env.GHCR_IMAGE }}@sha256:%s ' *) |
| 161 | +
|
| 162 | + - name: Inspect image |
| 163 | + run: | |
| 164 | + docker buildx imagetools inspect '${{ env.GHCR_IMAGE }}:${{ steps.meta.outputs.version }}' |
0 commit comments