Skip to content

Commit 826baa6

Browse files
committed
fix and refactor static packages
Signed-off-by: CrazyMax <[email protected]>
1 parent f0188d6 commit 826baa6

File tree

5 files changed

+435
-158
lines changed

5 files changed

+435
-158
lines changed

.github/workflows/ci.yml

Lines changed: 26 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,28 @@ 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+
target:
39+
- linux/amd64
40+
- linux/arm/v6
41+
- linux/arm/v7
42+
- linux/arm64
43+
- darwin/amd64
44+
- darwin/arm64
45+
- windows/amd64
46+
steps:
47+
-
48+
name: Checkout
49+
uses: actions/checkout@v3
50+
-
51+
name: Set up Docker Buildx
52+
uses: docker/setup-buildx-action@v1
53+
-
54+
name: Build
55+
run: |
56+
make static-${{ matrix.target }}

Jenkinsfile

Lines changed: 38 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,55 @@ 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+
][arch]
71+
def nodeLabel = "linux&&${config.label}"
72+
if (config.label == 'x86_64') {
73+
nodeLabel = "${nodeLabel}&&ubuntu"
74+
}
75+
def branch = env.CHANGE_TARGET ?: env.BRANCH_NAME
76+
return { ->
77+
wrappedNode(label: nodeLabel, cleanWorkspace: true) {
78+
stage("static-${pkg.os}-${arch}") {
10479
// This is just a "dummy" stage to make the distro/arch visible
10580
// in Jenkins' BlueOcean view, which truncates names....
10681
sh 'echo starting...'
10782
}
10883
stage("info") {
10984
sh 'docker version'
11085
sh 'docker info'
86+
sh 'env|sort'
11187
}
11288
stage("build") {
11389
try {
11490
checkout scm
115-
sh "make REF=$branch DOCKER_BUILD_PKGS='cross-win' static"
91+
sh "make REF=$branch static-${pkg.os}/${config.targetarch}"
11692
} finally {
11793
sh "make clean"
11894
}
11995
}
12096
}
121-
},
122-
]
97+
}
98+
}
12399

124-
def genPackageSteps(opts) {
100+
def genStaticSteps(opts) {
125101
return opts.arches.collectEntries {
126-
["${opts.image}-${it}": genBuildStep(opts, it)]
102+
["static-${opts.os}-${it}": genStaticStep(opts, it)]
127103
}
128104
}
129105

130-
build_package_steps << pkgs.collectEntries { genPackageSteps(it) }
106+
def parallelStages = pkgs.collectEntries { genPkgSteps(it) }
107+
parallelStages << statics.collectEntries { genStaticSteps(it) }
131108

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

Makefile

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -92,8 +92,12 @@ debian-% raspbian-% ubuntu-%: checkout ## build deb packages for the specified d
9292
$(MAKE) -C deb VERSION=$(VERSION) GO_VERSION=$(GO_VERSION) $@
9393

9494
.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
95+
static: static-linux static-darwin static-windows ## build static packages
96+
97+
.PHONY: static-%
98+
static-%: checkout ## build static packages for specified os
99+
$(MAKE) -C static VERSION=$(VERSION) GO_VERSION=$(GO_VERSION) $@
100+
101+
.PHONY: static-linux/% static-darwin/% static-windows/%
102+
static-linux/% static-darwin/% static-windows/%: checkout ## build static packages for specificed os/arch
103+
$(MAKE) -C static VERSION=$(VERSION) GO_VERSION=$(GO_VERSION) $@

static/Makefile

Lines changed: 35 additions & 91 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,47 @@ 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
4019

4120
.PHONY: static
42-
static: static-linux cross-mac cross-win cross-arm ## create all static packages
21+
static: static-linux static-darwin static-windows ## create common static packages
4322

4423
.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
24+
static-linux: static-linux/amd64 static-linux/arm64 ## create common static linux packages
25+
26+
.PHONY: static-darwin
27+
static-darwin: static-darwin/amd64 static-darwin/arm64 ## create common static darwin packages
28+
29+
.PHONY: static-windows
30+
static-windows: static-windows/amd64 ## create common static windows packages
31+
32+
.PHONY: static-linux/%
33+
static-linux/%: ## create linux static packages for the specified architecture
34+
$(MAKE) build-static TARGETPLATFORM=linux/$*
35+
36+
.PHONY: static-darwin/%
37+
static-darwin/%: ## create darwin static packages for the specified architecture
38+
$(MAKE) build-static TARGETPLATFORM=darwin/$*
39+
40+
.PHONY: static-windows/%
41+
static-windows/%: ## create windows static packages for the specified architecture
42+
$(MAKE) build-static TARGETPLATFORM=windows/$*
43+
44+
.PHONY: build-static
45+
build-static:
46+
PRODUCT="$(PRODUCT)" \
47+
PLATFORM="$(PLATFORM)" \
48+
DEFAULT_PRODUCT_LICENSE="$(DEFAULT_PRODUCT_LICENSE)" \
49+
PACKAGER_NAME="$(PACKAGER_NAME)" \
50+
CLI_DIR="$(CLI_DIR)" \
51+
ENGINE_DIR="$(ENGINE_DIR)" \
52+
BUILDX_DIR="$(BUILDX_DIR)" \
53+
STATIC_VER="$(GEN_STATIC_VER)" \
54+
DOCKER_BUILDX_REF="$(DOCKER_BUILDX_REF)" \
55+
CONTAINERD_VERSION="$(CONTAINERD_VERSION)" \
56+
RUNC_VERSION="$(RUNC_VERSION)" \
57+
./build-static "$(CURDIR)" "$(TARGETPLATFORM)"
6458

6559
.PHONY: hash_files
6660
hash_files:
6761
@echo "Hashing directory $(DIR_TO_HASH)"
6862
$(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)