From 5a0277d1cef2b288b9a7c8e0a7f9f39f20e3ba93 Mon Sep 17 00:00:00 2001 From: holly sparkles Date: Tue, 10 Oct 2023 22:04:54 +0200 Subject: [PATCH] feat: add docker support --- Dockerfile | 14 ++++++++++++++ README.md | 10 ++++++++++ docker-compose.yml | 11 +++++++++++ 3 files changed, 35 insertions(+) create mode 100644 Dockerfile create mode 100644 docker-compose.yml diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..7de70a4 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,14 @@ +FROM rust:1.73-slim AS builder + +RUN apt-get update && apt-get install -y libssl-dev pkg-config + +COPY . /sources +WORKDIR /sources +RUN rustup target add x86_64-unknown-linux-musl +RUN cargo build --target x86_64-unknown-linux-musl --release + +FROM alpine:3.16 +COPY --from=builder /sources/target/x86_64-unknown-linux-musl/release/license-api-rs /lapi + +EXPOSE 8080 +ENTRYPOINT ["/lapi"] diff --git a/README.md b/README.md index 07ed65a..b1b8e89 100644 --- a/README.md +++ b/README.md @@ -33,6 +33,16 @@ export LICENSE_API_WELCOME_MESSAGE="/path/to/welcome.txt" All environment variables except for `LICENSE_API_DATABASE` are optional. If `LICENSE_API_DATABASE` is not set, the server will refuse to start. +## Docker + +This project has first-class Docker support. I prefer to not pull my images from a repository, as that leaves one vulnerable to supply chain attacks. To build the Docker image, simply run `docker build -t lapi:latest .` in the repository directory. + +I am using [Alpine](https://hub.docker.com/_/alpine/) as a base image, and the application is built using the `x86_64-unknown-linux-musl` [build target](https://blog.rust-lang.org/2023/05/09/Updating-musl-targets.html). + +A sample `docker-compose.yml` file is also included. + +On my home server, this service uses 964 KB of RAM with my license database, so it is lightweight. + ## License - [AGPL 3.0](LICENSE) diff --git a/docker-compose.yml b/docker-compose.yml new file mode 100644 index 0000000..7695b4a --- /dev/null +++ b/docker-compose.yml @@ -0,0 +1,11 @@ +version: '3' +services: + lapi: + image: lapi:latest + volumes: + - /path/to/my/data/:/config + environment: + - LICENSE_API_DATABASE=/config/licenses/database.yml + ports: + - 3535:8080 + restart: unless-stopped -- libgit2 1.7.2