Skip to content

Commit a4f20db

Browse files
committed
Fix visibility issue github image cicd
1 parent 81d0273 commit a4f20db

File tree

1 file changed

+56
-47
lines changed

1 file changed

+56
-47
lines changed

.github/workflows/image.yaml

+56-47
Original file line numberDiff line numberDiff line change
@@ -9,53 +9,62 @@ on:
99

1010
# Defines two custom environment variables for the workflow. These are used for the Container registry domain, and a name for the Docker image that this workflow builds.
1111
env:
12-
REGISTRY: ghcr.io
13-
IMAGE_NAME: ${{ github.repository }}
12+
REGISTRY: ghcr.io
13+
IMAGE_NAME: ${{ github.repository }}
1414

1515
# There is a single job in this workflow. It's configured to run on the latest available version of Ubuntu.
1616
jobs:
17-
build-and-push-image:
18-
runs-on: ubuntu-latest
19-
# Sets the permissions granted to the `GITHUB_TOKEN` for the actions in this job.
20-
permissions:
21-
contents: read
22-
packages: write
23-
attestations: write
24-
id-token: write
25-
#
26-
steps:
27-
- name: Checkout repository
28-
uses: actions/checkout@v4
29-
# Uses the `docker/login-action` action to log in to the Container registry registry using the account and password that will publish the packages. Once published, the packages are scoped to the account defined here.
30-
- name: Log in to the Container registry
31-
uses: docker/login-action@65b78e6e13532edd9afa3aa52ac7964289d1a9c1
32-
with:
33-
registry: ${{ env.REGISTRY }}
34-
username: ${{ github.actor }}
35-
password: ${{ secrets.GITHUB_TOKEN }}
36-
# This step uses [docker/metadata-action](https://github.com/docker/metadata-action#about) to extract tags and labels that will be applied to the specified image. The `id` "meta" allows the output of this step to be referenced in a subsequent step. The `images` value provides the base name for the tags and labels.
37-
- name: Extract metadata (tags, labels) for Docker
38-
id: meta
39-
uses: docker/metadata-action@9ec57ed1fcdbf14dcef7dfbe97b2010124a938b7
40-
with:
41-
images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}
42-
# This step uses the `docker/build-push-action` action to build the image, based on your repository's `Dockerfile`. If the build succeeds, it pushes the image to GitHub Packages.
43-
# It uses the `context` parameter to define the build's context as the set of files located in the specified path. For more information, see "[Usage](https://github.com/docker/build-push-action#usage)" in the README of the `docker/build-push-action` repository.
44-
# It uses the `tags` and `labels` parameters to tag and label the image with the output from the "meta" step.
45-
- name: Build and push Docker image
46-
id: push
47-
uses: docker/build-push-action@f2a1d5e99d037542a71f64918e516c093c6f3fc4
48-
with:
49-
context: .
50-
push: true
51-
tags: ${{ steps.meta.outputs.tags }}
52-
labels: ${{ steps.meta.outputs.labels }}
53-
54-
# This step generates an artifact attestation for the image, which is an unforgeable statement about where and how it was built. It increases supply chain security for people who consume the image. For more information, see "[AUTOTITLE](/actions/security-guides/using-artifact-attestations-to-establish-provenance-for-builds)."
55-
- name: Generate artifact attestation
56-
uses: actions/attest-build-provenance@v1
57-
with:
58-
subject-name: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME}}
59-
subject-digest: ${{ steps.push.outputs.digest }}
60-
push-to-registry: true
61-
17+
build-and-push-image:
18+
runs-on: ubuntu-latest
19+
# Sets the permissions granted to the `GITHUB_TOKEN` for the actions in this job.
20+
permissions:
21+
contents: read
22+
packages: write
23+
attestations: write
24+
id-token: write
25+
#
26+
steps:
27+
- name: Checkout repository
28+
uses: actions/checkout@v4
29+
# Uses the `docker/login-action` action to log in to the Container registry registry using the account and password that will publish the packages. Once published, the packages are scoped to the account defined here.
30+
- name: Log in to the Container registry
31+
uses: docker/login-action@65b78e6e13532edd9afa3aa52ac7964289d1a9c1
32+
with:
33+
registry: ${{ env.REGISTRY }}
34+
username: ${{ github.actor }}
35+
password: ${{ secrets.GITHUB_TOKEN }}
36+
# This step uses [docker/metadata-action](https://github.com/docker/metadata-action#about) to extract tags and labels that will be applied to the specified image. The `id` "meta" allows the output of this step to be referenced in a subsequent step. The `images` value provides the base name for the tags and labels.
37+
- name: Extract metadata (tags, labels) for Docker
38+
id: meta
39+
uses: docker/metadata-action@9ec57ed1fcdbf14dcef7dfbe97b2010124a938b7
40+
with:
41+
images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}
42+
# This step uses the `docker/build-push-action` action to build the image, based on your repository's `Dockerfile`. If the build succeeds, it pushes the image to GitHub Packages.
43+
# It uses the `context` parameter to define the build's context as the set of files located in the specified path. For more information, see "[Usage](https://github.com/docker/build-push-action#usage)" in the README of the `docker/build-push-action` repository.
44+
# It uses the `tags` and `labels` parameters to tag and label the image with the output from the "meta" step.
45+
- name: Build and push Docker image
46+
id: push
47+
uses: docker/build-push-action@f2a1d5e99d037542a71f64918e516c093c6f3fc4
48+
with:
49+
context: .
50+
push: true
51+
tags: ${{ steps.meta.outputs.tags }}
52+
labels: ${{ steps.meta.outputs.labels }}
53+
54+
# This step generates an artifact attestation for the image, which is an unforgeable statement about where and how it was built. It increases supply chain security for people who consume the image. For more information, see "[AUTOTITLE](/actions/security-guides/using-artifact-attestations-to-establish-provenance-for-builds)."
55+
- name: Generate artifact attestation
56+
uses: actions/attest-build-provenance@v1
57+
with:
58+
subject-name: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME}}
59+
subject-digest: ${{ steps.push.outputs.digest }}
60+
push-to-registry: true
61+
62+
# This step makes the Docker image public, so users can pull it without authentication.
63+
- name: Make Docker image public
64+
run: |
65+
curl \
66+
-X PATCH \
67+
-H "Authorization: Bearer ${{ secrets.GITHUB_TOKEN }}" \
68+
-H "Accept: application/vnd.github.v3+json" \
69+
https://api.github.com/user/packages/container/${{ env.IMAGE_NAME }}/visibility \
70+
-d '{"visibility":"public"}'

0 commit comments

Comments
 (0)