Debian Codegraph @

Dockerfile

raw
1 # syntax=docker/dockerfile:1
2
3 # GO_VERSION sets the version of the golang base image to use.
4 # It must be a valid tag in the docker.io/library/golang image repository.
5 ARG GO_VERSION=1.25.9
6
7 # BASE_DEBIAN_DISTRO sets the golang base image debian variant to use.
8 # It must be a valid variant in the docker.io/library/golang image repository.
9 ARG BASE_DEBIAN_DISTRO=bookworm
10
11 # XX_VERSION sets the version of the xx utility to use.
12 # It must be a valid tag in the docker.io/tonistiigi/xx image repository.
13 ARG XX_VERSION=1.9.0
14
15 # OSXCROSS_VERSION sets the MacOSX cross toolchain to use.
16 # It must be a valid tag in the docker.io/crazymax/osxcross image repository.
17 ARG OSXCROSS_VERSION=11.3-r8-debian
18
19 # GOLANGCI_LINT_VERSION sets the version of the golangci-lint image to use.
20 # It must be a valid tag in the docker.io/golangci/golangci-lint image repository.
21 ARG GOLANGCI_LINT_VERSION=v2.11
22
23 # PACKAGE sets the package name to print in the "--version" output.
24 # It sets the "github.com/docker/docker-credential-helpers/credentials.Package
25 # variable at compile time.
26 ARG PACKAGE=github.com/docker/docker-credential-helpers
27
28 # xx is a helper for cross-compilation
29 FROM --platform=$BUILDPLATFORM tonistiigi/xx:${XX_VERSION} AS xx
30
31 # osxcross contains the MacOSX cross toolchain for xx
32 FROM crazymax/osxcross:${OSXCROSS_VERSION} AS osxcross
33
34 FROM --platform=$BUILDPLATFORM golang:${GO_VERSION}-${BASE_DEBIAN_DISTRO} AS gobase
35 COPY --from=xx / /
36 RUN apt-get update && apt-get install -y --no-install-recommends clang dpkg-dev file git lld llvm make pkg-config rsync
37 ENV GOFLAGS="-mod=vendor"
38 ENV CGO_ENABLED="1"
39 WORKDIR /src
40
41 FROM gobase AS vendored
42 RUN --mount=target=/context \
43 --mount=target=.,type=tmpfs \
44 --mount=target=/go/pkg/mod,type=cache <<EOT
45 set -e
46 rsync -a /context/. .
47 go mod tidy
48 go mod vendor
49 mkdir /out
50 cp -r go.mod go.sum vendor /out
51 EOT
52
53 FROM scratch AS vendor-update
54 COPY --from=vendored /out /
55
56 FROM vendored AS vendor-validate
57 RUN --mount=target=/context \
58 --mount=target=.,type=tmpfs <<EOT
59 set -e
60 rsync -a /context/. .
61 git add -A
62 rm -rf vendor
63 cp -rf /out/* .
64 if [ -n "$(git status --porcelain -- go.mod go.sum vendor)" ]; then
65 echo >&2 'ERROR: Vendor result differs. Please vendor your package with "make vendor"'
66 git status --porcelain -- go.mod go.sum vendor
67 exit 1
68 fi
69 EOT
70
71 FROM golangci/golangci-lint:${GOLANGCI_LINT_VERSION} AS golangci-lint
72 FROM gobase AS lint
73 RUN apt-get install -y binutils gcc libc6-dev libgcc-11-dev libsecret-1-dev pkg-config
74 RUN --mount=type=bind,target=. \
75 --mount=type=cache,target=/root/.cache \
76 --mount=from=golangci-lint,source=/usr/bin/golangci-lint,target=/usr/bin/golangci-lint \
77 golangci-lint run ./...
78
79 FROM gobase AS base
80 ARG TARGETPLATFORM
81 RUN xx-apt-get install -y binutils gcc libc6-dev libgcc-11-dev libsecret-1-dev pkg-config
82
83 FROM base AS test
84 RUN xx-apt-get install -y dbus-x11 gnome-keyring gpg-agent gpgconf libsecret-1-dev pass
85 RUN --mount=type=bind,target=. \
86 --mount=type=cache,target=/root/.cache \
87 --mount=type=cache,target=/go/pkg/mod <<EOT
88 set -e
89 cp -r .github/workflows/fixtures /root/.gnupg
90 gpg-connect-agent "RELOADAGENT" /bye
91 gpg --import --batch --yes /root/.gnupg/7D851EB72D73BDA0.key
92 gpg --update-trustdb
93 echo '5\ny\n' | gpg --command-fd 0 --no-tty --edit-key 7D851EB72D73BDA0 trust
94 gpg-connect-agent "PRESET_PASSPHRASE 3E2D1142AA59E08E16B7E2C64BA6DDC773B1A627 -1 77697468207374757069642070617373706872617365" /bye
95 gpg-connect-agent "KEYINFO 3E2D1142AA59E08E16B7E2C64BA6DDC773B1A627" /bye
96 gpg-connect-agent "PRESET_PASSPHRASE BA83FC8947213477F28ADC019F6564A956456163 -1 77697468207374757069642070617373706872617365" /bye
97 gpg-connect-agent "KEYINFO BA83FC8947213477F28ADC019F6564A956456163" /bye
98 pass init 7D851EB72D73BDA0
99 gpg -k
100
101 mkdir /out
102 xx-go --wrap
103 make test COVERAGEDIR=/out
104 EOT
105
106 FROM scratch AS test-coverage
107 COPY --from=test /out /
108
109 FROM gobase AS version
110 RUN --mount=target=. \
111 echo -n "$(./hack/git-meta version)" | tee /tmp/.version ; echo -n "$(./hack/git-meta revision)" | tee /tmp/.revision
112
113 FROM base AS build
114 ARG PACKAGE
115 RUN --mount=type=bind,target=. \
116 --mount=type=cache,target=/root/.cache \
117 --mount=type=cache,target=/go/pkg/mod \
118 --mount=type=bind,from=osxcross,src=/osxsdk,target=/xx-sdk \
119 --mount=type=bind,source=/tmp/.version,target=/tmp/.version,from=version \
120 --mount=type=bind,source=/tmp/.revision,target=/tmp/.revision,from=version <<EOT
121 set -ex
122 export MACOSX_VERSION_MIN=$(make print-MACOSX_DEPLOYMENT_TARGET)
123 xx-go --wrap
124 case "$(xx-info os)" in
125 linux)
126 make build-pass build-secretservice PACKAGE=$PACKAGE VERSION=$(cat /tmp/.version) REVISION=$(cat /tmp/.revision) DESTDIR=/out
127 xx-verify /out/docker-credential-pass
128 xx-verify /out/docker-credential-secretservice
129 ;;
130 darwin)
131 go install std
132 make build-osxkeychain build-pass PACKAGE=$PACKAGE VERSION=$(cat /tmp/.version) REVISION=$(cat /tmp/.revision) DESTDIR=/out
133 xx-verify /out/docker-credential-osxkeychain
134 xx-verify /out/docker-credential-pass
135 ;;
136 windows)
137 make build-wincred PACKAGE=$PACKAGE VERSION=$(cat /tmp/.version) REVISION=$(cat /tmp/.revision) DESTDIR=/out
138 mv /out/docker-credential-wincred /out/docker-credential-wincred.exe
139 xx-verify /out/docker-credential-wincred.exe
140 ;;
141 esac
142 EOT
143
144 FROM scratch AS binaries
145 COPY --from=build /out /
146
147 FROM --platform=$BUILDPLATFORM alpine AS releaser
148 WORKDIR /work
149 ARG TARGETOS
150 ARG TARGETARCH
151 ARG TARGETVARIANT
152 RUN --mount=from=binaries \
153 --mount=type=bind,source=/tmp/.version,target=/tmp/.version,from=version <<EOT
154 set -e
155 mkdir /out
156 version="$(cat /tmp/.version)"
157 [ "$TARGETOS" = "windows" ] && ext=".exe"
158 for f in *; do
159 cp "$f" "/out/${f%.*}-${version}.${TARGETOS}-${TARGETARCH}${TARGETVARIANT}${ext}"
160 done
161 EOT
162
163 FROM scratch AS release
164 COPY --from=releaser /out/ /
165
166 FROM binaries