From d7f056f77e5de1c81a176d3fd51307b3d77ed3f2 Mon Sep 17 00:00:00 2001 From: Sebastian Hugentobler Date: Fri, 10 May 2024 17:09:07 +0200 Subject: [PATCH] add containerfile --- .containerignore | 2 ++ Containerfile | 22 ++++++++++++++++++++++ README.md | 4 ++-- 3 files changed, 26 insertions(+), 2 deletions(-) create mode 100644 .containerignore create mode 100644 Containerfile diff --git a/.containerignore b/.containerignore new file mode 100644 index 0000000..5fda93c --- /dev/null +++ b/.containerignore @@ -0,0 +1,2 @@ +/target +Containerfile diff --git a/Containerfile b/Containerfile new file mode 100644 index 0000000..6bb9360 --- /dev/null +++ b/Containerfile @@ -0,0 +1,22 @@ +FROM docker.io/rust:1-alpine3.19 AS builder + +RUN apk --no-cache add musl-dev + +ENV CARGO_CARGO_NEW_VCS="none" +ENV CARGO_BUILD_RUSTFLAGS="-C target-feature=+crt-static" + +WORKDIR /work + +COPY . . + +RUN cargo build --release --target=$(arch)-unknown-linux-musl +RUN cp "./target/$(arch)-unknown-linux-musl/release/rusty-library" /app + + +FROM scratch + +COPY --from=builder /app /app +CMD ["/app", "--", "/library"] + +VOLUME ["/library"] +EXPOSE 3000 diff --git a/README.md b/README.md index 6f8f9b0..6a7aed0 100644 --- a/README.md +++ b/README.md @@ -17,8 +17,8 @@ do but luckily enough it is the part I need for myself. ## Nix A [nix](https://nixos.org/download/) environment with enabled -[nix-commands](https://nixos.org/manual/nix/stable/contributing/experimental-features#xp-feature-nix-command) -in order to use `nix develop` and `nix build`. +[nix-commands](https://nixos.wiki/wiki/Flakes) in order to use `nix develop` and +`nix build`. A statically linked binary for linux systems (using [musl](https://musl.libc.org/)) can be compiled by running `nix build` (run