Skip to content

Commit 0e5dbc6

Browse files
authored
Merge pull request #219 from crazy-max/dockerfile
Dockerfile for cross compilation
2 parents e595cd6 + a251a3e commit 0e5dbc6

File tree

6 files changed

+158
-85
lines changed

6 files changed

+158
-85
lines changed

.dockerignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
/bin
2+
/release

.github/workflows/build.yml

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
name: build
2+
3+
on:
4+
workflow_dispatch:
5+
push:
6+
branches:
7+
- 'master'
8+
tags:
9+
- 'v*'
10+
pull_request:
11+
12+
env:
13+
DESTDIR: ./bin
14+
15+
jobs:
16+
build:
17+
runs-on: ubuntu-latest
18+
steps:
19+
-
20+
name: Checkout
21+
uses: actions/checkout@v3
22+
-
23+
name: Set up QEMU
24+
uses: docker/setup-qemu-action@v2
25+
-
26+
name: Set up Docker Buildx
27+
uses: docker/setup-buildx-action@v2
28+
-
29+
name: Build
30+
uses: docker/bake-action@v2
31+
with:
32+
targets: binaries
33+
-
34+
name: Move artifacts
35+
run: |
36+
mv ${{ env.DESTDIR }}/**/* ${{ env.DESTDIR }}/
37+
-
38+
name: Upload artifacts
39+
uses: actions/upload-artifact@v3
40+
with:
41+
name: docker-credential-helpers
42+
path: ${{ env.DESTDIR }}/*
43+
if-no-files-found: error

.gitignore

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
1-
bin
2-
release
1+
/bin
2+
/release

Dockerfile

Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
# syntax=docker/dockerfile:1
2+
3+
ARG GO_VERSION=1.16.7
4+
ARG XX_VERSION=1.1.2
5+
ARG OSXCROSS_VERSION=11.3-r7-alpine
6+
7+
ARG PKG=github.com/docker/docker-credential-helpers
8+
9+
# xx is a helper for cross-compilation
10+
FROM --platform=$BUILDPLATFORM tonistiigi/xx:${XX_VERSION} AS xx
11+
12+
# osxcross contains the MacOSX cross toolchain for xx
13+
FROM crazymax/osxcross:${OSXCROSS_VERSION} AS osxcross
14+
15+
FROM --platform=$BUILDPLATFORM golang:${GO_VERSION}-alpine AS gobase
16+
COPY --from=xx / /
17+
RUN apk add --no-cache clang file git lld llvm pkgconf
18+
ENV GOFLAGS="-mod=vendor"
19+
ENV CGO_ENABLED="1"
20+
WORKDIR /src
21+
22+
FROM gobase AS version
23+
ARG PKG
24+
RUN --mount=target=. \
25+
VERSION=$(git describe --match 'v[0-9]*' --dirty='.m' --always --tags); \
26+
echo "-s -w -X ${PKG}/credentials.Version=${VERSION}" | tee /tmp/.ldflags; \
27+
echo -n "${VERSION}" | tee /tmp/.version;
28+
29+
FROM gobase AS base
30+
ARG TARGETPLATFORM
31+
RUN xx-apk add musl-dev gcc libsecret-dev pass
32+
33+
FROM base AS build-linux
34+
ARG TARGETOS
35+
ARG TARGETARCH
36+
ARG TARGETVARIANT
37+
RUN --mount=type=bind,target=. \
38+
--mount=type=cache,target=/root/.cache \
39+
--mount=type=cache,target=/go/pkg/mod \
40+
--mount=type=bind,from=version,source=/tmp/.ldflags,target=/tmp/.ldflags <<EOT
41+
set -ex
42+
mkdir /out
43+
xx-go build -ldflags "$(cat /tmp/.ldflags)" -o /out/docker-credential-pass-${TARGETOS}-${TARGETARCH}${TARGETVARIANT} ./pass/cmd/main.go
44+
xx-verify /out/docker-credential-pass-${TARGETOS}-${TARGETARCH}${TARGETVARIANT}
45+
xx-go build -ldflags "$(cat /tmp/.ldflags)" -o /out/docker-credential-secretservice-${TARGETOS}-${TARGETARCH}${TARGETVARIANT} ./secretservice/cmd/main_linux.go
46+
xx-verify /out/docker-credential-secretservice-${TARGETOS}-${TARGETARCH}${TARGETVARIANT}
47+
EOT
48+
49+
FROM base AS build-darwin
50+
ARG TARGETARCH
51+
ARG TARGETVARIANT
52+
RUN --mount=type=bind,target=. \
53+
--mount=type=cache,target=/root/.cache \
54+
--mount=type=cache,target=/go/pkg/mod \
55+
--mount=type=bind,from=osxcross,src=/osxsdk,target=/xx-sdk \
56+
--mount=type=bind,from=version,source=/tmp/.ldflags,target=/tmp/.ldflags <<EOT
57+
set -ex
58+
mkdir /out
59+
xx-go install std
60+
xx-go build -ldflags "$(cat /tmp/.ldflags)" -o /out/docker-credential-osxkeychain-${TARGETARCH}${TARGETVARIANT} ./osxkeychain/cmd/main_darwin.go
61+
xx-verify /out/docker-credential-osxkeychain-${TARGETARCH}${TARGETVARIANT}
62+
EOT
63+
64+
FROM base AS build-windows
65+
ARG TARGETARCH
66+
ARG TARGETVARIANT
67+
RUN --mount=type=bind,target=. \
68+
--mount=type=cache,target=/root/.cache \
69+
--mount=type=cache,target=/go/pkg/mod \
70+
--mount=type=bind,from=version,source=/tmp/.ldflags,target=/tmp/.ldflags <<EOT
71+
set -ex
72+
mkdir /out
73+
xx-go build -ldflags "$(cat /tmp/.ldflags)" -o /out/docker-credential-wincred-${TARGETARCH}${TARGETVARIANT}.exe ./wincred/cmd/main_windows.go
74+
xx-verify /out/docker-credential-wincred-${TARGETARCH}${TARGETVARIANT}.exe
75+
EOT
76+
77+
FROM build-$TARGETOS AS build
78+
79+
FROM scratch AS binaries
80+
COPY --from=build /out /

Jenkinsfile

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

docker-bake.hcl

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
variable "GO_VERSION" {
2+
default = "1.16.7"
3+
}
4+
variable "DESTDIR" {
5+
default = "./bin"
6+
}
7+
8+
target "_common" {
9+
args = {
10+
GO_VERSION = GO_VERSION
11+
}
12+
}
13+
14+
group "default" {
15+
targets = ["binaries"]
16+
}
17+
18+
target "binaries" {
19+
inherits = ["_common"]
20+
target = "binaries"
21+
output = [DESTDIR]
22+
platforms = [
23+
"darwin/amd64",
24+
"darwin/arm64",
25+
"linux/amd64",
26+
"linux/arm64",
27+
"linux/arm/v7",
28+
"linux/arm/v6",
29+
"windows/amd64"
30+
]
31+
}

0 commit comments

Comments
 (0)