Spaces:
Runtime error
Runtime error
File size: 2,371 Bytes
62459c6 4364310 ad297a0 82cc061 4364310 aab1269 4364310 ad297a0 4364310 ad297a0 4364310 ad297a0 4364310 ad297a0 aab1269 d900bad ad297a0 4364310 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 |
FROM --platform=$BUILDPLATFORM rust:1.75.0-alpine3.18 AS chef
# We only pay the installation cost once,
# it will be cached from the second build onwards
RUN apk add --no-cache alpine-sdk musl-dev g++ make libcrypto3 libressl-dev upx perl build-base
RUN cargo install cargo-chef --locked
WORKDIR /app
FROM chef AS planner
COPY ./Cargo.toml ./Cargo.lock ./
RUN cargo chef prepare --recipe-path recipe.json
FROM --platform=$BUILDPLATFORM chef AS builder
COPY --from=planner /app/recipe.json recipe.json
# Specify the cache type to use (memory, redis, hybrid, no-cache)
ARG CACHE=memory
ENV CACHE=${CACHE}
# Cook the dependencies
RUN export ARCH=$(uname -m) && \
if [ "$CACHE" = "memory" ] ; then cargo chef cook --release --target=$ARCH-unknown-linux-musl --recipe-path recipe.json ; \
else if [ "$CACHE" = "redis" ] ; then cargo chef cook --release --target=$ARCH-unknown-linux-musl --no-default-features --features redis-cache --recipe-path recipe.json ; \
else if [ "$CACHE" = "hybrid" ] ; then cargo chef cook --release --target=$ARCH-unknown-linux-musl --features redis-cache --recipe-path recipe.json ; \
else if [ "$CACHE" = "no-cache" ] ; then cargo chef cook --release --target=$ARCH-unknown-linux-musl --no-default-features --recipe-path recipe.json ; fi ; fi ; fi ; fi
# Copy the source code and public folder
COPY ./src ./src
COPY ./public ./public
# Build the application
RUN export ARCH=$(uname -m) && \
if [ "$CACHE" = "memory" ] ; then cargo build --release --target=$ARCH-unknown-linux-musl ; \
else if [ "$CACHE" = "redis" ] ; then cargo build --release --target=$ARCH-unknown-linux-musl --no-default-features --features redis-cache ; \
else if [ "$CACHE" = "hybrid" ] ; then cargo build --release --target=$ARCH-unknown-linux-musl --features redis-cache ; \
else if [ "$CACHE" = "no-cache" ] ; then cargo build --release --target=$ARCH-unknown-linux-musl --no-default-features ; fi ; fi ; fi ; fi
# Optimise binary size with UPX
RUN export ARCH=$(uname -m) \
&& upx --lzma --best /app/target/$ARCH-unknown-linux-musl/release/websurfx \
&& cp /app/target/$ARCH-unknown-linux-musl/release/websurfx /usr/local/bin/websurfx
FROM --platform=$BUILDPLATFORM scratch
COPY --from=builder /app/public/ /opt/websurfx/public/
VOLUME ["/etc/xdg/websurfx/"]
COPY --from=builder /usr/local/bin/websurfx /usr/local/bin/websurfx
CMD ["websurfx"]
|