docker cross compilation

This commit is contained in:
lovasoa
2023-10-03 02:56:24 +02:00
parent 0edaeff502
commit 4a32aca0ef
3 changed files with 39 additions and 11 deletions
+5
View File
@@ -0,0 +1,5 @@
[target.armv7-unknown-linux-gnueabihf]
linker = "gcc-arm-linux-gnueabihf"
[target.aarch64-unknown-linux-gnu]
linker = "aarch64-linux-gnu-gcc"
+2
View File
@@ -10,3 +10,5 @@ configuration.md
.github/
examples/
mssql/
tests/
.idea/
+32 -11
View File
@@ -1,19 +1,40 @@
FROM rust:1.72-alpine3.17 as builder
RUN apk add --no-cache musl-dev
FROM --platform=$BUILDPLATFORM rust:1.72-slim as builder
WORKDIR /usr/src/sqlpage
RUN cargo init .
ARG TARGETARCH
RUN apt-get update && apt-get install -y musl-tools && \
if [ "$TARGETARCH" = "amd64" ]; then \
echo x86_64-unknown-linux-gnu > TARGET; \
apt-get install -y gcc libgcc-s1; \
cp /lib/x86_64-linux-gnu/libgcc_s.so.1 libgcc_s.so.1; \
elif [ "$TARGETARCH" = "arm64" ]; then \
echo aarch64-unknown-linux-gnu > TARGET; \
apt-get install -y gcc-aarch64-linux-gnu libgcc-s1-arm64-cross; \
cp /usr/aarch64-linux-gnu/lib/libgcc_s.so.1 libgcc_s.so.1; \
elif [ "$TARGETARCH" = "arm" ]; then \
echo armv7-unknown-linux-gnueabihf > TARGET; \
apt-get install -y gcc-arm-linux-gnueabihf libgcc-s1-armhf-cross; \
cp /usr/arm-linux-gnueabihf/lib/libgcc_s.so.1 libgcc_s.so.1; \
else \
echo "Unknown platform: $TARGETPLATFORM"; \
exit 1; \
fi && \
rustup target add $(cat TARGET) && \
cargo init .
COPY Cargo.toml Cargo.lock ./
RUN cargo build --profile superoptimized
COPY .cargo ./.cargo
RUN cargo build --target $(cat TARGET) --profile superoptimized
COPY . .
RUN touch src/main.rs && \
cargo build --profile superoptimized
cargo build --target $(cat TARGET) --profile superoptimized
RUN mv target/$(cat TARGET)/superoptimized/sqlpage sqlpage.bin && \
strip sqlpage.bin
FROM alpine:3.17
RUN rm -rf /var/lib/apt/lists/* && \
addgroup -S sqlpage && adduser -S sqlpage -G sqlpage
COPY --from=builder /usr/src/sqlpage/target/superoptimized/sqlpage /usr/local/bin/sqlpage
FROM busybox:glibc
RUN addgroup --system sqlpage && \
adduser --system --no-create-home --ingroup sqlpage sqlpage
COPY --from=builder /usr/src/sqlpage/sqlpage.bin /usr/local/bin/sqlpage
COPY --from=builder /usr/src/sqlpage/libgcc_s.so.1 /lib/libgcc_s.so.1
WORKDIR /var/www
COPY --from=builder /usr/src/sqlpage/index.sql .
USER sqlpage
EXPOSE 8080
CMD ["sqlpage"]
CMD ["/usr/local/bin/sqlpage"]