67 lines
2.1 KiB
Text
67 lines
2.1 KiB
Text
########################################
|
|
FROM --platform=$BUILDPLATFORM messense/rust-musl-cross:${TARGETARCH}-musl AS builder
|
|
|
|
LABEL maintainer="Jun Kurihara"
|
|
|
|
ARG TARGETARCH
|
|
ARG CARGO_FEATURES
|
|
ENV CARGO_FEATURES=${CARGO_FEATURES}
|
|
|
|
RUN if [ $TARGETARCH = "amd64" ]; then \
|
|
echo "x86_64" > /arch; \
|
|
elif [ $TARGETARCH = "arm64" ]; then \
|
|
echo "aarch64" > /arch; \
|
|
else \
|
|
echo "Unsupported platform: $TARGETARCH"; \
|
|
exit 1; \
|
|
fi
|
|
|
|
ENV CFLAGS=-Ofast
|
|
|
|
WORKDIR /tmp
|
|
|
|
COPY . /tmp/
|
|
|
|
ENV RUSTFLAGS="-C link-arg=-s"
|
|
|
|
RUN echo "Building rpxy from source" && \
|
|
# force to reinstall rustup to get the latest version
|
|
rm -rf ~/.rustup && \
|
|
curl https://sh.rustup.rs -sqSf | sh -s -- -y --profile minimal --default-toolchain stable --default-host $(uname -m)-unknown-linux-gnu && \
|
|
rustup target add $(cat /arch)-unknown-linux-musl || rustup component add --toolchain stable rust-src && \
|
|
rustup component add --toolchain stable rustfmt clippy && \
|
|
# build rpxy
|
|
cargo build --release --target $(cat /arch)-unknown-linux-musl ${CARGO_FEATURES} && \
|
|
musl-strip --strip-all /tmp/target/$(cat /arch)-unknown-linux-musl/release/rpxy && \
|
|
cp /tmp/target/$(cat /arch)-unknown-linux-musl/release/rpxy /tmp/target/release/rpxy
|
|
|
|
########################################
|
|
FROM --platform=$TARGETPLATFORM alpine:latest AS runner
|
|
LABEL maintainer="Jun Kurihara"
|
|
|
|
ENV RUNTIME_DEPS="logrotate ca-certificates su-exec"
|
|
|
|
RUN apk add --no-cache ${RUNTIME_DEPS} && \
|
|
update-ca-certificates && \
|
|
find / -type d -path /proc -prune -o -type f -perm /u+s -exec chmod u-s {} \; && \
|
|
find / -type d -path /proc -prune -o -type f -perm /g+s -exec chmod g-s {} \; && \
|
|
mkdir -p /rpxy/bin &&\
|
|
mkdir -p /rpxy/log &&\
|
|
mkdir -p /rpxy/cache &&\
|
|
mkdir -p /rpxy/config
|
|
|
|
COPY --from=builder /tmp/target/release/rpxy /rpxy/bin/rpxy
|
|
COPY ./docker/run.sh /rpxy
|
|
COPY ./docker/entrypoint.sh /rpxy
|
|
|
|
RUN chmod +x /rpxy/run.sh && \
|
|
chmod +x /rpxy/entrypoint.sh
|
|
|
|
ENV SSL_CERT_FILE=/etc/ssl/certs/ca-certificates.crt
|
|
ENV SSL_CERT_DIR=/etc/ssl/certs
|
|
|
|
EXPOSE 80 443
|
|
|
|
CMD ["/rpxy/entrypoint.sh"]
|
|
|
|
ENTRYPOINT ["/rpxy/entrypoint.sh"]
|