Skip to content

Commit

Permalink
Dockerfile: DOCKER_STATIC arg
Browse files Browse the repository at this point in the history
Signed-off-by: CrazyMax <crazy-max@users.noreply.github.com>
  • Loading branch information
crazy-max committed Nov 26, 2022
1 parent 8041607 commit 02276cd
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 15 deletions.
36 changes: 21 additions & 15 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ ARG DOCKERCLI_VERSION=v17.06.2-ce
ARG CROSS="false"
ARG SYSTEMD="false"
ARG DEBIAN_FRONTEND=noninteractive
ARG DOCKER_STATIC=1

# cross compilation helper
FROM --platform=$BUILDPLATFORM tonistiigi/xx:${XX_VERSION} AS xx
Expand Down Expand Up @@ -236,16 +237,17 @@ WORKDIR /go/src/github.com/containerd/containerd
ARG DEBIAN_FRONTEND
ARG TARGETPLATFORM
RUN xx-apt-get install -y --no-install-recommends gcc libbtrfs-dev libsecret-1-dev
ARG DOCKER_STATIC
RUN --mount=from=containerd-src,src=/usr/src/containerd,rw \
--mount=type=cache,target=/root/.cache <<EOT
set -e
export CC=$(xx-info)-gcc
export CGO_ENABLED=0
export CGO_ENABLED=$([ "$DOCKER_STATIC" = "1" ] && echo "0" || echo "1")
xx-go --wrap
make binaries
xx-verify bin/containerd
xx-verify bin/containerd-shim-runc-v2
xx-verify bin/ctr
make $([ "$DOCKER_STATIC" = "1" ] && echo "STATIC=1") binaries
xx-verify $([ "$DOCKER_STATIC" = "1" ] && echo "--static") bin/containerd
xx-verify $([ "$DOCKER_STATIC" = "1" ] && echo "--static") bin/containerd-shim-runc-v2
xx-verify $([ "$DOCKER_STATIC" = "1" ] && echo "--static") bin/ctr
mkdir /build
mv bin/containerd bin/containerd-shim-runc-v2 bin/ctr /build
EOT
Expand Down Expand Up @@ -321,12 +323,13 @@ WORKDIR /go/src/github.com/opencontainers/runc
ARG DEBIAN_FRONTEND
ARG TARGETPLATFORM
RUN xx-apt-get install -y --no-install-recommends dpkg-dev gcc libc6-dev libseccomp-dev
ARG DOCKER_STATIC
RUN --mount=from=runc-src,src=/usr/src/runc,rw \
--mount=type=cache,target=/root/.cache <<EOT
set -e
xx-go --wrap
CGO_ENABLED=1 make BUILDTAGS="seccomp" runc
xx-verify runc
CGO_ENABLED=1 make BUILDTAGS="seccomp" "$([ "$DOCKER_STATIC" = "1" ] && echo "static" || echo "runc")"
xx-verify $([ "$DOCKER_STATIC" = "1" ] && echo "--static") runc
mkdir /build
mv runc /build/
EOT
Expand All @@ -350,14 +353,16 @@ ARG DEBIAN_FRONTEND
RUN apt-get update && apt-get install -y --no-install-recommends cmake
ARG TARGETPLATFORM
RUN xx-apt-get install -y --no-install-recommends gcc libc6-dev
ARG DOCKER_STATIC
RUN --mount=from=tini-src,src=/usr/src/tini,rw \
--mount=type=cache,target=/root/.cache <<EOT
set -e
tinitarget=$([ "$DOCKER_STATIC" = "1" ] && echo "tini-static" || echo "tini")
CC=$(xx-info)-gcc cmake .
make tini
xx-verify tini
make ${tinitarget}
xx-verify $([ "$DOCKER_STATIC" = "1" ] && echo "--static") ${tinitarget}
mkdir /build
mv tini /build/docker-init
mv ${tinitarget} /build/docker-init
EOT

FROM tini-build AS tini-linux
Expand All @@ -378,15 +383,16 @@ ARG DEBIAN_FRONTEND
ARG TARGETPLATFORM
RUN xx-apt-get install -y --no-install-recommends gcc libc6-dev
ENV GO111MODULE=on
ENV CGO_ENABLED=1
ARG DOCKER_STATIC
RUN --mount=from=rootlesskit-src,src=/usr/src/rootlesskit,rw \
--mount=type=cache,target=/go/pkg/mod \
--mount=type=cache,target=/root/.cache <<EOT
set -e
xx-go build -o /build/rootlesskit -ldflags="-linkmode=external" ./cmd/rootlesskit
xx-verify /build/rootlesskit
xx-go build -o /build/rootlesskit-docker-proxy -ldflags="-linkmode=external" ./cmd/rootlesskit-docker-proxy
xx-verify /build/rootlesskit-docker-proxy
export CGO_ENABLED=$([ "$DOCKER_STATIC" = "1" ] && echo "0" || echo "1")
xx-go build -o /build/rootlesskit -ldflags="$([ "$DOCKER_STATIC" != "1" ] && echo "-linkmode=external")" ./cmd/rootlesskit
xx-verify $([ "$DOCKER_STATIC" = "1" ] && echo "--static") /build/rootlesskit
xx-go build -o /build/rootlesskit-docker-proxy -ldflags="$([ "$DOCKER_STATIC" != "1" ] && echo "-linkmode=external")" ./cmd/rootlesskit-docker-proxy
xx-verify $([ "$DOCKER_STATIC" = "1" ] && echo "--static") /build/rootlesskit-docker-proxy
EOT
COPY ./contrib/dockerd-rootless.sh /build/
COPY ./contrib/dockerd-rootless-setuptool.sh /build/
Expand Down
4 changes: 4 additions & 0 deletions docker-bake.hcl
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
variable "BUNDLES_OUTPUT" {
default = "./bundles"
}
variable "DOCKER_STATIC" {
default = "1"
}
variable "DOCKER_CROSSPLATFORMS" {
default = ""
}
Expand All @@ -9,6 +12,7 @@ target "_common" {
args = {
BUILDKIT_CONTEXT_KEEP_GIT_DIR = 1
APT_MIRROR = "cdn-fastly.deb.debian.org"
DOCKER_STATIC = DOCKER_STATIC
}
}

Expand Down

0 comments on commit 02276cd

Please sign in to comment.