Skip to content

Commit 23516f2

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

File tree

6 files changed

+343
-170
lines changed

6 files changed

+343
-170
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 "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
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 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: 5 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,19 +79,16 @@ 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 $@
9391

9492
.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
93+
static: checkout ## build static package
94+
$(MAKE) -C static build

common.mk

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,23 @@ DOCKER_SCAN_REF ?= v0.17.0
4343
DOCKER_COMPOSE_REF ?= v2.3.4
4444
DOCKER_BUILDX_REF ?= v0.8.1
4545

46+
# Export vars as envs
4647
export BUILDTIME
4748
export DEFAULT_PRODUCT_LICENSE
4849
export PACKAGER_NAME
4950
export PLATFORM
51+
export VERSION
52+
export GO_VERSION
53+
54+
export DOCKER_CLI_REPO
55+
export DOCKER_ENGINE_REPO
56+
export DOCKER_SCAN_REPO
57+
export DOCKER_COMPOSE_REPO
58+
export DOCKER_BUILDX_REPO
59+
60+
export REF
61+
export DOCKER_CLI_REF
62+
export DOCKER_ENGINE_REF
63+
export DOCKER_SCAN_REF
64+
export DOCKER_COMPOSE_REF
65+
export DOCKER_BUILDX_REF

static/Makefile

Lines changed: 15 additions & 98 deletions
Original file line numberDiff line numberDiff line change
@@ -4,115 +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-
# 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
15+
export STATIC_VERSION
16+
export CONTAINERD_VERSION
17+
export RUNC_VERSION
3018

3119
.PHONY: help
32-
help: ## show make targets
33-
@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}'
3422

3523
.PHONY: clean
3624
clean: ## remove build artifacts
37-
[ ! -d build ] || $(CHOWN) -R $(shell id -u):$(shell id -g) build
38-
$(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
43-
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
25+
@[ ! -d build ] || $(CHOWN) -R $(shell id -u):$(shell id -g) build
26+
@$(RM) -r build
6127

62-
# buildx
63-
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)"
6431

6532
.PHONY: hash_files
66-
hash_files:
33+
hash_files: ## hash files
6734
@echo "Hashing directory $(DIR_TO_HASH)"
6835
$(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)