Skip to content

Commit 32f4543

Browse files
authored
Merge pull request #27 from numtide/dockerfile
Switch pipeline to build Go inside Dockerfile
2 parents 66d49ba + 15de4c1 commit 32f4543

File tree

5 files changed

+84
-73
lines changed

5 files changed

+84
-73
lines changed

.dockerignore

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
# Git
2+
.git
3+
.gitignore
4+
5+
# Local development environment (Nix, direnv)
6+
.direnv/
7+
result*
8+
flake.nix
9+
flake.lock
10+
devshell.nix
11+
.envrc*
12+
13+
# Build artifacts and local tools
14+
bin/
15+
dist/
16+
17+
# Test and linting artifacts
18+
cover.out
19+
cover.html
20+
.golangci.toml
21+
.testcoverage.yml
22+
23+
# CI/CD & Temporary files
24+
Dockerfile.cross
25+
26+
# Documentation and planning
27+
docs/
28+
plans/
29+
README.md
30+
*.md
31+
32+
# Project and configuration files not needed for the build
33+
Makefile
34+
PROJECT
35+
scripts/

.github/workflows/build-and-release.yaml

Lines changed: 6 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,7 @@ jobs:
6565
echo "::error::CodeQL produced ${count} alerts (warning/error)."
6666
exit 1
6767
fi
68+
6869
scan-intermediate-image:
6970
runs-on: ubuntu-latest
7071
steps:
@@ -74,7 +75,7 @@ jobs:
7475
continue-on-error: true
7576
with:
7677
cache-db: true
77-
image: "alpine:3.22.2" # sync this with Containerfile
78+
image: "golang:1.25.3-alpine3.22" # sync this with Containerfile
7879
output-file: grype.sarif
7980
severity-cutoff: high
8081
- name: Upload SARIF file
@@ -87,12 +88,9 @@ jobs:
8788
jq '.runs[0].results | map(select(.level == "error"))' grype.sarif
8889
exit 1
8990
90-
build-go:
91-
needs: [ scan-dependencies, scan-codeql, scan-intermediate-image ]
91+
test-go:
92+
needs: [ scan-dependencies ]
9293
runs-on: ubuntu-latest
93-
strategy:
94-
matrix:
95-
arch: ${{ fromJson(inputs.architectures) }}
9694
steps:
9795
- name: Check out code
9896
uses: actions/checkout@08c6903cd8c0fde910a37f88322edcfb5dd907a8 # v5.0.0
@@ -114,34 +112,8 @@ jobs:
114112
with:
115113
config: ./.testcoverage.yml
116114

117-
- name: Build
118-
run: |-
119-
mkdir -p $GITHUB_WORKSPACE/dist
120-
121-
CGO_ENABLED=0 \
122-
GOARCH=${{ matrix.arch }} \
123-
GOOS=linux \
124-
go build \
125-
-ldflags '\
126-
-s -w \
127-
-buildid=${{ github.sha }} \
128-
-X main.version=${{ github.ref_name }} \
129-
-X main.commit=${{ github.sha }} \
130-
' \
131-
-trimpath -mod=readonly \
132-
-o $GITHUB_WORKSPACE/dist/multigres-operator-${{ matrix.arch }} \
133-
./cmd/multigres-operator
134-
135-
- name: Upload artifacts
136-
uses: actions/upload-artifact@ea165f8d65b6e75b540449e92b4886f43607fa02 # v4.6.2
137-
with:
138-
name: multigres-operator-${{matrix.arch}}
139-
path: dist/*
140-
if-no-files-found: error
141-
retention-days: 7
142-
143115
build-scan-push-container:
144-
needs: [ build-go ]
116+
needs: [ test-go ]
145117
runs-on: ubuntu-latest
146118
steps:
147119
- name: Check out code
@@ -163,11 +135,6 @@ jobs:
163135
- name: Setup Docker buildx
164136
uses: docker/setup-buildx-action@e468171a9de216ec08956ac3ada2f0791b6bd435 # v3.11.1
165137

166-
- uses: actions/download-artifact@634f93cb2916e3fdff6788551b99b062d0335ce0 # v5.0.0
167-
with:
168-
pattern: multigres-operator-*
169-
path: dist/
170-
171138
- name: Log into registry
172139
uses: docker/login-action@5e57cd118135c172c3672efd75eb46360885c0ef # v3.6.0
173140
with:
@@ -179,7 +146,7 @@ jobs:
179146
uses: docker/build-push-action@263435318d21b8e681c14492fe198d362a7d2c83 # v6.18.0
180147
with:
181148
context: .
182-
file: Containerfile
149+
file: Dockerfile
183150
platforms: linux/${{ join(fromJson(inputs.architectures), ',linux/') }}
184151
load: true
185152
push: false
@@ -227,18 +194,3 @@ jobs:
227194
docker tag "$IMAGE:${{ github.sha }}" "$IMAGE:${{ github.ref_name }}"
228195
docker push "$IMAGE:${{ github.ref_name }}"
229196
fi
230-
231-
create-release:
232-
needs: [ build-scan-push-container ]
233-
runs-on: ubuntu-latest
234-
if: ${{ inputs.create-release }}
235-
steps:
236-
- uses: actions/download-artifact@634f93cb2916e3fdff6788551b99b062d0335ce0 # v5.0.0
237-
with:
238-
pattern: "*"
239-
path: dist/
240-
241-
- name: Release
242-
uses: softprops/action-gh-release@aec2ec56f94eb8180ceec724245f64ef008b89f5 # v2.4.0
243-
with:
244-
files: dist/**

Containerfile

Lines changed: 0 additions & 19 deletions
This file was deleted.

Dockerfile

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
# Containerfile for multigres-operator
2+
3+
# Github workflow step anchore/scan-action scans only the final image
4+
# sync this intermediate FROM reference with:
5+
# build-and-release.yaml => scan-intermediate-image
6+
FROM golang:1.25.3-alpine3.22 AS builder
7+
8+
ARG TARGETOS
9+
ARG TARGETARCH
10+
11+
WORKDIR /workspace
12+
# Copy the Go Modules manifests
13+
COPY go.mod go.mod
14+
COPY go.sum go.sum
15+
# cache deps before building and copying source so that we don't need to re-download as much
16+
# and so that source changes don't invalidate our downloaded layer
17+
RUN go mod download
18+
19+
# Copy the Go source (relies on .dockerignore to filter)
20+
COPY . .
21+
22+
# Build
23+
# the GOARCH has no default value to allow the binary to be built according to the host where the command
24+
# was called. For example, if we call make docker-build in a local env which has the Apple Silicon M1 SO
25+
# the docker BUILDPLATFORM arg will be linux/arm64 when for Apple x86 it will be linux/amd64. Therefore,
26+
# by leaving it empty we can ensure that the container and binary shipped on it will have the same platform.
27+
RUN CGO_ENABLED=0 \
28+
GOOS=${TARGETOS:-linux} \
29+
GOARCH=${TARGETARCH} \
30+
go build \
31+
-ldflags '-s -w -buildid=' \
32+
-trimpath -mod=readonly \
33+
-a -o manager \
34+
cmd/multigres-operator/main.go
35+
36+
# Use distroless as minimal base image to package the manager binary
37+
# Refer to https://github.com/GoogleContainerTools/distroless for more details
38+
FROM gcr.io/distroless/static:nonroot
39+
WORKDIR /
40+
COPY --from=builder /workspace/manager .
41+
USER 65532:65532
42+
43+
ENTRYPOINT ["/manager"]

go.sum

Whitespace-only changes.

0 commit comments

Comments
 (0)