Skip to content

[master] fix and refactor static packages with fixed cross-comp on moby #718

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 13 commits into
base: master
Choose a base branch
from
Draft
Prev Previous commit
Next Next commit
static: fix and refactor
Signed-off-by: CrazyMax <crazy-max@users.noreply.github.com>
Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
  • Loading branch information
crazy-max committed Jul 25, 2022
commit fbe69acf71ecb94031d49fa716fb6267acb4c25d
40 changes: 39 additions & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -11,7 +11,7 @@ on:
pull_request:

jobs:
build:
pkg:
runs-on: ubuntu-20.04
strategy:
fail-fast: false
@@ -29,3 +29,41 @@ jobs:
name: Build
run: |
make ${{ matrix.target }}

static:
runs-on: ubuntu-20.04
strategy:
fail-fast: false
matrix:
platform:
- linux/amd64
- linux/arm/v6
- linux/arm/v7
- linux/arm64
- darwin/amd64
- darwin/arm64
- windows/amd64
steps:
-
name: Prepare
run: |
platform=${{ matrix.platform }}
echo "PLATFORM_PAIR=${platform//\//-}" >> $GITHUB_ENV
-
name: Checkout
uses: actions/checkout@v3
-
name: Set up Docker Buildx
uses: docker/setup-buildx-action@v1
-
name: Build
run: |
make TARGETPLATFORM=${{ matrix.platform }} static
-
name: Upload static packages
uses: actions/upload-artifact@v2
with:
name: static-${{ env.PLATFORM_PAIR }}
path: static/build/${{ matrix.platform }}/*.*
if-no-files-found: error
retention-days: 7
101 changes: 40 additions & 61 deletions Jenkinsfile
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
#!groovy

def branch = env.CHANGE_TARGET ?: env.BRANCH_NAME

def pkgs = [
[target: "centos-7", image: "centos:7", arches: ["amd64", "aarch64"]], // (EOL: June 30, 2024)
[target: "centos-8", image: "quay.io/centos/centos:stream8", arches: ["amd64", "aarch64"]],
@@ -19,15 +17,16 @@ def pkgs = [
[target: "ubuntu-jammy", image: "ubuntu:jammy", arches: ["amd64", "aarch64", "armhf"]], // Ubuntu 22.04 LTS (End of support: April, 2027. EOL: April, 2032)
]

def genBuildStep(LinkedHashMap pkg, String arch) {
def statics = [
[os: "linux", arches: ["amd64", "armv6", "armv7", "aarch64"]],
[os: "darwin", arches: ["amd64", "aarch64"]],
[os: "windows", arches: ["amd64"]],
]

def genPkgStep(LinkedHashMap pkg, String arch) {
def nodeLabel = "linux&&${arch}"
def platform = ""
def branch = env.CHANGE_TARGET ?: env.BRANCH_NAME

if (arch == 'armhf') {
// Running armhf builds on EC2 requires --platform parameter
// Otherwise it accidentally pulls armel images which then breaks the verify step
platform = "--platform=linux/${arch}"
nodeLabel = "${nodeLabel}&&ubuntu"
} else {
nodeLabel = "${nodeLabel}&&ubuntu-2004"
@@ -42,6 +41,7 @@ def genBuildStep(LinkedHashMap pkg, String arch) {
stage("info") {
sh 'docker version'
sh 'docker info'
sh 'env|sort'
}
stage("build") {
checkout scm
@@ -55,78 +55,57 @@ def genBuildStep(LinkedHashMap pkg, String arch) {
}
}

def build_package_steps = [
'static-linux': { ->
wrappedNode(label: 'ubuntu-2004 && x86_64', cleanWorkspace: true) {
stage("static-linux") {
// This is just a "dummy" stage to make the distro/arch visible
// in Jenkins' BlueOcean view, which truncates names....
sh 'echo starting...'
}
stage("info") {
sh 'docker version'
sh 'docker info'
}
stage("build") {
try {
checkout scm
sh "make REF=$branch DOCKER_BUILD_PKGS='static-linux' static"
} finally {
sh "make clean"
}
}
}
},
'cross-mac': { ->
wrappedNode(label: 'ubuntu-2004 && x86_64', cleanWorkspace: true) {
stage("cross-mac") {
// This is just a "dummy" stage to make the distro/arch visible
// in Jenkins' BlueOcean view, which truncates names....
sh 'echo starting...'
}
stage("info") {
sh 'docker version'
sh 'docker info'
}
stage("build") {
try {
checkout scm
sh "make REF=$branch DOCKER_BUILD_PKGS='cross-mac' static"
} finally {
sh "make clean"
}
}
}
},
'cross-win': { ->
wrappedNode(label: 'ubuntu-2004 && x86_64', cleanWorkspace: true) {
stage("cross-win") {
def genPkgSteps(opts) {
return opts.arches.collectEntries {
["${opts.image}-${it}": genPkgStep(opts, it)]
}
}

def genStaticStep(LinkedHashMap pkg, String arch) {
def config = [
amd64: [label: "x86_64", targetarch: "amd64"],
aarch64: [label: "aarch64", targetarch: "arm64"],
armv6: [label: "aarch64", targetarch: "arm/v6"],
armv7: [label: "aarch64", targetarch: "arm/v7"],
ppc64le: [label: "ppc64le", targetarch: "ppc64le"],
s390x : [label: "s390x", targetarch: "s390x"],
][arch]
def nodeLabel = "linux&&${config.label}"
if (config.label == 'x86_64') {
nodeLabel = "${nodeLabel}&&ubuntu"
}
def branch = env.CHANGE_TARGET ?: env.BRANCH_NAME
return { ->
wrappedNode(label: nodeLabel, cleanWorkspace: true) {
stage("static-${pkg.os}-${arch}") {
// This is just a "dummy" stage to make the distro/arch visible
// in Jenkins' BlueOcean view, which truncates names....
sh 'echo starting...'
}
stage("info") {
sh 'docker version'
sh 'docker info'
sh 'env|sort'
}
stage("build") {
try {
checkout scm
sh "make REF=$branch DOCKER_BUILD_PKGS='cross-win' static"
sh "make REF=$branch TARGETPLATFORM=${pkg.os}/${config.targetarch} static"
} finally {
sh "make clean"
}
}
}
},
]
}
}

def genPackageSteps(opts) {
def genStaticSteps(opts) {
return opts.arches.collectEntries {
["${opts.image}-${it}": genBuildStep(opts, it)]
["static-${opts.os}-${it}": genStaticStep(opts, it)]
}
}

build_package_steps << pkgs.collectEntries { genPackageSteps(it) }
def parallelStages = pkgs.collectEntries { genPkgSteps(it) }
parallelStages << statics.collectEntries { genStaticSteps(it) }

parallel(build_package_steps)
parallel(parallelStages)
16 changes: 6 additions & 10 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
include common.mk

STATIC_VERSION=$(shell static/gen-static-ver $(realpath $(CURDIR)/src/github.com/docker/docker) $(VERSION))

# Taken from: https://www.cmcrossroads.com/article/printing-value-makefile-variable
print-% : ; @echo $($*)

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

.PHONY: deb rpm
deb rpm: checkout ## build rpm/deb packages
$(MAKE) -C $@ VERSION=$(VERSION) GO_VERSION=$(GO_VERSION) $@
$(MAKE) -C $@ $@

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

.PHONY: debian-% raspbian-% ubuntu-%
debian-% raspbian-% ubuntu-%: checkout ## build deb packages for the specified distro
$(MAKE) -C deb VERSION=$(VERSION) GO_VERSION=$(GO_VERSION) $@
$(MAKE) -C deb $@


.PHONY: static
static: DOCKER_BUILD_PKGS:=static-linux cross-mac cross-win cross-arm
static: checkout ## build static-compiled packages
for p in $(DOCKER_BUILD_PKGS); do \
$(MAKE) -C $@ VERSION=$(VERSION) GO_VERSION=$(GO_VERSION) TARGETPLATFORM=$(TARGETPLATFORM) CONTAINERD_VERSION=$(CONTAINERD_VERSION) RUNC_VERSION=$(RUNC_VERSION) $${p}; \
done
static: checkout ## build static package
$(MAKE) -C static build

.PHONY: verify
verify: ## verify installation of packages
16 changes: 16 additions & 0 deletions common.mk
Original file line number Diff line number Diff line change
@@ -50,7 +50,23 @@ VERIFY_PACKAGE_REPO ?= staging
# Optional flags like --platform=linux/armhf
VERIFY_PLATFORM ?=

# Export vars as envs
export BUILDTIME
export DEFAULT_PRODUCT_LICENSE
export PACKAGER_NAME
export PLATFORM
export VERSION
export GO_VERSION

export DOCKER_CLI_REPO
export DOCKER_ENGINE_REPO
export DOCKER_SCAN_REPO
export DOCKER_COMPOSE_REPO
export DOCKER_BUILDX_REPO

export REF
export DOCKER_CLI_REF
export DOCKER_ENGINE_REF
export DOCKER_SCAN_REF
export DOCKER_COMPOSE_REF
export DOCKER_BUILDX_REF
110 changes: 15 additions & 95 deletions static/Makefile
Original file line number Diff line number Diff line change
@@ -4,112 +4,32 @@ CLI_DIR=$(realpath $(CURDIR)/../src/github.com/docker/cli)
ENGINE_DIR=$(realpath $(CURDIR)/../src/github.com/docker/docker)
BUILDX_DIR=$(realpath $(CURDIR)/../src/github.com/docker/buildx)

GEN_STATIC_VER=$(shell ./gen-static-ver $(CLI_DIR) $(VERSION))
STATIC_VERSION=$(shell ./gen-static-ver $(CLI_DIR) $(VERSION))
HASH_CMD=docker run -v $(CURDIR):/sum -w /sum debian:jessie bash hash_files
DIR_TO_HASH:=build/linux
DOCKER_CLI_GOLANG_IMG=golang:$(GO_VERSION)

DOCKER_BUILD_OPTS=
export CLI_DIR
export ENGINE_DIR
export BUILDX_DIR

ifneq ($(strip $(CONTAINERD_VERSION)),)
# Set custom build-args to override the containerd version to build for static
# packages. The Dockerfile for 20.10 and earlier used CONTAINERD_COMMIT, later
# versions use CONTAINERD_VERSION. We can remove CONTAINERD_VERSION once 20.10.x
# reaches EOL.
DOCKER_BUILD_OPTS +=--build-arg=CONTAINERD_VERSION=$(CONTAINERD_VERSION)
DOCKER_BUILD_OPTS +=--build-arg=CONTAINERD_COMMIT=$(CONTAINERD_VERSION)
endif

ifneq ($(strip $(RUNC_VERSION)),)
# Set custom build-args to override the runc version to build for static packages.
DOCKER_BUILD_OPTS +=--build-arg=RUNC_VERSION=$(RUNC_VERSION)
endif
export STATIC_VERSION
export CONTAINERD_VERSION
export RUNC_VERSION

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

.PHONY: clean
clean: ## remove build artifacts
[ ! -d build ] || $(CHOWN) -R $(shell id -u):$(shell id -g) build
$(RM) -r build
-docker builder prune -f --filter until=24h

.PHONY: static
static: static-linux cross-mac cross-win cross-arm ## create all static packages

.PHONY: static-linux
static-linux: static-cli static-engine static-buildx-plugin ## create tgz
mkdir -p build/linux/docker
cp $(CLI_DIR)/build/docker build/linux/docker/
for f in dockerd containerd ctr containerd-shim containerd-shim-runc-v2 docker-init docker-proxy runc; do \
cp -L $(ENGINE_DIR)/bundles/binary-daemon/$$f build/linux/docker/$$f; \
done
tar -C build/linux -c -z -f build/linux/docker-$(GEN_STATIC_VER).tgz docker

# extra binaries for running rootless
mkdir -p build/linux/docker-rootless-extras
for f in rootlesskit rootlesskit-docker-proxy dockerd-rootless.sh dockerd-rootless-setuptool.sh vpnkit; do \
if [ -f $(ENGINE_DIR)/bundles/binary-daemon/$$f ]; then \
cp -L $(ENGINE_DIR)/bundles/binary-daemon/$$f build/linux/docker-rootless-extras/$$f; \
fi \
done
tar -C build/linux -c -z -f build/linux/docker-rootless-extras-$(GEN_STATIC_VER).tgz docker-rootless-extras
@[ ! -d build ] || $(CHOWN) -R $(shell id -u):$(shell id -g) build
@$(RM) -r build

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

.PHONY: hash_files
hash_files:
hash_files: ## hash files
@echo "Hashing directory $(DIR_TO_HASH)"
$(HASH_CMD) "$(DIR_TO_HASH)"

.PHONY: buildx
buildx:
docker buildx inspect | grep -q 'Driver: docker-container' || docker buildx create --use

.PHONY: cross-mac
cross-mac: buildx
cd $(CLI_DIR) && VERSION=$(GEN_STATIC_VER) docker buildx bake --set binary.platform=darwin/amd64,darwin/arm64 binary
dest=$$PWD/build/mac; cd $(CLI_DIR)/build && for platform in *; do \
arch=$$(echo $$platform | cut -d_ -f2); \
mkdir -p $$dest/$$arch/docker; \
cp $$platform/docker-darwin-* $$dest/$$arch/docker/docker && \
tar -C $$dest/$$arch -c -z -f $$dest/$$arch/docker-$(GEN_STATIC_VER).tgz docker; \
done

.PHONY: cross-win
cross-win: cross-win-engine
cd $(CLI_DIR) && VERSION=$(GEN_STATIC_VER) docker buildx bake --set binary.platform=windows/amd64 binary
mkdir -p build/win/amd64/docker
cp $(CLI_DIR)/build/docker-windows-amd64.exe build/win/amd64/docker/docker.exe
cp $(ENGINE_DIR)/bundles/cross/windows/amd64-daemon/dockerd.exe build/win/amd64/docker/dockerd.exe
cp $(ENGINE_DIR)/bundles/cross/windows/amd64-daemon/docker-proxy.exe build/win/amd64/docker/docker-proxy.exe
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'
$(CHOWN) -R $(shell id -u):$(shell id -g) build

.PHONY: cross-arm
cross-arm: cross-all-cli ## create tgz with linux armhf client only
mkdir -p build/arm/docker
cp $(CLI_DIR)/build/docker-linux-arm build/arm/docker/docker
tar -C build/arm -c -z -f build/arm/docker-$(GEN_STATIC_VER).tgz docker

.PHONY: static-cli
static-cli:
cd $(CLI_DIR) && VERSION=$(GEN_STATIC_VER) docker buildx bake --set binary.platform=$(TARGETPLATFORM) --set binary.args.CGO_ENABLED=$(CGO_ENABLED) binary

.PHONY: static-engine
static-engine:
$(MAKE) -C $(ENGINE_DIR) VERSION=$(GEN_STATIC_VER) DOCKER_BUILD_OPTS="$(DOCKER_BUILD_OPTS)" binary

.PHONY: static-buildx-plugin
static-buildx-plugin:
cd $(BUILDX_DIR) && docker buildx bake --set binaries.platform=$(TARGETPLATFORM) binaries && mv ./bin/buildx ./bin/docker-buildx

.PHONY: cross-all-cli
cross-all-cli:
$(MAKE) -C $(CLI_DIR) -f docker.Makefile VERSION=$(GEN_STATIC_VER) cross

.PHONY: cross-win-engine
cross-win-engine:
$(MAKE) -C $(ENGINE_DIR) VERSION=$(GEN_STATIC_VER) DOCKER_CROSSPLATFORMS=windows/amd64 DOCKER_BUILD_OPTS="$(DOCKER_BUILD_OPTS)" cross
Loading