Skip to content

Commit 3a2012a

Browse files
authored
Merge pull request #17 from crazy-max/vendor
vendor dockerfile to validate go mod
2 parents c58128a + d7156b1 commit 3a2012a

4 files changed

Lines changed: 122 additions & 9 deletions

File tree

.github/workflows/build.yml

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,11 @@
1-
name: Build
1+
name: build
2+
3+
permissions:
4+
contents: read
5+
6+
concurrency:
7+
group: ${{ github.workflow }}-${{ github.ref }}
8+
cancel-in-progress: true
29

310
on:
411
push:

.github/workflows/validate.yml

Lines changed: 38 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,11 @@
1-
name: Validate
1+
name: validate
2+
3+
permissions:
4+
contents: read
5+
6+
concurrency:
7+
group: ${{ github.workflow }}-${{ github.ref }}
8+
cancel-in-progress: true
29

310
on:
411
push:
@@ -7,11 +14,35 @@ on:
714
pull_request:
815

916
jobs:
17+
prepare:
18+
runs-on: ubuntu-24.04
19+
outputs:
20+
includes: ${{ steps.generate.outputs.matrix }}
21+
steps:
22+
-
23+
name: Checkout
24+
uses: actions/checkout@v6
25+
-
26+
name: Generate matrix
27+
id: generate
28+
uses: docker/bake-action/subaction/matrix@v6
29+
with:
30+
target: validate-all
31+
1032
validate:
11-
runs-on: ubuntu-latest
33+
runs-on: ubuntu-24.04
34+
needs:
35+
- prepare
36+
strategy:
37+
fail-fast: false
38+
matrix:
39+
include: ${{ fromJson(needs.prepare.outputs.includes) }}
1240
steps:
13-
- uses: actions/checkout@v5
14-
- name: Set up Docker Buildx
15-
uses: docker/setup-buildx-action@v3
16-
- name: Run validate-all
17-
run: docker buildx bake validate-all
41+
-
42+
name: Set up Docker Buildx
43+
uses: docker/setup-buildx-action@v3
44+
-
45+
name: Validate
46+
uses: docker/bake-action@v6
47+
with:
48+
targets: ${{ matrix.target }}

docker-bake.hcl

Lines changed: 30 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,12 @@ variable "DOCKER_HARDENED_IMAGES_KEYRING_VERSION" {
1212
description = "The git branch or commit hash of docker/hardened-images-keyring to use for DHI verification."
1313
}
1414

15+
target "_common" {
16+
args = {
17+
BUILDKIT_CONTEXT_KEEP_GIT_DIR = 1
18+
}
19+
}
20+
1521
target "tuf-root" {
1622
target = "tuf-root"
1723
output = [{
@@ -34,7 +40,7 @@ target "validate-tuf-root" {
3440
}
3541

3642
group "validate-all" {
37-
targets = ["lint", "lint-gopls", "validate-dockerfile", "validate-generated-files"]
43+
targets = ["lint", "lint-gopls", "validate-vendor", "validate-dockerfile", "validate-generated-files"]
3844
}
3945

4046
group "validate-generated-files" {
@@ -49,11 +55,19 @@ target "lint" {
4955
}
5056
}
5157

58+
target "validate-vendor" {
59+
inherits = ["_common"]
60+
dockerfile = "./hack/dockerfiles/vendor.Dockerfile"
61+
target = "validate"
62+
output = ["type=cacheonly"]
63+
}
64+
5265
target "validate-dockerfile" {
5366
matrix = {
5467
dockerfile = [
5568
"Dockerfile",
5669
"./hack/dockerfiles/lint.Dockerfile",
70+
"./hack/dockerfiles/vendor.Dockerfile"
5771
]
5872
}
5973
name = "validate-dockerfile-${md5(dockerfile)}"
@@ -66,6 +80,21 @@ target "lint-gopls" {
6680
target = "gopls-analyze"
6781
}
6882

83+
target "vendor" {
84+
inherits = ["_common"]
85+
dockerfile = "./hack/dockerfiles/vendor.Dockerfile"
86+
target = "update"
87+
output = ["."]
88+
}
89+
90+
target "mod-outdated" {
91+
inherits = ["_common"]
92+
dockerfile = "./hack/dockerfiles/vendor.Dockerfile"
93+
target = "outdated"
94+
no-cache-filter = ["outdated"]
95+
output = ["type=cacheonly"]
96+
}
97+
6998
target "binary" {
7099
target = "binary"
71100
platforms = [ "local" ]

hack/dockerfiles/vendor.Dockerfile

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
# syntax=docker/dockerfile:1
2+
3+
ARG GO_VERSION=1.25
4+
ARG ALPINE_VERSION=3.23
5+
ARG MODOUTDATED_VERSION=v0.9.0
6+
7+
FROM golang:${GO_VERSION}-alpine${ALPINE_VERSION} AS base
8+
RUN apk add --no-cache git rsync
9+
WORKDIR /src
10+
11+
FROM base AS vendored
12+
RUN --mount=target=/context \
13+
--mount=target=.,type=tmpfs \
14+
--mount=target=/go/pkg/mod,type=cache <<EOT
15+
set -e
16+
rsync -a /context/. .
17+
go mod tidy
18+
mkdir /out
19+
cp -r go.mod go.sum /out
20+
EOT
21+
22+
FROM scratch AS update
23+
COPY --from=vendored /out /
24+
25+
FROM vendored AS validate
26+
RUN --mount=target=/context \
27+
--mount=target=.,type=tmpfs <<EOT
28+
set -e
29+
rsync -a /context/. .
30+
git add -A
31+
cp -rf /out/* .
32+
if [ -n "$(git status --porcelain -- go.mod go.sum)" ]; then
33+
echo >&2 'ERROR: Vendor result differs. Please vendor your package with "docker buildx bake vendor"'
34+
git status --porcelain -- go.mod go.sum
35+
exit 1
36+
fi
37+
EOT
38+
39+
FROM --platform=linux/amd64 psampaz/go-mod-outdated:${MODOUTDATED_VERSION} AS go-mod-outdated-amd64
40+
41+
FROM go-mod-outdated-amd64 AS go-mod-outdated
42+
FROM base AS outdated
43+
RUN --mount=target=.,rw \
44+
--mount=target=/go/pkg/mod,type=cache \
45+
--mount=from=go-mod-outdated,source=/usr/bin/go-mod-outdated,target=/usr/bin/go-mod-outdated \
46+
go list -mod=mod -u -m -json all | go-mod-outdated -update -direct

0 commit comments

Comments
 (0)