From fdfc20815c3f8c10d63fa953207038b71795289c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=BF=98=E5=BF=A7=E5=8C=97=E8=90=B1=E8=8D=89?= Date: Fri, 1 Sep 2023 16:59:37 +0800 Subject: [PATCH] feat: docker support --- .dockerignore | 2 ++ Dockerfile | 10 ++++++++++ docker-compose.yml | 8 ++++++++ flake.nix | 18 ++++++++---------- 4 files changed, 28 insertions(+), 10 deletions(-) create mode 100644 .dockerignore create mode 100644 Dockerfile create mode 100644 docker-compose.yml diff --git a/.dockerignore b/.dockerignore new file mode 100644 index 0000000..2c4918c --- /dev/null +++ b/.dockerignore @@ -0,0 +1,2 @@ +/target +*.db diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..23dfbd3 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,10 @@ +FROM rust:1.72-alpine as builder +RUN apk add --no-cache musl-dev +WORKDIR /usr/src/app +COPY . . +RUN cargo install --path . --target x86_64-unknown-linux-musl + +FROM alpine:latest +WORKDIR /guoql +COPY --from=builder /usr/local/cargo/bin/guoql /guoql/guoql +CMD ["./guoql", "./guoql.db", "--host", "0.0.0.0"] diff --git a/docker-compose.yml b/docker-compose.yml new file mode 100644 index 0000000..7903f32 --- /dev/null +++ b/docker-compose.yml @@ -0,0 +1,8 @@ +version: "3" +services: + guoql: + build: . + ports: + - "8080:8080" + volumes: + - ./guoql.db:/guoql/guoql.db diff --git a/flake.nix b/flake.nix index 8b42e84..f656b51 100644 --- a/flake.nix +++ b/flake.nix @@ -29,10 +29,13 @@ fenixPkgs = fenix.packages.${system}; pkgs = nixpkgs.legacyPackages.${system}; - toolchain = fenixPkgs.stable.withComponents [ - "cargo" - "clippy" - "rustc" + toolchain = fenixPkgs.combine [ + fenixPkgs.stable.cargo + fenixPkgs.stable.clippy + fenixPkgs.stable.rustc + fenixPkgs.stable.rustfmt + fenixPkgs.stable.rust-std + fenixPkgs.targets.x86_64-unknown-linux-musl.stable.rust-std ]; craneLib = crane.lib.${system}.overrideToolchain toolchain; in @@ -60,12 +63,7 @@ devShells.default = pkgs.mkShell { packages = [ - (fenixPkgs.complete.withComponents [ - "cargo" - "clippy" - "rustc" - "rustfmt" - ]) + toolchain fenixPkgs.rust-analyzer pkgs.cargo-expand pkgs.cargo-bloat