Skip to content

Commit 8a26967

Browse files
committed
static: fix and refactor
Signed-off-by: CrazyMax <[email protected]>
1 parent 50367ae commit 8a26967

File tree

5 files changed

+335
-162
lines changed

5 files changed

+335
-162
lines changed

.github/workflows/ci.yml

Lines changed: 39 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ on:
1111
pull_request:
1212

1313
jobs:
14-
build:
14+
pkg:
1515
runs-on: ubuntu-20.04
1616
strategy:
1717
fail-fast: false
@@ -29,3 +29,41 @@ jobs:
2929
name: Build
3030
run: |
3131
make ${{ matrix.target }}
32+
33+
static:
34+
runs-on: ubuntu-20.04
35+
strategy:
36+
fail-fast: false
37+
matrix:
38+
platform:
39+
- linux-amd64
40+
#- linux-arm-v6 # FIXME: cross compilation fails https://github.com/docker/docker-ce-packaging/pull/665#issuecomment-1081864970
41+
- linux-arm-v7
42+
- linux-arm64
43+
- darwin-amd64
44+
- darwin-arm64
45+
- windows-amd64
46+
steps:
47+
-
48+
name: Prepare
49+
run: |
50+
platform=${{ matrix.platform }}
51+
echo "TARGETPLATFORM=${platform//-/\/}" >> $GITHUB_ENV
52+
-
53+
name: Checkout
54+
uses: actions/checkout@v3
55+
-
56+
name: Set up Docker Buildx
57+
uses: docker/setup-buildx-action@v1
58+
-
59+
name: Build
60+
run: |
61+
make static-${{ matrix.platform }}
62+
-
63+
name: Upload static packages
64+
uses: actions/upload-artifact@v2
65+
with:
66+
name: static-${{ matrix.platform }}
67+
path: static/build/${{ env.TARGETPLATFORM }}/*.*
68+
if-no-files-found: error
69+
retention-days: 7

Jenkinsfile

Lines changed: 40 additions & 61 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
#!groovy
22

3-
def branch = env.CHANGE_TARGET ?: env.BRANCH_NAME
4-
53
def pkgs = [
64
[target: "centos-7", image: "centos:7", arches: ["amd64", "aarch64"]], // (EOL: June 30, 2024)
75
[target: "centos-8", image: "quay.io/centos/centos:stream8", arches: ["amd64", "aarch64"]],
@@ -19,15 +17,16 @@ def pkgs = [
1917
[target: "ubuntu-jammy", image: "ubuntu:jammy", arches: ["amd64", "aarch64", "armhf"]], // Ubuntu 22.04 LTS (End of support: April, 2027. EOL: April, 2032)
2018
]
2119

22-
def genBuildStep(LinkedHashMap pkg, String arch) {
20+
def statics = [
21+
[os: "linux", arches: ["amd64", "armv6", "armv7", "aarch64"]],
22+
[os: "darwin", arches: ["amd64", "aarch64"]],
23+
[os: "windows", arches: ["amd64"]],
24+
]
25+
26+
def genPkgStep(LinkedHashMap pkg, String arch) {
2327
def nodeLabel = "linux&&${arch}"
24-
def platform = ""
2528
def branch = env.CHANGE_TARGET ?: env.BRANCH_NAME
26-
2729
if (arch == 'armhf') {
28-
// Running armhf builds on EC2 requires --platform parameter
29-
// Otherwise it accidentally pulls armel images which then breaks the verify step
30-
platform = "--platform=linux/${arch}"
3130
nodeLabel = "${nodeLabel}&&ubuntu"
3231
} else {
3332
nodeLabel = "${nodeLabel}&&ubuntu-2004"
@@ -42,6 +41,7 @@ def genBuildStep(LinkedHashMap pkg, String arch) {
4241
stage("info") {
4342
sh 'docker version'
4443
sh 'docker info'
44+
sh 'env|sort'
4545
}
4646
stage("build") {
4747
try {
@@ -55,78 +55,57 @@ def genBuildStep(LinkedHashMap pkg, String arch) {
5555
}
5656
}
5757

58-
def build_package_steps = [
59-
'static-linux': { ->
60-
wrappedNode(label: 'ubuntu-2004 && x86_64', cleanWorkspace: true) {
61-
stage("static-linux") {
62-
// This is just a "dummy" stage to make the distro/arch visible
63-
// in Jenkins' BlueOcean view, which truncates names....
64-
sh 'echo starting...'
65-
}
66-
stage("info") {
67-
sh 'docker version'
68-
sh 'docker info'
69-
}
70-
stage("build") {
71-
try {
72-
checkout scm
73-
sh "make REF=$branch DOCKER_BUILD_PKGS='static-linux' static"
74-
} finally {
75-
sh "make clean"
76-
}
77-
}
78-
}
79-
},
80-
'cross-mac': { ->
81-
wrappedNode(label: 'ubuntu-2004 && x86_64', cleanWorkspace: true) {
82-
stage("cross-mac") {
83-
// This is just a "dummy" stage to make the distro/arch visible
84-
// in Jenkins' BlueOcean view, which truncates names....
85-
sh 'echo starting...'
86-
}
87-
stage("info") {
88-
sh 'docker version'
89-
sh 'docker info'
90-
}
91-
stage("build") {
92-
try {
93-
checkout scm
94-
sh "make REF=$branch DOCKER_BUILD_PKGS='cross-mac' static"
95-
} finally {
96-
sh "make clean"
97-
}
98-
}
99-
}
100-
},
101-
'cross-win': { ->
102-
wrappedNode(label: 'ubuntu-2004 && x86_64', cleanWorkspace: true) {
103-
stage("cross-win") {
58+
def genPkgSteps(opts) {
59+
return opts.arches.collectEntries {
60+
["${opts.image}-${it}": genPkgStep(opts, it)]
61+
}
62+
}
63+
64+
def genStaticStep(LinkedHashMap pkg, String arch) {
65+
def config = [
66+
amd64: [label: "x86_64", targetarch: "amd64"],
67+
aarch64: [label: "aarch64", targetarch: "arm64"],
68+
armv6: [label: "armhf", targetarch: "arm-v6"],
69+
armv7: [label: "armhf", targetarch: "arm-v7"],
70+
ppc64le: [label: "ppc64le", targetarch: "ppc64le"],
71+
s390x : [label: "s390x", targetarch: "s390x"],
72+
][arch]
73+
def nodeLabel = "linux&&${config.label}"
74+
if (config.label == 'x86_64') {
75+
nodeLabel = "${nodeLabel}&&ubuntu"
76+
}
77+
def branch = env.CHANGE_TARGET ?: env.BRANCH_NAME
78+
return { ->
79+
wrappedNode(label: nodeLabel, cleanWorkspace: true) {
80+
stage("static-${pkg.os}-${arch}") {
10481
// This is just a "dummy" stage to make the distro/arch visible
10582
// in Jenkins' BlueOcean view, which truncates names....
10683
sh 'echo starting...'
10784
}
10885
stage("info") {
10986
sh 'docker version'
11087
sh 'docker info'
88+
sh 'env|sort'
11189
}
11290
stage("build") {
11391
try {
11492
checkout scm
115-
sh "make REF=$branch DOCKER_BUILD_PKGS='cross-win' static"
93+
sh "make REF=$branch static-${pkg.os}-${config.targetarch}"
11694
} finally {
11795
sh "make clean"
11896
}
11997
}
12098
}
121-
},
122-
]
99+
}
100+
}
123101

124-
def genPackageSteps(opts) {
102+
def genStaticSteps(opts) {
125103
return opts.arches.collectEntries {
126-
["${opts.image}-${it}": genBuildStep(opts, it)]
104+
["static-${opts.os}-${it}": genStaticStep(opts, it)]
127105
}
128106
}
129107

130-
build_package_steps << pkgs.collectEntries { genPackageSteps(it) }
108+
def parallelStages = pkgs.collectEntries { genPkgSteps(it) }
109+
parallelStages << statics.collectEntries { genStaticSteps(it) }
131110

132-
parallel(build_package_steps)
111+
parallel(parallelStages)

Makefile

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -91,9 +91,6 @@ centos-% fedora-% rhel-%: checkout ## build rpm packages for the specified distr
9191
debian-% raspbian-% ubuntu-%: checkout ## build deb packages for the specified distro
9292
$(MAKE) -C deb VERSION=$(VERSION) GO_VERSION=$(GO_VERSION) $@
9393

94-
.PHONY: static
95-
static: DOCKER_BUILD_PKGS:=static-linux cross-mac cross-win cross-arm
96-
static: checkout ## build static-compiled packages
97-
for p in $(DOCKER_BUILD_PKGS); do \
98-
$(MAKE) -C $@ VERSION=$(VERSION) GO_VERSION=$(GO_VERSION) TARGETPLATFORM=$(TARGETPLATFORM) CONTAINERD_VERSION=$(CONTAINERD_VERSION) RUNC_VERSION=$(RUNC_VERSION) $${p}; \
99-
done
94+
.PHONY: static-%
95+
static-%: checkout ## build static-compiled packages for the specified os-arch
96+
$(MAKE) -C static VERSION=$(VERSION) GO_VERSION=$(GO_VERSION) $@

static/Makefile

Lines changed: 14 additions & 94 deletions
Original file line numberDiff line numberDiff line change
@@ -7,26 +7,6 @@ BUILDX_DIR=$(realpath $(CURDIR)/../src/github.com/docker/buildx)
77
GEN_STATIC_VER=$(shell ./gen-static-ver $(CLI_DIR) $(VERSION))
88
HASH_CMD=docker run -v $(CURDIR):/sum -w /sum debian:jessie bash hash_files
99
DIR_TO_HASH:=build/linux
10-
DOCKER_CLI_GOLANG_IMG=golang:$(GO_VERSION)
11-
12-
DOCKER_BUILD_OPTS=
13-
14-
ifneq ($(strip $(CONTAINERD_VERSION)),)
15-
# Set custom build-args to override the containerd version to build for static
16-
# packages. The Dockerfile for 20.10 and earlier used CONTAINERD_COMMIT, later
17-
# versions use CONTAINERD_VERSION. We can remove CONTAINERD_VERSION once 20.10.x
18-
# reaches EOL.
19-
DOCKER_BUILD_OPTS +=--build-arg=CONTAINERD_VERSION=$(CONTAINERD_VERSION)
20-
DOCKER_BUILD_OPTS +=--build-arg=CONTAINERD_COMMIT=$(CONTAINERD_VERSION)
21-
endif
22-
23-
ifneq ($(strip $(RUNC_VERSION)),)
24-
# Set custom build-args to override the runc version to build for static packages.
25-
# The Dockerfile for 20.10 and earlier used RUNC_COMMIT, later versions use
26-
# RUNC_VERSION. We can remove RUNC_COMMIT once 20.10.x reaches EOL.
27-
DOCKER_BUILD_OPTS +=--build-arg=RUNC_VERSION=$(RUNC_VERSION)
28-
DOCKER_BUILD_OPTS +=--build-arg=RUNC_COMMIT=$(RUNC_VERSION)
29-
endif
3010

3111
.PHONY: help
3212
help: ## show make targets
@@ -36,83 +16,23 @@ help: ## show make targets
3616
clean: ## remove build artifacts
3717
[ ! -d build ] || $(CHOWN) -R $(shell id -u):$(shell id -g) build
3818
$(RM) -r build
39-
-docker builder prune -f --filter until=24h
40-
41-
.PHONY: static
42-
static: static-linux cross-mac cross-win cross-arm ## create all static packages
4319

44-
.PHONY: static-linux
45-
static-linux: static-cli static-engine static-buildx-plugin ## create tgz
46-
mkdir -p build/linux/docker
47-
cp $(CLI_DIR)/build/docker build/linux/docker/
48-
for f in dockerd containerd ctr containerd-shim containerd-shim-runc-v2 docker-init docker-proxy runc; do \
49-
cp -L $(ENGINE_DIR)/bundles/binary-daemon/$$f build/linux/docker/$$f; \
50-
done
51-
tar -C build/linux -c -z -f build/linux/docker-$(GEN_STATIC_VER).tgz docker
52-
53-
# extra binaries for running rootless
54-
mkdir -p build/linux/docker-rootless-extras
55-
for f in rootlesskit rootlesskit-docker-proxy dockerd-rootless.sh dockerd-rootless-setuptool.sh vpnkit; do \
56-
if [ -f $(ENGINE_DIR)/bundles/binary-daemon/$$f ]; then \
57-
cp -L $(ENGINE_DIR)/bundles/binary-daemon/$$f build/linux/docker-rootless-extras/$$f; \
58-
fi \
59-
done
60-
tar -C build/linux -c -z -f build/linux/docker-rootless-extras-$(GEN_STATIC_VER).tgz docker-rootless-extras
61-
62-
# buildx
63-
tar -C $(BUILDX_DIR)/bin -c -z -f build/linux/docker-buildx-plugin-$(DOCKER_BUILDX_REF:v%=%).tgz docker-buildx
20+
.PHONY: static-%
21+
static-%:
22+
PRODUCT="$(PRODUCT)" \
23+
PLATFORM="$(PLATFORM)" \
24+
DEFAULT_PRODUCT_LICENSE="$(DEFAULT_PRODUCT_LICENSE)" \
25+
PACKAGER_NAME="$(PACKAGER_NAME)" \
26+
CLI_DIR="$(CLI_DIR)" \
27+
ENGINE_DIR="$(ENGINE_DIR)" \
28+
BUILDX_DIR="$(BUILDX_DIR)" \
29+
GEN_STATIC_VER="$(GEN_STATIC_VER)" \
30+
DOCKER_BUILDX_REF="$(DOCKER_BUILDX_REF)" \
31+
CONTAINERD_VERSION="$(CONTAINERD_VERSION)" \
32+
RUNC_VERSION="$(RUNC_VERSION)" \
33+
./build-static "$(CURDIR)" "$(subst -,/,$(*))"
6434

6535
.PHONY: hash_files
6636
hash_files:
6737
@echo "Hashing directory $(DIR_TO_HASH)"
6838
$(HASH_CMD) "$(DIR_TO_HASH)"
69-
70-
.PHONY: buildx
71-
buildx:
72-
docker buildx inspect | grep -q 'Driver: docker-container' || docker buildx create --use
73-
74-
.PHONY: cross-mac
75-
cross-mac: buildx
76-
cd $(CLI_DIR) && VERSION=$(GEN_STATIC_VER) docker buildx bake --set binary.platform=darwin/amd64,darwin/arm64 binary
77-
dest=$$PWD/build/mac; cd $(CLI_DIR)/build && for platform in *; do \
78-
arch=$$(echo $$platform | cut -d_ -f2); \
79-
mkdir -p $$dest/$$arch/docker; \
80-
cp $$platform/docker-darwin-* $$dest/$$arch/docker/docker && \
81-
tar -C $$dest/$$arch -c -z -f $$dest/$$arch/docker-$(GEN_STATIC_VER).tgz docker; \
82-
done
83-
84-
.PHONY: cross-win
85-
cross-win: cross-win-engine
86-
cd $(CLI_DIR) && VERSION=$(GEN_STATIC_VER) docker buildx bake --set binary.platform=windows/amd64 binary
87-
mkdir -p build/win/amd64/docker
88-
cp $(CLI_DIR)/build/docker-windows-amd64.exe build/win/amd64/docker/docker.exe
89-
cp $(ENGINE_DIR)/bundles/cross/windows/amd64-daemon/dockerd-$(GEN_STATIC_VER).exe build/win/amd64/docker/dockerd.exe
90-
cp $(ENGINE_DIR)/bundles/cross/windows/amd64-daemon/docker-proxy-$(GEN_STATIC_VER).exe build/win/amd64/docker/docker-proxy.exe
91-
docker run --rm -v $(CURDIR)/build/win/amd64:/v -w /v alpine sh -c 'apk update&&apk add zip&&zip -r docker-$(GEN_STATIC_VER).zip docker'
92-
$(CHOWN) -R $(shell id -u):$(shell id -g) build
93-
94-
.PHONY: cross-arm
95-
cross-arm: cross-all-cli ## create tgz with linux armhf client only
96-
mkdir -p build/arm/docker
97-
cp $(CLI_DIR)/build/docker-linux-arm build/arm/docker/docker
98-
tar -C build/arm -c -z -f build/arm/docker-$(GEN_STATIC_VER).tgz docker
99-
100-
.PHONY: static-cli
101-
static-cli:
102-
cd $(CLI_DIR) && VERSION=$(GEN_STATIC_VER) docker buildx bake --set binary.platform=$(TARGETPLATFORM) --set binary.args.CGO_ENABLED=$(CGO_ENABLED) binary
103-
104-
.PHONY: static-engine
105-
static-engine:
106-
$(MAKE) -C $(ENGINE_DIR) VERSION=$(GEN_STATIC_VER) DOCKER_BUILD_OPTS="$(DOCKER_BUILD_OPTS)" binary
107-
108-
.PHONY: static-buildx-plugin
109-
static-buildx-plugin:
110-
cd $(BUILDX_DIR) && docker buildx bake --set binaries.platform=$(TARGETPLATFORM) binaries && mv ./bin/buildx ./bin/docker-buildx
111-
112-
.PHONY: cross-all-cli
113-
cross-all-cli:
114-
$(MAKE) -C $(CLI_DIR) -f docker.Makefile VERSION=$(GEN_STATIC_VER) cross
115-
116-
.PHONY: cross-win-engine
117-
cross-win-engine:
118-
$(MAKE) -C $(ENGINE_DIR) VERSION=$(GEN_STATIC_VER) DOCKER_CROSSPLATFORMS=windows/amd64 DOCKER_BUILD_OPTS="$(DOCKER_BUILD_OPTS)" cross

0 commit comments

Comments
 (0)