Skip to content
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

dockerfile: use glibc to build riscv64 #4332

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
45 changes: 45 additions & 0 deletions .github/workflows/buildkit.yml
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,51 @@ jobs:
path: ${{ env.DESTDIR }}/*
if-no-files-found: error

prepare-smoketest:
runs-on: ubuntu-20.04
outputs:
matrix: ${{ steps.platforms.outputs.matrix }}
steps:
-
name: Checkout
uses: actions/checkout@v4
-
name: Create matrix
id: platforms
run: |
matrix="$(docker buildx bake binaries-smoketest --print | jq -cr '.target."binaries-smoketest".platforms')"
echo "matrix=$matrix" >> $GITHUB_OUTPUT

smoketest:
runs-on: ubuntu-20.04
needs:
- prepare-smoketest
strategy:
fail-fast: false
matrix:
platform: ${{ fromJson(needs.prepare-smoketest.outputs.matrix) }}
steps:
-
name: Checkout
uses: actions/checkout@v4
-
name: Set up QEMU
uses: docker/setup-qemu-action@v3
-
name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
with:
version: ${{ env.SETUP_BUILDX_VERSION }}
driver-opts: image=${{ env.SETUP_BUILDKIT_IMAGE }}
buildkitd-flags: --debug
-
name: Test
uses: docker/bake-action@v4
with:
targets: binaries-smoketest
set: |
*.platform=${{ matrix.platform }}

image:
runs-on: ubuntu-22.04
needs:
Expand Down
69 changes: 58 additions & 11 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,15 @@ ARG DELVE_VERSION=v1.21.0

ARG GO_VERSION=1.20
ARG ALPINE_VERSION=3.18
ARG XX_VERSION=1.2.1
ARG BUILDKIT_DEBUG

# xx is a helper for cross-compilation
FROM --platform=$BUILDPLATFORM tonistiigi/xx:${XX_VERSION} AS xx

# go base image to retrieve /usr/local/go for ubuntu gobuild base
FROM --platform=$BUILDPLATFORM golang:${GO_VERSION} AS golang-debian

# minio for s3 integration tests
FROM minio/minio:${MINIO_VERSION} AS minio
FROM minio/mc:${MINIO_MC_VERSION} AS minio-mc
Expand All @@ -35,21 +42,33 @@ FROM alpine:${ALPINE_VERSION} AS alpine-ppc64le
FROM alpine:edge@sha256:2d01a16bab53a8405876cec4c27235d47455a7b72b75334c614f2fb0968b3f90 AS alpine-riscv64
FROM alpine-$TARGETARCH AS alpinebase

# xx is a helper for cross-compilation
FROM --platform=$BUILDPLATFORM tonistiigi/xx:1.2.1 AS xx
# gobuild is base stage for compiling go/cgo
FROM --platform=$BUILDPLATFORM golang:${GO_VERSION}-alpine${ALPINE_VERSION} AS gobuild-base-alpine
COPY --from=xx / /
RUN apk add --no-cache file bash clang lld musl-dev pkgconfig git make

# go base image
FROM --platform=$BUILDPLATFORM golang:${GO_VERSION}-alpine${ALPINE_VERSION} AS golatest
FROM --platform=$BUILDPLATFORM ubuntu:22.04 AS gobuild-base-ubuntu
COPY --from=xx / /
RUN apt-get update && apt-get install --no-install-recommends -y ca-certificates file bash clang lld llvm pkg-config git make
COPY --from=golang-debian /usr/local/go /usr/local/go
ENV GOROOT="/usr/local/go"
ENV GOPATH="/go"
ENV PATH="$GOPATH/bin:/usr/local/go/bin:$PATH"
RUN mkdir -p "$GOPATH/src" "$GOPATH/bin" && chmod -R 777 "$GOPATH"

# TODO: remove once go cgo build for riscv64 is properly fixed: https://github.com/moby/buildkit/issues/4316
FROM gobuild-base-alpine AS gobuild-base-amd64
FROM gobuild-base-alpine AS gobuild-base-arm
FROM gobuild-base-alpine AS gobuild-base-arm64
FROM gobuild-base-alpine AS gobuild-base-s390x
FROM gobuild-base-alpine AS gobuild-base-ppc64le
FROM gobuild-base-ubuntu AS gobuild-base-riscv64
FROM gobuild-base-$TARGETARCH AS gobuild-base

# git stage is used for checking out remote repository sources
FROM --platform=$BUILDPLATFORM alpine:${ALPINE_VERSION} AS git
FROM --platform=$BUILDPLATFORM alpinebase AS git
RUN apk add --no-cache git

# gobuild is base stage for compiling go/cgo
FROM golatest AS gobuild-base
RUN apk add --no-cache file bash clang lld musl-dev pkgconfig git make
COPY --link --from=xx / /

# delve for debug variant
FROM gobuild-base AS dlv
ARG DELVE_VERSION
Expand All @@ -65,13 +84,28 @@ RUN git clone https://github.com/opencontainers/runc.git runc \
&& cd runc && git checkout -q "$RUNC_VERSION"

# build runc binary
FROM gobuild-base AS runc
FROM gobuild-base AS runc-base-alpine
WORKDIR $GOPATH/src/github.com/opencontainers/runc
ARG TARGETPLATFORM
# gcc is only installed for libgcc
# lld has issues building static binaries for ppc so prefer ld for it
RUN set -e; xx-apk add musl-dev gcc libseccomp-dev libseccomp-static; \
[ "$(xx-info arch)" != "ppc64le" ] || XX_CC_PREFER_LINKER=ld xx-clang --setup-target-triple

FROM gobuild-base AS runc-base-ubuntu
WORKDIR $GOPATH/src/github.com/opencontainers/runc
ARG TARGETPLATFORM
RUN xx-apt-get install --no-install-recommends -y dpkg-dev gcc libc6-dev libseccomp-dev

FROM runc-base-alpine AS runc-base-amd64
FROM runc-base-alpine AS runc-base-arm
FROM runc-base-alpine AS runc-base-arm64
FROM runc-base-alpine AS runc-base-s390x
FROM runc-base-alpine AS runc-base-ppc64le
FROM runc-base-ubuntu AS runc-base-riscv64
FROM runc-base-$TARGETARCH AS runc-base

FROM runc-base AS runc
RUN --mount=from=runc-src,src=/usr/src/runc,target=. --mount=target=/root/.cache,type=cache \
CGO_ENABLED=1 xx-go build -mod=vendor -ldflags '-extldflags -static' -tags 'apparmor seccomp netgo cgo static_build osusergo' -o /usr/bin/runc ./ && \
xx-verify --static /usr/bin/runc
Expand Down Expand Up @@ -345,5 +379,18 @@ ENV BUILDKIT_HOST=unix:///run/user/1000/buildkit/buildkitd.sock
VOLUME /home/user/.local/share/buildkit
ENTRYPOINT ["rootlesskit", "buildkitd"]

# smoke tests
FROM --platform=$TARGETPLATFORM buildkit-export AS binaries-smoketest
WORKDIR /usr/local/bin
COPY --from=binaries / .
RUN apk add --no-cache file
RUN <<EOT
set -ex
file buildkitd
buildkitd --version
file buildkit-runc
buildkit-runc --version
EOT

# buildkit builds the buildkit container image
FROM buildkit-$TARGETOS${BUILDKIT_DEBUG:+-debug} AS buildkit
14 changes: 14 additions & 0 deletions docker-bake.hcl
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,20 @@ target "binaries-cross" {
]
}

target "binaries-smoketest" {
inherits = ["_common"]
target = "binaries-smoketest"
output = ["type=cacheonly"]
platforms = [
"linux/amd64",
"linux/arm/v7",
"linux/arm64",
"linux/s390x",
"linux/ppc64le",
"linux/riscv64"
]
}

target "release" {
inherits = ["binaries-cross"]
target = "release"
Expand Down