Skip to content

Commit a88eff1

Browse files
committed
Try to simplify
1 parent 4b9fb57 commit a88eff1

File tree

1 file changed

+31
-31
lines changed

1 file changed

+31
-31
lines changed

.github/workflows/ci.yml

Lines changed: 31 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
# Written using
2+
# https://docs.docker.com/build/ci/github-actions/multi-platform/
3+
# and
4+
# https://github.com/sredevopsorg/multi-arch-docker-github-workflow/blob/main/.github/workflows/multi-build.yaml
15
name: CI
26

37
on:
@@ -8,7 +12,12 @@ on:
812
- '*'
913
pull_request:
1014

11-
# https://docs.docker.com/build/ci/github-actions/multi-platform/
15+
env:
16+
# The name of the Docker image to be built and pushed to GHCR
17+
# The image name is derived from the GitHub repository name and the GitHub Container Registry (GHCR) URL.
18+
# The image name will be in the format: ghcr.io/<owner>/<repo>
19+
GHCR_IMAGE: ${{ env.GHCR_IMAGE }}
20+
1221
jobs:
1322

1423
build:
@@ -27,19 +36,11 @@ jobs:
2736
- name: Set up Docker Buildx
2837
uses: docker/setup-buildx-action@v3
2938

30-
- name: Log in to GitHub Docker Registry
31-
# if: github.event_name != 'pull_request'
32-
uses: docker/login-action@v3
33-
with:
34-
registry: ghcr.io
35-
username: ${{ github.actor }}
36-
password: ${{ secrets.GITHUB_TOKEN }}
37-
3839
- name: Extract metadata for publishing image
3940
id: meta
4041
uses: docker/metadata-action@v5
4142
with:
42-
images: ghcr.io/${{ github.repository }}
43+
images: ${{ env.GHCR_IMAGE }}
4344

4445
- name: Build and export to Docker local cache
4546
uses: docker/build-push-action@v6
@@ -51,19 +52,24 @@ jobs:
5152
- name: Test cli works in cached runtime image
5253
run: docker run --rm tag_for_testing uvx pycowsay 'hello ubuntu-devcontainer!'
5354

54-
# image names must be all lower case, meta does this for us to make tags
55-
# but can't get the image name back out
56-
- name: Generate image repo name
57-
run: echo REGISTRY_IMAGE=ghcr.io/$(tr '[:upper:]' '[:lower:]' <<< "${{ github.repository }}") >> $GITHUB_ENV
55+
- name: Log in to GitHub Docker Registry
56+
# if: github.event_name != 'pull_request'
57+
uses: docker/login-action@v3
58+
with:
59+
registry: ghcr.io
60+
username: ${{ github.actor }}
61+
password: ${{ secrets.GITHUB_TOKEN }}
5862

5963
- name: Build and push by digest
6064
id: build
6165
# if: github.ref_type == 'tag'
6266
uses: docker/build-push-action@v6
6367
with:
6468
labels: ${{ steps.meta.outputs.labels }}
65-
tags: ${{ env.REGISTRY_IMAGE }}
66-
outputs: type=image,push-by-digest=true,name-canonical=true,push=true
69+
annotations: ${{ steps.meta.outputs.annotations }}
70+
outputs: type=image,name=${{ env.GHCR_IMAGE }},push-by-digest=true,name-canonical=true,push=true,oci-mediatypes=true
71+
cache-from: type=gha,scope=${{ github.repository }}-${{ github.ref_name }}-${{ matrix.platform }}
72+
cache-to: type=gha,scope=${{ github.repository }}-${{ github.ref_name }}-${{ matrix.platform }}
6773

6874
- name: Export digest
6975
run: |
@@ -77,7 +83,6 @@ jobs:
7783
name: digests-linux-${{ matrix.arch }}
7884
path: ${{ runner.temp }}/digests/*
7985
if-no-files-found: error
80-
retention-days: 1
8186

8287
merge:
8388
runs-on: ubuntu-latest
@@ -93,39 +98,34 @@ jobs:
9398
pattern: digests-*
9499
merge-multiple: true
95100

96-
- name: Log in to GitHub Docker Registry
97-
uses: docker/login-action@v3
98-
with:
99-
registry: ghcr.io
100-
username: ${{ github.actor }}
101-
password: ${{ secrets.GITHUB_TOKEN }}
102-
103101
- name: Set up Docker Buildx
104102
uses: docker/setup-buildx-action@v3
105103

106104
- name: Create tags for publishing image
107105
id: meta
108106
uses: docker/metadata-action@v5
109107
with:
110-
images: ghcr.io/${{ github.repository }}
108+
images: ${{ env.GHCR_IMAGE }}
111109
tags: |
112110
type=ref,event=pr
113111
114112
# type=ref,event=tag
115113
# type=raw,value=latest
116114
# type=raw,value=noble
117115

118-
# image names must be all lower case, meta does this for us to make tags
119-
# but can't get the image name back out
120-
- name: Generate image repo name
121-
run: echo REGISTRY_IMAGE=ghcr.io/$(tr '[:upper:]' '[:lower:]' <<< "${{ github.repository }}") >> $GITHUB_ENV
116+
- name: Log in to GitHub Docker Registry
117+
uses: docker/login-action@v3
118+
with:
119+
registry: ghcr.io
120+
username: ${{ github.actor }}
121+
password: ${{ secrets.GITHUB_TOKEN }}
122122

123123
- name: Create manifest list and push
124124
working-directory: ${{ runner.temp }}/digests
125125
run: |
126126
docker buildx imagetools create $(jq -cr '.tags | map("-t " + .) | join(" ")' <<< "$DOCKER_METADATA_OUTPUT_JSON") \
127-
$(printf '${{ env.REGISTRY_IMAGE }}@sha256:%s ' *)
127+
$(printf '${{ env.GHCR_IMAGE }}@sha256:%s ' *)
128128
129129
- name: Inspect image
130130
run: |
131-
docker buildx imagetools inspect ${{ env.REGISTRY_IMAGE }}:${{ steps.meta.outputs.version }}
131+
docker buildx imagetools inspect ${{ env.GHCR_IMAGE }}:${{ steps.meta.outputs.version }}

0 commit comments

Comments
 (0)