# Author: FL03 <jo3mccain@icloud.com>
ARG RUST_VERSION=latest
FROM rust:${RUST_VERSION} AS builder-base
# update and upgrade the system
RUN apt-get update -y && apt-get upgrade -y
FROM builder-base AS builder
# setup the working directory
WORKDIR /app
# copy the source code
ADD . .
# build the project
RUN --mount=type=cache,target=/workspace/target/ \
--mount=type=cache,target=/usr/local/cargo/registry/ \
cargo build --release --verbose
FROM debian:bookworm-slim AS runner-base
# update and upgrade the system
RUN apt-get update -y && \
apt-get upgrade -y
# install the required system dependencies
RUN apt-get install -y \
postgresql
# create a user and group
RUN groupadd -g 10001 agroup && \
useradd -m -u 10001 -g agroup auser
# switch to the user
USER auser
# copy the binary to the system
COPY --from=builder --chown=auser:agroup /app/target/release/pzzld /usr/local/bin/pzzld
# copy the configuration files
COPY --from=builder --chown=auser:agroup --chmod=755 --link /app/.config /opt/pzzld/.config
COPY --from=builder --chown=auser:agroup --chmod=755 --link /app/*.config.toml* /opt/pzzld/.config/*.config.toml*
COPY --from=builder --chown=auser:agroup --chmod=755 --link /app/Puzzled.toml* /opt/pzzld/.config/Puzzled.toml*
# set the permissions
RUN chmod +x /usr/local/bin/pzzld && \
chmod +x /opt/pzzld/.config && \
chown auser /usr/local/bin/pzzld && \
chown -R auser /opt/pzzld
FROM runner-base AS runner
# Set the environment variables
ENV APP_MODE=release \
HOSTNAME="0.0.0.0" \
HOSTPORT=8080 \
PZZLD_CONFIG="/opt/pzzld/.config" \
RUST_LOG=trace
# set the working directory
WORKDIR /opt/pzzld
# expose the port
EXPOSE ${HOSTPORT}
# set the entrypoint
ENTRYPOINT ["bcr"]