Source code for my personal quote bot project.

Updated dockerfile to use new Rust code.

+84 -26
+48 -26
Dockerfile
··· 1 - # The following Dockerfile code has been taken from the uv documentation 2 - # and adapted to suit my program: https://docs.astral.sh/uv/guides/integration/docker/ 1 + # syntax=docker/dockerfile:1 3 2 4 - # Use a Python image with uv pre-installed 5 - FROM ghcr.io/astral-sh/uv:python3.13-bookworm-slim 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. 6 9 7 - # Install the project into `/app` 10 + ARG RUST_VERSION=1.85.0 11 + ARG APP_NAME=audquotes 12 + FROM rust:${RUST_VERSION}-bullseye AS build 8 13 WORKDIR /app 9 14 10 - # Enable bytecode compilation 11 - ENV UV_COMPILE_BYTECODE=1 12 - 13 - # Copy from the cache instead of linking since it's a mounted volume 14 - ENV UV_LINK_MODE=copy 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. 22 + RUN --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 29 + set -e 30 + cargo build --locked --release 31 + cp ./target/release/audquotes /bin/server 32 + cp -r ./quotes /bin/quotes 33 + EOF 15 34 16 - # Install the project's dependencies using the lockfile and settings 17 - RUN --mount=type=cache,target=/root/.cache/uv \ 18 - --mount=type=bind,source=uv.lock,target=uv.lock \ 19 - --mount=type=bind,source=pyproject.toml,target=pyproject.toml \ 20 - uv sync --frozen --no-install-project --no-dev 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). 46 + FROM debian:bullseye AS final 21 47 22 - # Then, add the rest of the project source code and install it 23 - # Installing separately from its dependencies allows optimal layer caching 24 - ADD . /app 25 - RUN --mount=type=cache,target=/root/.cache/uv \ 26 - uv sync --frozen --no-dev 48 + RUN apt update && apt upgrade -y && apt install -y openssl ca-certificates 27 49 28 - # Place executables in the environment at the front of the path 29 - ENV PATH="/app/.venv/bin:$PATH" 50 + # Copy the executable from the "build" stage. 51 + COPY --from=build /bin/server /bin/ 52 + COPY --from=build /bin/quotes /quotes 30 53 31 - # Make port 8080 available to the world outside this container 54 + # Expose the port that the application listens on. 32 55 EXPOSE 8080 33 56 34 - # Reset the entrypoint, don't invoke `uv` 35 - ENTRYPOINT [] 36 - CMD ["uv", "run", "schedule_script.py", "--no-simulation-mode"] 57 + # What the container should run when it is started. 58 + CMD ["/bin/server"]
+36
Dockerfile-python
··· 1 + # The following Dockerfile code has been taken from the uv documentation 2 + # and adapted to suit my program: https://docs.astral.sh/uv/guides/integration/docker/ 3 + 4 + # Use a Python image with uv pre-installed 5 + FROM ghcr.io/astral-sh/uv:python3.13-bookworm-slim 6 + 7 + # Install the project into `/app` 8 + WORKDIR /app 9 + 10 + # Enable bytecode compilation 11 + ENV UV_COMPILE_BYTECODE=1 12 + 13 + # Copy from the cache instead of linking since it's a mounted volume 14 + ENV UV_LINK_MODE=copy 15 + 16 + # Install the project's dependencies using the lockfile and settings 17 + RUN --mount=type=cache,target=/root/.cache/uv \ 18 + --mount=type=bind,source=uv.lock,target=uv.lock \ 19 + --mount=type=bind,source=pyproject.toml,target=pyproject.toml \ 20 + uv sync --frozen --no-install-project --no-dev 21 + 22 + # Then, add the rest of the project source code and install it 23 + # Installing separately from its dependencies allows optimal layer caching 24 + ADD . /app 25 + RUN --mount=type=cache,target=/root/.cache/uv \ 26 + uv sync --frozen --no-dev 27 + 28 + # Place executables in the environment at the front of the path 29 + ENV PATH="/app/.venv/bin:$PATH" 30 + 31 + # Make port 8080 available to the world outside this container 32 + EXPOSE 8080 33 + 34 + # Reset the entrypoint, don't invoke `uv` 35 + ENTRYPOINT [] 36 + CMD ["uv", "run", "schedule_script.py", "--no-simulation-mode"]