Source code for my personal quote bot project.
at rust 2.4 kB view raw
1# syntax=docker/dockerfile:1 2 3# Comments are provided throughout this file to help you get started. 4# If you need more help, visit the Dockerfile reference guide at 5# https://docs.docker.com/reference/dockerfile/ 6 7################################################################################ 8# Create a stage for building the application. 9 10ARG RUST_VERSION=1.85.0 11ARG APP_NAME=audquotes 12FROM rust:${RUST_VERSION}-bullseye AS build 13WORKDIR /app 14 15# Build the application. 16# Leverage a cache mount to /usr/local/cargo/registry/ 17# for downloaded dependencies and a cache mount to /app/target/ for 18# compiled dependencies which will speed up subsequent builds. 19# Leverage a bind mount to the src directory to avoid having to copy the 20# source code into the container. Once built, copy the executable to an 21# output directory before the cache mounted /app/target is unmounted. 22RUN --mount=type=bind,source=src,target=src \ 23 --mount=type=bind,source=quotes,target=quotes \ 24 --mount=type=bind,source=Cargo.toml,target=Cargo.toml \ 25 --mount=type=bind,source=Cargo.lock,target=Cargo.lock \ 26 --mount=type=cache,target=/app/target/ \ 27 --mount=type=cache,target=/usr/local/cargo/registry/ \ 28 <<EOF 29set -e 30cargo build --locked --release 31cp ./target/release/audquotes /bin/server 32cp -r ./quotes /bin/quotes 33EOF 34 35################################################################################ 36# Create a new stage for running the application that contains the minimal 37# runtime dependencies for the application. This often uses a different base 38# image from the build stage where the necessary files are copied from the build 39# stage. 40# 41# The example below uses the debian bullseye image as the foundation for running the app. 42# By specifying the "bullseye-slim" tag, it will also use whatever happens to be the 43# most recent version of that tag when you build your Dockerfile. If 44# reproducibility is important, consider using a digest 45# (e.g., debian@sha256:ac707220fbd7b67fc19b112cee8170b41a9e97f703f588b2cdbbcdcecdd8af57). 46FROM debian:bullseye AS final 47 48RUN apt update && apt upgrade -y && apt install -y openssl ca-certificates 49 50# Copy the executable from the "build" stage. 51COPY --from=build /bin/server /bin/ 52COPY --from=build /bin/quotes /quotes 53 54# Expose the port that the application listens on. 55EXPOSE 8080 56 57# What the container should run when it is started. 58CMD ["/bin/server"]