2020-10-10 21:15:19 +02:00
|
|
|
# Using multistage build:
|
|
|
|
# https://docs.docker.com/develop/develop-images/multistage-build/
|
|
|
|
# https://whitfin.io/speeding-up-rust-docker-builds/
|
|
|
|
|
|
|
|
########################## BUILD IMAGE ##########################
|
|
|
|
# Rust build image to build Autarco Scraper's statically compiled binary
|
2021-08-27 21:42:26 +02:00
|
|
|
FROM docker.io/rust:1.54 as builder
|
2020-10-10 21:15:19 +02:00
|
|
|
|
|
|
|
# Build the dependencies first
|
|
|
|
RUN USER=root cargo new --bin autarco-scraper
|
|
|
|
WORKDIR ./autarco-scraper
|
|
|
|
COPY ./Cargo.* ./
|
|
|
|
RUN cargo build --release
|
|
|
|
RUN rm src/*.rs
|
|
|
|
|
|
|
|
# Add the real project files from current folder
|
|
|
|
ADD . ./
|
|
|
|
|
|
|
|
# Build the actual binary from the copied local files
|
|
|
|
RUN rm ./target/release/deps/autarco_scraper*
|
|
|
|
RUN cargo build --release
|
|
|
|
|
|
|
|
########################## RUNTIME IMAGE ##########################
|
|
|
|
# Create new stage with a minimal image for the actual runtime image/container
|
2021-08-27 21:42:26 +02:00
|
|
|
FROM docker.io/debian:bullseye-slim
|
2020-10-10 21:15:19 +02:00
|
|
|
|
2021-08-27 21:42:26 +02:00
|
|
|
# Install CA certificates
|
2020-10-10 21:15:19 +02:00
|
|
|
RUN apt-get update && \
|
|
|
|
apt-get upgrade -y && \
|
2021-08-27 21:42:26 +02:00
|
|
|
apt-get install -y --no-install-recommends ca-certificates && \
|
2020-10-10 21:15:19 +02:00
|
|
|
rm -rf /var/lib/apt/lists/*
|
|
|
|
|
|
|
|
# Copy the binary from the "builder" stage to the current stage
|
|
|
|
RUN adduser --system --disabled-login --home /autarco-scraper --gecos "" --shell /bin/bash autarco-scraper
|
|
|
|
COPY --from=builder /autarco-scraper/target/release/autarco-scraper /autarco-scraper
|
|
|
|
|
|
|
|
# Standard port on which Rocket launches
|
|
|
|
EXPOSE 8000
|
|
|
|
|
|
|
|
# Set user to www-data
|
|
|
|
USER autarco-scraper
|
|
|
|
|
|
|
|
# Set container home directory
|
|
|
|
WORKDIR /autarco-scraper
|
|
|
|
|
|
|
|
# Run Autarco Scraper
|
|
|
|
ENTRYPOINT [ "/autarco-scraper/autarco-scraper" ]
|