Skip to content

Commit 0b6e8d1

Browse files
authored
Update docker-publish.yml
1 parent 0ec0b62 commit 0b6e8d1

File tree

1 file changed

+74
-14
lines changed

1 file changed

+74
-14
lines changed

.github/workflows/docker-publish.yml

Lines changed: 74 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -7,30 +7,90 @@ name: Docker
77

88
on:
99
schedule:
10-
- cron: '40 11 * * *'
10+
- cron: '17 1 * * *'
1111
push:
12-
branches: [ main ]
12+
branches: [ "main" ]
1313
# Publish semver tags as releases.
1414
tags: [ 'v*.*.*' ]
1515
pull_request:
16-
branches: [ main ]
17-
jobs:
16+
branches: [ "main" ]
17+
18+
env:
19+
# Use docker.io for Docker Hub if empty
20+
REGISTRY: docker.io
21+
# github.repository as <account>/<repo>
22+
IMAGE_NAME: tofandel/php_node
1823

24+
25+
jobs:
1926
build:
2027

2128
runs-on: ubuntu-latest
29+
permissions:
30+
contents: read
31+
packages: write
32+
# This is used to complete the identity challenge
33+
# with sigstore/fulcio when running outside of PRs.
34+
id-token: write
2235

2336
steps:
24-
- name: Publish Docker
25-
# You may pin to the exact commit or the version.
26-
# uses: elgohr/Publish-Docker-Github-Action@93655185f260b851ede78d9a57760a8bbda65f68
27-
uses: elgohr/Publish-Docker-Github-Action@v4
37+
- name: Checkout repository
38+
uses: actions/checkout@v3
39+
40+
# Install the cosign tool except on PR
41+
# https://github.com/sigstore/cosign-installer
42+
- name: Install cosign
43+
if: github.event_name != 'pull_request'
44+
uses: sigstore/cosign-installer@f3c664df7af409cb4873aa5068053ba9d61a57b6 #v2.6.0
2845
with:
29-
default_branch: main
30-
# The name of the image you would like to push
31-
name: tofandel/php_node
32-
# The login username for the registry
46+
cosign-release: 'v1.11.0'
47+
48+
49+
# Workaround: https://github.com/docker/build-push-action/issues/461
50+
- name: Setup Docker buildx
51+
uses: docker/setup-buildx-action@79abd3f86f79a9d68a23c75a09a9a85889262adf
52+
53+
# Login against a Docker registry except on PR
54+
# https://github.com/docker/login-action
55+
- name: Log into registry ${{ env.REGISTRY }}
56+
if: github.event_name != 'pull_request'
57+
uses: docker/login-action@28218f9b04b4f3f62068d7b6ce6ca5b26e35336c
58+
with:
59+
registry: ${{ env.REGISTRY }}
3360
username: ${{ secrets.DOCKER_USERNAME }}
34-
# The login password for the registry
3561
password: ${{ secrets.DOCKER_TOKEN }}
36-
tag_semver: true
62+
63+
# Extract metadata (tags, labels) for Docker
64+
# https://github.com/docker/metadata-action
65+
- name: Extract Docker metadata
66+
id: meta
67+
uses: docker/metadata-action@98669ae865ea3cffbcbaa878cf57c20bbf1c6c38
68+
with:
69+
images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}
70+
71+
# Build and push Docker image with Buildx (don't push on PR)
72+
# https://github.com/docker/build-push-action
73+
- name: Build and push Docker image
74+
id: build-and-push
75+
uses: docker/build-push-action@ac9327eae2b366085ac7f6a2d02df8aa8ead720a
76+
with:
77+
context: .
78+
push: ${{ github.event_name != 'pull_request' }}
79+
tags: ${{ steps.meta.outputs.tags }}
80+
labels: ${{ steps.meta.outputs.labels }}
81+
cache-from: type=gha
82+
cache-to: type=gha,mode=max
83+
84+
85+
# Sign the resulting Docker image digest except on PRs.
86+
# This will only write to the public Rekor transparency log when the Docker
87+
# repository is public to avoid leaking data. If you would like to publish
88+
# transparency data even for private images, pass --force to cosign below.
89+
# https://github.com/sigstore/cosign
90+
- name: Sign the published Docker image
91+
if: ${{ github.event_name != 'pull_request' }}
92+
env:
93+
COSIGN_EXPERIMENTAL: "true"
94+
# This step uses the identity token to provision an ephemeral certificate
95+
# against the sigstore community Fulcio instance.
96+
run: echo "${{ steps.meta.outputs.tags }}" | xargs -I {} cosign sign {}@${{ steps.build-and-push.outputs.digest }}

0 commit comments

Comments
 (0)