Skip to content

Commit

Permalink
Add src bake target to retrieve the qemu source with patches applied
Browse files Browse the repository at this point in the history
Signed-off-by: Tibor Vass <[email protected]>
  • Loading branch information
tiborvass committed Apr 8, 2022
1 parent 1aa2eba commit 1f4eac6
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 5 deletions.
9 changes: 6 additions & 3 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,13 @@ ARG QEMU_REPO=https://github.com/qemu/qemu
# xx is a helper for cross-compilation
FROM --platform=$BUILDPLATFORM tonistiigi/xx@sha256:56b19a5fb89b99195ec494d59ad34370d14540858c1f56c560ec1e7f2d1c177f AS xx

FROM --platform=$BUILDPLATFORM ${ALPINE_BASE} AS src
FROM --platform=$BUILDPLATFORM ${ALPINE_BASE} AS src-clone
RUN apk add --no-cache git patch

WORKDIR /src
ARG QEMU_VERSION
ARG QEMU_REPO
RUN git clone $QEMU_REPO && cd qemu && git checkout $QEMU_VERSION
RUN mkdir qemu && cd qemu && git init && git fetch --depth 1 $QEMU_REPO $QEMU_VERSION && git checkout FETCH_HEAD
COPY patches patches
ARG QEMU_PATCHES=cpu-max
ARG QEMU_PATCHES_ALL=${QEMU_PATCHES},alpine-patches,zero-init-msghdr,sched
Expand Down Expand Up @@ -53,6 +53,9 @@ RUN <<eof
scripts/git-submodule.sh update ui/keycodemapdb tests/fp/berkeley-testfloat-3 tests/fp/berkeley-softfloat-3 dtc slirp
eof

FROM scratch AS src
COPY --from=src-clone /src/qemu/ /

FROM --platform=$BUILDPLATFORM ${ALPINE_BASE} AS base
RUN apk add --no-cache git clang lld python3 llvm make ninja pkgconfig glib-dev gcc musl-dev perl bash
COPY --from=xx / /
Expand All @@ -70,7 +73,7 @@ FROM base AS build
ARG TARGETPLATFORM
ARG QEMU_VERSION QEMU_TARGETS
ENV AR=llvm-ar STRIP=llvm-strip
RUN --mount=target=.,from=src,src=/src/qemu,rw --mount=target=./install-scripts,src=scripts \
RUN --mount=target=.,from=src-clone,src=/src/qemu,rw --mount=target=./install-scripts,src=scripts \
TARGETPLATFORM=${TARGETPLATFORM} configure_qemu.sh && \
make -j "$(getconf _NPROCESSORS_ONLN)" && \
make install && \
Expand Down
17 changes: 15 additions & 2 deletions docker-bake.hcl
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@ variable "QEMU_REPO" {
variable "QEMU_VERSION" {
default = "v6.2.0"
}
variable "QEMU_PATCHES" {
default = "cpu-max,buildkit-direct-execve-v6.2"
}

// Special target: https://github.com/docker/metadata-action#bake-definition
target "meta-helper" {
Expand Down Expand Up @@ -54,7 +57,7 @@ target "buildkit" {
inherits = ["mainline"]
args = {
BINARY_PREFIX = "buildkit-"
QEMU_PATCHES = "cpu-max,buildkit-direct-execve-v6.2"
QEMU_PATCHES = QEMU_PATCHES
QEMU_PRESERVE_ARGV0 = ""
}
cache-from = ["${REPO}:buildkit-master"]
Expand All @@ -80,4 +83,14 @@ target "archive" {

target "archive-all" {
inherits = ["archive", "all-arch"]
}
}

target "src" {
inherits = ["mainline"]
args = {
QEMU_PATCHES = QEMU_PATCHES
QEMU_PRESERVE_ARGV0 = ""
}
target = "src"
output = ["./qemu"]
}

0 comments on commit 1f4eac6

Please sign in to comment.