Skip to content

Commit 31c972f

Browse files
committed
Add Docker build workflow to GitHub Actions
Refactor GitHub Actions workflows by simplifying Docker build process Enhance Dockerfile and GitHub workflows for private repository support Update Dockerfile and GitHub Actions to enhance private repository support Update Dockerfile and GitHub Actions to use x-access-token for private repository access Refactor Dockerfile and GitHub Actions workflows to remove private repository configurations Update Dockerfile and GitHub Actions workflows to support private repository access with GitHub PAT Refactor GitHub Actions workflow by renaming test job to 'unit-tests' and updating step names for clarity Add authentication step for private Go modules in GitHub Actions workflow Update GitHub Actions workflows to use GITHUB_TOKEN for authentication instead of GH_PAT Update GitHub Actions workflow to use GIT_ACCESS_TOKEN for Docker build authentication Update GitHub Actions workflow to use GITHUB_TOKEN for Docker build authentication Update GitHub Actions workflows to use GH_PAT for authentication instead of GITHUB_TOKEN Add push-image input to Docker workflow and update tests workflow to conditionally push images Refactor GitHub Actions workflows to consistently use GITHUB_TOKEN for authentication and remove push-image input from Docker workflow Update GitHub Actions workflows to use GH_PAT for Docker image push condition and improve authentication for private Go modules Update GitHub Actions workflow to use GH_PAT for authentication in Docker image push condition Upgrade docker/build-push-action to v6 and enhance image push configuration in GitHub Actions workflow Update GitHub Actions workflow to rename 'Run unit tests' step to 'Run tests' for improved clarity Trigger CI checks Refactor GitHub Actions workflow by renaming 'tests' to 'Tests' and updating job name from 'unit-tests' to 'test' for improved clarity.
1 parent b53c62f commit 31c972f

3 files changed

Lines changed: 115 additions & 0 deletions

File tree

.github/workflows/docker.yml

Lines changed: 89 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,89 @@
1+
name: docker
2+
3+
on:
4+
workflow_call:
5+
inputs:
6+
version:
7+
description: Version tag for the image (uses git commit SHA if not provided)
8+
required: false
9+
type: string
10+
11+
push-image:
12+
description: "Set to true to push the image, false to only build it"
13+
required: true
14+
type: boolean
15+
secrets:
16+
GH_PAT:
17+
description: "A GitHub PAT with permissions to read the private repository."
18+
required: true
19+
20+
jobs:
21+
build:
22+
runs-on: ubuntu-24.04
23+
permissions:
24+
contents: read
25+
packages: write
26+
id-token: write # needed for provenance attestation
27+
attestations: write # needed for provenance attestation
28+
steps:
29+
- name: Checkout
30+
uses: actions/checkout@v4
31+
32+
- name: Set up Docker Buildx
33+
uses: docker/setup-buildx-action@v3
34+
35+
- name: Login to Registry
36+
uses: docker/login-action@v3
37+
with:
38+
registry: ghcr.io
39+
username: ${{ github.repository_owner }}
40+
password: ${{ github.token }}
41+
42+
- name: Export build information
43+
run: |
44+
echo "SOURCE_DATE_EPOCH=$(git log -1 --pretty=%ct)" >> $GITHUB_ENV
45+
echo "EXTRA_LABELS<<EOF
46+
org.opencontainers.image.created={{commit_date 'YYYY-MM-DDTHH:mm:ssZZ'}}
47+
org.opencontainers.image.title=UI Operator
48+
org.opencontainers.image.vendor=${{ github.repository_owner }}
49+
EOF" >> $GITHUB_ENV
50+
51+
- name: Docker metadata
52+
id: meta
53+
uses: docker/metadata-action@v5
54+
with:
55+
images: ghcr.io/${{ github.repository }}
56+
# Use version input if available, otherwise use the git SHA
57+
tags: |
58+
type=raw,value=${{ inputs.version || github.sha }}
59+
type=raw,value=latest,enable=${{ inputs.version && '{{is_default_branch}}' || 'false' }}
60+
labels: ${{ env.EXTRA_LABELS }}
61+
annotations: ${{ env.EXTRA_LABELS }}
62+
63+
- name: Build and push
64+
id: build
65+
uses: docker/build-push-action@v6
66+
with:
67+
context: .
68+
push: ${{ inputs.push-image }}
69+
tags: ${{ steps.meta.outputs.tags }}
70+
labels: ${{ steps.meta.outputs.labels }}
71+
annotations: ${{ steps.meta.outputs.annotations }}
72+
cache-from: type=gha
73+
cache-to: type=gha,mode=max
74+
outputs: type=image,name=ghcr.io/${{ github.repository }},push-by-digest=true,name-canonical=true,push=${{ inputs.push-image }}
75+
build-args: |
76+
GH_TOKEN=${{ secrets.GH_PAT }}
77+
PRIVATE_REPO_HOST=github.com/scality
78+
BUILD_DATE=${{ fromJson(steps.meta.outputs.json)['org.opencontainers.image.created'] }}
79+
GIT_COMMIT=${{ github.sha }}
80+
SOURCE_DATE_EPOCH=${{ env.SOURCE_DATE_EPOCH }}
81+
VERSION=${{ inputs.version || github.sha }}
82+
83+
- name: Generate GitHub SLSA provenance
84+
uses: actions/attest-build-provenance@v1
85+
if: ${{ inputs.push-image }}
86+
with:
87+
subject-digest: ${{ steps.build.outputs.digest }}
88+
subject-name: ghcr.io/${{ github.repository }}
89+
push-to-registry: true

.github/workflows/tests.yml

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,22 @@ jobs:
2424
go-version: ${{ env.GO_VERSION }}
2525
cache: true
2626

27+
- name: Authenticate for private Go modules
28+
env:
29+
GH_TOKEN: ${{ secrets.GH_PAT }}
30+
run: |
31+
git config --global url."https://oauth2:${GH_TOKEN}@github.com/scality".insteadOf "https://github.com/scality"
32+
go env -w GOPRIVATE='github.com/scality'
33+
2734
- name: Install dependencies
2835
run: go mod download
2936

3037
- name: Run tests
3138
run: make test
39+
40+
build:
41+
uses: ./.github/workflows/docker.yml
42+
with:
43+
push-image: ${{ github.event_name == 'push' && (github.ref == 'refs/heads/main' || github.ref == 'refs/heads/master') }}
44+
secrets:
45+
GH_PAT: ${{ secrets.GH_PAT }}

Dockerfile

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,24 @@
11
# Build the manager binary
22
FROM golang:1.24 AS builder
3+
4+
ARG GH_TOKEN
5+
6+
ARG PRIVATE_REPO_HOST=github.com/scality
7+
38
ARG TARGETOS
49
ARG TARGETARCH
510

611
WORKDIR /workspace
12+
13+
RUN go env -w GOPRIVATE=${PRIVATE_REPO_HOST}
14+
15+
RUN if [ -z "$GH_TOKEN" ]; then echo "GH_TOKEN is missing"; exit 1; fi && \
16+
git config --global url."https://oauth2:${GH_TOKEN}@${PRIVATE_REPO_HOST}".insteadOf "https://${PRIVATE_REPO_HOST}"
17+
718
# Copy the Go Modules manifests
819
COPY go.mod go.mod
920
COPY go.sum go.sum
21+
1022
# cache deps before building and copying source so that we don't need to re-download as much
1123
# and so that source changes don't invalidate our downloaded layer
1224
RUN go mod download

0 commit comments

Comments
 (0)