Skip to content

Commit f4584e0

Browse files
crazy-maxthaJeztah
authored andcommitted
static: fix and refactor
Signed-off-by: CrazyMax <[email protected]> Signed-off-by: Sebastiaan van Stijn <[email protected]>
1 parent 00cfedc commit f4584e0

File tree

7 files changed

+408
-167
lines changed

7 files changed

+408
-167
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
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 "PLATFORM_PAIR=${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 TARGETPLATFORM=${{ matrix.platform }} static
62+
-
63+
name: Upload static packages
64+
uses: actions/upload-artifact@v2
65+
with:
66+
name: static-${{ env.PLATFORM_PAIR }}
67+
path: static/build/${{ matrix.platform }}/*.*
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
checkout scm
@@ -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: "aarch64", targetarch: "arm/v6"],
69+
armv7: [label: "aarch64", 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 TARGETPLATFORM=${pkg.os}/${config.targetarch} static"
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: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
include common.mk
22

3-
STATIC_VERSION=$(shell static/gen-static-ver $(realpath $(CURDIR)/src/github.com/docker/docker) $(VERSION))
4-
53
# Taken from: https://www.cmcrossroads.com/article/printing-value-makefile-variable
64
print-% : ; @echo $($*)
75

@@ -81,22 +79,20 @@ clean: clean-src ## remove build artifacts
8179

8280
.PHONY: deb rpm
8381
deb rpm: checkout ## build rpm/deb packages
84-
$(MAKE) -C $@ VERSION=$(VERSION) GO_VERSION=$(GO_VERSION) $@
82+
$(MAKE) -C $@ $@
8583

8684
.PHONY: centos-% fedora-% rhel-%
8785
centos-% fedora-% rhel-%: checkout ## build rpm packages for the specified distro
88-
$(MAKE) -C rpm VERSION=$(VERSION) GO_VERSION=$(GO_VERSION) $@
86+
$(MAKE) -C rpm $@
8987

9088
.PHONY: debian-% raspbian-% ubuntu-%
9189
debian-% raspbian-% ubuntu-%: checkout ## build deb packages for the specified distro
92-
$(MAKE) -C deb VERSION=$(VERSION) GO_VERSION=$(GO_VERSION) $@
90+
$(MAKE) -C deb $@
91+
9392

9493
.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+
static: checkout ## build static package
95+
$(MAKE) -C static build
10096

10197
.PHONY: verify
10298
verify: ## verify installation of packages

common.mk

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,23 @@ VERIFY_PACKAGE_REPO ?= staging
5050
# Optional flags like --platform=linux/armhf
5151
VERIFY_PLATFORM ?=
5252

53+
# Export vars as envs
5354
export BUILDTIME
5455
export DEFAULT_PRODUCT_LICENSE
5556
export PACKAGER_NAME
5657
export PLATFORM
58+
export VERSION
59+
export GO_VERSION
60+
61+
export DOCKER_CLI_REPO
62+
export DOCKER_ENGINE_REPO
63+
export DOCKER_SCAN_REPO
64+
export DOCKER_COMPOSE_REPO
65+
export DOCKER_BUILDX_REPO
66+
67+
export REF
68+
export DOCKER_CLI_REF
69+
export DOCKER_ENGINE_REF
70+
export DOCKER_SCAN_REF
71+
export DOCKER_COMPOSE_REF
72+
export DOCKER_BUILDX_REF

static/Makefile

Lines changed: 15 additions & 95 deletions
Original file line numberDiff line numberDiff line change
@@ -4,112 +4,32 @@ CLI_DIR=$(realpath $(CURDIR)/../src/github.com/docker/cli)
44
ENGINE_DIR=$(realpath $(CURDIR)/../src/github.com/docker/docker)
55
BUILDX_DIR=$(realpath $(CURDIR)/../src/github.com/docker/buildx)
66

7-
GEN_STATIC_VER=$(shell ./gen-static-ver $(CLI_DIR) $(VERSION))
7+
STATIC_VERSION=$(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)
1110

12-
DOCKER_BUILD_OPTS=
11+
export CLI_DIR
12+
export ENGINE_DIR
13+
export BUILDX_DIR
1314

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-
DOCKER_BUILD_OPTS +=--build-arg=RUNC_VERSION=$(RUNC_VERSION)
26-
endif
15+
export STATIC_VERSION
16+
export CONTAINERD_VERSION
17+
export RUNC_VERSION
2718

2819
.PHONY: help
29-
help: ## show make targets
30-
@awk 'BEGIN {FS = ":.*?## "} /^[a-zA-Z_-]+:.*?## / {sub("\\\\n",sprintf("\n%22c"," "), $$2);printf " \033[36m%-20s\033[0m %s\n", $$1, $$2}' $(MAKEFILE_LIST)
20+
help:
21+
@grep -E '^[a-zA-Z_-]+:.*?## .*$$' $(MAKEFILE_LIST) | sort | awk 'BEGIN {FS = ":.*?## "}; {printf "$(BOLD)$(CYAN)%-25s$(RESET)%s\n", $$1, $$2}'
3122

3223
.PHONY: clean
3324
clean: ## remove build artifacts
34-
[ ! -d build ] || $(CHOWN) -R $(shell id -u):$(shell id -g) build
35-
$(RM) -r build
36-
-docker builder prune -f --filter until=24h
37-
38-
.PHONY: static
39-
static: static-linux cross-mac cross-win cross-arm ## create all static packages
40-
41-
.PHONY: static-linux
42-
static-linux: static-cli static-engine static-buildx-plugin ## create tgz
43-
mkdir -p build/linux/docker
44-
cp $(CLI_DIR)/build/docker build/linux/docker/
45-
for f in dockerd containerd ctr containerd-shim containerd-shim-runc-v2 docker-init docker-proxy runc; do \
46-
cp -L $(ENGINE_DIR)/bundles/binary-daemon/$$f build/linux/docker/$$f; \
47-
done
48-
tar -C build/linux -c -z -f build/linux/docker-$(GEN_STATIC_VER).tgz docker
49-
50-
# extra binaries for running rootless
51-
mkdir -p build/linux/docker-rootless-extras
52-
for f in rootlesskit rootlesskit-docker-proxy dockerd-rootless.sh dockerd-rootless-setuptool.sh vpnkit; do \
53-
if [ -f $(ENGINE_DIR)/bundles/binary-daemon/$$f ]; then \
54-
cp -L $(ENGINE_DIR)/bundles/binary-daemon/$$f build/linux/docker-rootless-extras/$$f; \
55-
fi \
56-
done
57-
tar -C build/linux -c -z -f build/linux/docker-rootless-extras-$(GEN_STATIC_VER).tgz docker-rootless-extras
25+
@[ ! -d build ] || $(CHOWN) -R $(shell id -u):$(shell id -g) build
26+
@$(RM) -r build
5827

59-
# buildx
60-
tar -C $(BUILDX_DIR)/bin -c -z -f build/linux/docker-buildx-plugin-$(DOCKER_BUILDX_REF:v%=%).tgz docker-buildx
28+
.PHONY: build
29+
build: ## build static package
30+
./build-static "$(CURDIR)" "$(TARGETPLATFORM)"
6131

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

0 commit comments

Comments
 (0)