build docker via nix

This commit is contained in:
Dmitriy Pleshevskiy 2022-09-18 23:34:38 +03:00
parent 21e9e89de2
commit ac3f245a1c
Signed by: pleshevskiy
GPG key ID: 1B59187B161C0215
3 changed files with 35 additions and 49 deletions

View file

@ -1,4 +0,0 @@
/target
.env*
!.envrc

View file

@ -1,22 +0,0 @@
FROM rust:1.62.0-slim-buster
WORKDIR /app
RUN cargo init .
COPY Cargo.* ./
RUN cargo build --release \
&& rm -rf src
COPY ./src ./src
RUN cargo install --bin vnetod --path . \
&& rm -rf ./src Cargo.*
VOLUME ["/data"]
WORKDIR /data
ENTRYPOINT ["/usr/local/cargo/bin/vnetod"]

View file

@ -10,34 +10,46 @@
version = "${cargoToml.package.version}_${builtins.substring 0 8 self.lastModifiedDate}_${self.shortRev or "dirty"}"; version = "${cargoToml.package.version}_${builtins.substring 0 8 self.lastModifiedDate}_${self.shortRev or "dirty"}";
in in
utils.lib.eachDefaultSystem utils.lib.eachDefaultSystem (system:
(system: let
let inherit (nixpkgs) lib;
inherit (nixpkgs) lib; pkgs = import nixpkgs { inherit system; };
pkgs = import nixpkgs { inherit system; };
vnetod = pkgs.rustPlatform.buildRustPackage { vnetod = pkgs.rustPlatform.buildRustPackage {
name = "vnetod-${version}"; name = "vnetod-${version}";
src = lib.cleanSource ./.; src = lib.cleanSource ./.;
cargoLock.lockFile = ./Cargo.lock; cargoLock.lockFile = ./Cargo.lock;
doCheck = true; doCheck = true;
}; };
in
{ docker = pkgs.dockerTools.buildLayeredImage {
apps.default = { name = "pleshevskiy/vnetod";
type = "app"; tag = cargoToml.package.version;
program = "${vnetod}/bin/vnetod"; config = {
Volumes."/data" = { };
WorkingDir = "/data";
Entrypoint = [ "${vnetod}/bin/vnetod" ];
}; };
};
in
{
apps.default = {
type = "app";
program = "${vnetod}/bin/vnetod";
};
packages.default = vnetod; packages = {
inherit docker;
default = vnetod;
};
devShell = pkgs.mkShell { devShell = pkgs.mkShell {
packages = with pkgs; [ cargo rustc rustfmt clippy rust-analyzer ]; packages = with pkgs; [ cargo rustc rustfmt clippy rust-analyzer ];
RUST_SRC_PATH = pkgs.rustPlatform.rustLibSrc; RUST_SRC_PATH = pkgs.rustPlatform.rustLibSrc;
}; };
overlays = f: p: { inherit vnetod; }; overlays = f: p: { inherit vnetod; };
}); });
} }