Skip to content

Commit b5fc410

Browse files
authored
Create docker-publish.yml
1 parent f8a413b commit b5fc410

File tree

1 file changed

+94
-0
lines changed

1 file changed

+94
-0
lines changed

.github/workflows/docker-publish.yml

Lines changed: 94 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,94 @@
1+
name: Docker
2+
3+
# This workflow uses actions that are not certified by GitHub.
4+
# They are provided by a third-party and are governed by
5+
# separate terms of service, privacy policy, and support
6+
# documentation.
7+
8+
on:
9+
workflow_dispatch:
10+
schedule:
11+
- cron: '36 7 * * *'
12+
push:
13+
branches: [ master ]
14+
# Publish semver tags as releases.
15+
tags: [ 'v*.*.*' ]
16+
pull_request:
17+
branches: [ master ]
18+
19+
env:
20+
# Use docker.io for Docker Hub if empty
21+
REGISTRY: ghcr.io
22+
# github.repository as <account>/<repo>
23+
IMAGE_NAME: netresearch/node-webserver
24+
25+
26+
jobs:
27+
build:
28+
29+
runs-on: ubuntu-latest
30+
permissions:
31+
contents: read
32+
packages: write
33+
# This is used to complete the identity challenge
34+
# with sigstore/fulcio when running outside of PRs.
35+
id-token: write
36+
37+
steps:
38+
- name: Checkout repository
39+
uses: actions/checkout@v2
40+
41+
# Install the cosign tool except on PR
42+
# https://github.com/sigstore/cosign-installer
43+
- name: Install cosign
44+
if: github.event_name != 'pull_request'
45+
uses: sigstore/cosign-installer@1e95c1de343b5b0c23352d6417ee3e48d5bcd422
46+
47+
# Workaround: https://github.com/docker/build-push-action/issues/461
48+
- name: Setup Docker buildx
49+
uses: docker/setup-buildx-action@79abd3f86f79a9d68a23c75a09a9a85889262adf
50+
51+
# Login against a Docker registry except on PR
52+
# https://github.com/docker/login-action
53+
- name: Log into registry ${{ env.REGISTRY }}
54+
if: github.event_name != 'pull_request'
55+
uses: docker/login-action@28218f9b04b4f3f62068d7b6ce6ca5b26e35336c
56+
with:
57+
registry: ${{ env.REGISTRY }}
58+
username: ${{ github.actor }}
59+
password: ${{ secrets.GITHUB_TOKEN }}
60+
61+
# Extract metadata (tags, labels) for Docker
62+
# https://github.com/docker/metadata-action
63+
- name: Extract Docker metadata
64+
id: meta
65+
uses: docker/metadata-action@98669ae865ea3cffbcbaa878cf57c20bbf1c6c38
66+
with:
67+
images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}
68+
69+
# Build and push Docker image with Buildx (don't push on PR)
70+
# https://github.com/docker/build-push-action
71+
- name: Build and push Docker image
72+
id: build-and-push
73+
uses: docker/build-push-action@ad44023a93711e3deb337508980b4b5e9bcdc5dc
74+
with:
75+
context: .
76+
push: ${{ github.event_name != 'pull_request' }}
77+
tags: ${{ steps.meta.outputs.tags }}
78+
labels: ${{ steps.meta.outputs.labels }}
79+
80+
# Sign the resulting Docker image digest except on PRs and private repos
81+
# The keyless signing process records signatures on the Rekor public
82+
# transparency log, so signing is disabled for private repos by default
83+
# to avoid leaking private data. If you wish to sign things anyways,
84+
# then this check can be removed and --force can be added to the cosign
85+
# command below.
86+
# https://github.com/sigstore/cosign
87+
- name: Sign the published Docker image
88+
if: ${{ github.event_name != 'pull_request' && !github.event.repository.private }}
89+
env:
90+
COSIGN_EXPERIMENTAL: "true"
91+
# This step uses the identity token to provision an ephemeral certificate
92+
# against the sigstore community Fulcio instance, and records it to the
93+
# sigstore community Rekor transparency log.
94+
run: cosign sign ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}@${{ steps.build-and-push.outputs.digest }}

0 commit comments

Comments
 (0)