From 03b3f692e1269797e5c140380bdf49e8b89f0b01 Mon Sep 17 00:00:00 2001 From: Jef Roosens Date: Fri, 10 Jan 2025 13:22:33 +0100 Subject: [PATCH] chore: add Dockerfile --- .dockerignore | 5 +++++ Cargo.lock | 1 + Cargo.toml | 6 +++++- Dockerfile | 43 +++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 54 insertions(+), 1 deletion(-) create mode 100644 .dockerignore create mode 100644 Dockerfile diff --git a/.dockerignore b/.dockerignore new file mode 100644 index 0000000..d06bf53 --- /dev/null +++ b/.dockerignore @@ -0,0 +1,5 @@ +* + +!Cargo.toml +!Cargo.lock +!src/** diff --git a/Cargo.lock b/Cargo.lock index eb41036..65794d1 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -703,6 +703,7 @@ version = "0.30.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "2e99fb7a497b1e3339bc746195567ed8d3e24945ecd636e3619d20b9de9e9149" dependencies = [ + "cc", "pkg-config", "vcpkg", ] diff --git a/Cargo.toml b/Cargo.toml index 5fe517e..18a921c 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -3,6 +3,10 @@ name = "calathea" version = "0.1.0" edition = "2021" +[[bin]] +path = "src/main.rs" +name = "calathea" + [dependencies] axum = { version = "0.7.9", features = ["macros"] } chrono = { version = "0.4.39", features = ["serde"] } @@ -10,7 +14,7 @@ r2d2 = "0.8.10" r2d2_sqlite = "0.25.0" # this dependency is needed soly because the r2d2_sqlite crate doesn't export # the 'chrono' feature flag -rusqlite = { version = "0.32.1", features = ["chrono"] } +rusqlite = { version = "0.32.1", features = ["chrono", "bundled"] } serde = { version = "1.0.217", features = ["derive"] } tera = "1.20.0" tokio = { version = "1.42.0", features = ["full"] } diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..ce6a9ee --- /dev/null +++ b/Dockerfile @@ -0,0 +1,43 @@ +FROM rust:1.83-alpine3.21 AS builder + +ARG DI_VER=1.2.5 + +WORKDIR /app + +RUN apk update && apk add --no-cache build-base + +# Build dumb-init +RUN wget -O - "https://github.com/Yelp/dumb-init/archive/refs/tags/v${DI_VER}.tar.gz" | tar -xzf - && \ + cd "dumb-init-${DI_VER}" && \ + make SHELL=/bin/sh && \ + mv dumb-init .. && \ + cd .. + +COPY Cargo.toml Cargo.lock ./ + +RUN cargo fetch --locked + +COPY . ./ + +RUN cargo build --release --frozen + + +FROM alpine:3.21 + +COPY --from=builder /app/target/release/calathea /bin/calathea +COPY --from=builder /app/dumb-init /bin/dumb-init + +# Create a non-root user & make sure it can write to the data directory +RUN set -x && \ + adduser -u 82 -D -S -G www-data www-data && \ + mkdir /data && \ + chown -R www-data:www-data /data + +WORKDIR /data + +USER www-data:www-data + +ENTRYPOINT [ "/bin/dumb-init", "--" ] +CMD [ "/bin/calathea" ] + +