JacobLinCool / JacobLinCool/node-prisma-alpine

Cross Compilation instead of QEMU Emulation

Open
#2 0 comments 0 reactions 0 assignees View on GitHub
help wanted
Dominant language
TypeScript
Stars
2
Forks
1
PR merge metrics
No merged PRs in 30d

Description

Currently, I use buildx, which uses QEMU under the hood, to build multi-arch images.

The problem is, the compilation is very slow and takes up to 5 and a half hours when building for another architecture.

I have tried the following Dockerfile but it always fails on compiling amd64 binaries on my Apple Silicon MBP.

```dockerfile
FROM --platform=$BUILDPLATFORM rust:alpine as preparation

ARG PRISMA_VERSION
RUN apk --no-cache add git
RUN git clone --depth=1 --branch=${PRISMA_VERSION} https://github.com/prisma/prisma-engines.git /prisma
RUN cd /prisma && cargo fetch

FROM --platform=$BUILDPLATFORM rust:alpine as builder

ARG TARGETARCH
ENV RUSTFLAGS="-C target-feature=-crt-static"
RUN apk --no-cache add openssl direnv git musl-dev openssl-dev build-base perl protoc gcc
RUN ln -s /usr/bin/gcc /usr/bin/musl-gcc
COPY --from=preparation /prisma /prisma
COPY --from=preparation /usr/local/cargo /usr/local/cargo
RUN cd /prisma && [ "$TARGETARCH" = "amd64" ] && rustup target add x86_64-unknown-linux-musl && cargo build --release --offline --target x86_64-unknown-linux-musl && cp -R /prisma/target/x86_64-unknown-linux-musl/release /tmp/prisma-engines || true
RUN cd /prisma && [ "$TARGETARCH" = "arm64" ] && rustup target add aarch64-unknown-linux-musl && cargo build --release --offline --target aarch64-unknown-linux-musl && cp -R /prisma/target/aarch64-unknown-linux-musl/release /tmp/prisma-engines || true

FROM node:lts-alpine as production

RUN apk --no-cache add openssl
COPY --from=builder /tmp/prisma-engines/ /tmp/prisma-engines/
ENV PRISMA_QUERY_ENGINE_BINARY=/tmp/prisma-engines/query-engine \
PRISMA_MIGRATION_ENGINE_BINARY=/tmp/prisma-engines/migration-engine \
PRISMA_INTROSPECTION_ENGINE_BINARY=/tmp/prisma-engines/introspection-engine \
PRISMA_FMT_BINARY=/tmp/prisma-engines/prisma-fmt \
PRISMA_CLI_QUERY_ENGINE_TYPE=binary \
PRISMA_CLIENT_ENGINE_TYPE=binary
```

Contributor guide

No contributing guide indexed for this repository

Research direction

Start with the Dockerfile and the buildx multi-architecture build described in the issue, then reproduce the amd64 build on Apple Silicon. Investigate the Rust cargo build and target setup for the prisma-engines binaries; done means both amd64 and arm64 images build without QEMU emulation.

Written by the indexing model from the issue text.

Assessment

Tech stack
docker, rust
Domain
build-system, devops
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
20/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.