From 9714533ef1c4b768056c9e6f3e189d7122d7265f Mon Sep 17 00:00:00 2001 From: Lennart <18233294+lennart-k@users.noreply.github.com> Date: Thu, 31 Oct 2024 17:10:07 +0100 Subject: [PATCH] Add Dockerfile --- .dockerignore | 16 ++++++++++++++++ Dockerfile | 28 ++++++++++++++++++++++++++++ README.md | 2 +- 3 files changed, 45 insertions(+), 1 deletion(-) create mode 100644 .dockerignore create mode 100644 Dockerfile diff --git a/.dockerignore b/.dockerignore new file mode 100644 index 0000000..b9491a8 --- /dev/null +++ b/.dockerignore @@ -0,0 +1,16 @@ +target +crates/*/target +# For libraries ignore Cargo.lock +crates/*/Cargo.lock + +db.toml +db.sqlite3* +config.toml +schema.sql + +/.idea + +.env + +**/node_modules +**/dist diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..62d46d3 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,28 @@ +FROM node:23-slim AS frontend-builder +RUN corepack enable +WORKDIR /frontend +COPY crates/frontend/frontend/package.json /frontend/package.json +RUN pnpm install +COPY crates/frontend/frontend /frontend +RUN pnpm build +# Templates will be in /frontend/dist/templates +# Assets will be in /frontend/dist/assets + + +FROM rust:1.82-alpine AS builder +# We need to statically link C dependencies like sqlite, otherwise we get +# exec /usr/local/bin/rustical: no such file or directory +# x86_64-unknown-linux-musl does static linking by default +RUN apk add --no-progress build-base; \ + rustup target add x86_64-unknown-linux-musl +WORKDIR /rustical +COPY . . +COPY --from=frontend-builder /frontend/dist crates/frontend/frontend/dist +RUN --mount=type=cache,target=target cargo install --target x86_64-unknown-linux-musl --path . + +FROM scratch +COPY --from=builder /usr/local/cargo/bin/rustical /usr/local/bin/rustical +CMD ["/usr/local/bin/rustical"] + +LABEL org.opencontainers.image.authors="Lennart K github.com/lennart-k" +EXPOSE 4000 diff --git a/README.md b/README.md index 9fd3983..a1c6fdb 100644 --- a/README.md +++ b/README.md @@ -30,7 +30,7 @@ a calendar server - [ ] Restore endpoint - [ ] Packaging - [x] Ensure cargo install works - - [ ] Docker image + - [x] Docker image - [ ] Releases - [ ] Locking - [ ] Testing such that I'm confident enough to use it myself :)