From 02fd42bb72ccbeff3326cd9d95c2fa56c8565a54 Mon Sep 17 00:00:00 2001 From: Garen Tyler Date: Tue, 3 Dec 2024 23:21:35 -0700 Subject: [PATCH] Add dockerfile and docker-bake configs --- Cargo.toml | 2 +- Dockerfile | 38 ++++++++++++++++++++++++++++++++++++++ docker-bake.hcl | 7 +++++++ docker-compose.yml | 15 +++++++++++++++ 4 files changed, 61 insertions(+), 1 deletion(-) create mode 100644 Dockerfile create mode 100644 docker-bake.hcl create mode 100644 docker-compose.yml diff --git a/Cargo.toml b/Cargo.toml index 6641554..cc806f4 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -7,7 +7,7 @@ authors = ["Garen Tyler "] repository = "https://github.com/garentyler/composition" readme = "README.md" license = "MIT" -edition = "2024" +edition = "2021" [[bin]] name = "composition" diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..2330deb --- /dev/null +++ b/Dockerfile @@ -0,0 +1,38 @@ +FROM rust:1.83.0-alpine3.20 AS base +RUN apk add --no-cache musl-dev=1.2.5-r0 git=2.45.2-r0 +RUN cargo install cargo-chef --locked --version 0.1.68 +WORKDIR /app +RUN git config --global --add safe.directory /app + +FROM base AS dev +RUN cargo install cargo-watch --locked --version 8.5.3 +VOLUME /app +VOLUME /app/.git +EXPOSE 25565 +CMD ["cargo", "watch", "-x", "run"] + +FROM base AS planner +COPY Cargo.toml . +COPY Cargo.lock . +RUN cargo chef prepare --recipe-path recipe.json + +FROM base AS builder +COPY --from=planner /app/recipe.json recipe.json +RUN cargo chef cook --release --recipe-path recipe.json +COPY src src +COPY build.rs . +COPY Cargo.toml . +COPY Cargo.lock . +COPY .git .git +RUN cargo build --release +RUN strip target/release/composition + +FROM alpine:3.20 AS prod +RUN apk add --no-cache tini=0.19.0-r3 +RUN addgroup --gid 10001 --system composition && adduser --uid 10000 --system --ingroup composition --home /app composition +VOLUME /app/data +WORKDIR /app/data +COPY --from=builder /app/target/release/composition /app +EXPOSE 25565 +USER composition +ENTRYPOINT ["tini", "--", "/app/composition"] diff --git a/docker-bake.hcl b/docker-bake.hcl new file mode 100644 index 0000000..258a31b --- /dev/null +++ b/docker-bake.hcl @@ -0,0 +1,7 @@ +target "default" { + context = "." + dockerfile = "Dockerfile" + tags = ["composition:latest", "garentyler/composition:latest"] + platforms = ["linux/amd64", "linux/arm64"] + target = "prod" +} \ No newline at end of file diff --git a/docker-compose.yml b/docker-compose.yml new file mode 100644 index 0000000..026ead5 --- /dev/null +++ b/docker-compose.yml @@ -0,0 +1,15 @@ +# This file is only meant to provide a simple dev environment. +# For prod images, look at docker-bake.hcl. +services: + server: + container_name: composition + restart: unless-stopped + build: + context: . + dockerfile: Dockerfile + target: dev + ports: + - "25565:25565" + volumes: + - .:/app + - .git:/app/.git