Skip to content

Commit 7f595cd

Browse files
authored
Create docker.yml (#87)
Add a new GitHub Actions workflow under .circleci/docker.yml to automate Docker image building, pushing, and signing with Buildx, caching, and cosign on scheduled and event-driven triggers New Features: Add Docker GitHub Actions workflow to build and push container images to the registry Integrate cosign to sign published images outside of pull requests Enhancements: Use Docker Buildx for multi-platform builds with GitHub Actions cache Extract and apply Docker metadata (tags and labels) via docker/metadata-action CI: Trigger the Docker workflow on a daily cron, master branch pushes, pull requests, and semver tag creations Signed-off-by: Dargon789 <64915515+Dargon789@users.noreply.github.com>
1 parent 9095c2c commit 7f595cd

1 file changed

Lines changed: 100 additions & 0 deletions

File tree

.circleci/docker.yml

Lines changed: 100 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,100 @@
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+
schedule:
10+
- cron: '21 12 * * *'
11+
push:
12+
branches: [ "master" ]
13+
# Publish semver tags as releases.
14+
tags: [ 'v*.*.*' ]
15+
pull_request:
16+
branches: [ "master" ]
17+
18+
env:
19+
# Use docker.io for Docker Hub if empty
20+
REGISTRY: ghcr.io
21+
# github.repository as <account>/<repo>
22+
IMAGE_NAME: ${{ github.repository }}
23+
24+
25+
jobs:
26+
build:
27+
- name: Build the Docker image
28+
run: docker build . --file path/to/Dockerfile --tag my-image-name:$(date +%s)
29+
30+
runs-on: ubuntu-latest
31+
permissions:
32+
contents: read
33+
packages: write
34+
# This is used to complete the identity challenge
35+
# with sigstore/fulcio when running outside of PRs.
36+
id-token: write
37+
38+
steps:
39+
- name: Checkout repository
40+
uses: actions/checkout@v4
41+
42+
# Install the cosign tool except on PR
43+
# https://github.com/sigstore/cosign-installer
44+
- name: Install cosign
45+
if: github.event_name != 'pull_request'
46+
uses: sigstore/cosign-installer@59acb6260d9c0ba8f4a2f9d9b48431a222b68e20 #v3.5.0
47+
with:
48+
cosign-release: 'v2.2.4'
49+
50+
# Set up BuildKit Docker container builder to be able to build
51+
# multi-platform images and export cache
52+
# https://github.com/docker/setup-buildx-action
53+
- name: Set up Docker Buildx
54+
uses: docker/setup-buildx-action@f95db51fddba0c2d1ec667646a06c2ce06100226 # v3.0.0
55+
56+
# Login against a Docker registry except on PR
57+
# https://github.com/docker/login-action
58+
- name: Log into registry ${{ env.REGISTRY }}
59+
if: github.event_name != 'pull_request'
60+
uses: docker/login-action@343f7c4344506bcbf9b4de18042ae17996df046d # v3.0.0
61+
with:
62+
registry: ${{ env.REGISTRY }}
63+
username: ${{ github.actor }}
64+
password: ${{ secrets.GITHUB_TOKEN }}
65+
66+
# Extract metadata (tags, labels) for Docker
67+
# https://github.com/docker/metadata-action
68+
- name: Extract Docker metadata
69+
id: meta
70+
uses: docker/metadata-action@96383f45573cb7f253c731d3b3ab81c87ef81934 # v5.0.0
71+
with:
72+
images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}
73+
74+
# Build and push Docker image with Buildx (don't push on PR)
75+
# https://github.com/docker/build-push-action
76+
- name: Build and push Docker image
77+
id: build-and-push
78+
uses: docker/build-push-action@v5.0.0
79+
with:
80+
context: ./
81+
push: ${{ github.event_name != 'pull_request' }}
82+
tags: ${{ steps.meta.outputs.tags }}
83+
labels: ${{ steps.meta.outputs.labels }}
84+
cache-from: type=gha
85+
cache-to: type=gha,mode=max
86+
87+
# Sign the resulting Docker image digest except on PRs.
88+
# This will only write to the public Rekor transparency log when the Docker
89+
# repository is public to avoid leaking data. If you would like to publish
90+
# transparency data even for private images, pass --force to cosign below.
91+
# https://github.com/sigstore/cosign
92+
- name: Sign the published Docker image
93+
if: ${{ github.event_name != 'pull_request' }}
94+
env:
95+
# https://docs.github.com/en/actions/security-guides/security-hardening-for-github-actions#using-an-intermediate-environment-variable
96+
TAGS: ${{ steps.meta.outputs.tags }}
97+
DIGEST: ${{ steps.build-and-push.outputs.digest }}
98+
# This step uses the identity token to provision an ephemeral certificate
99+
# against the sigstore community Fulcio instance.
100+
run: echo "${TAGS}" | xargs -I {} cosign sign --yes {}@${DIGEST}

0 commit comments

Comments
 (0)