feat(Nix): change build paths and add Docker images
This commit is contained in:
@@ -47,22 +47,21 @@
|
||||
triple = "aarch64-unknown-linux-gnu";
|
||||
};
|
||||
};
|
||||
mkRustBuild = import ./nix/backend.nix;
|
||||
rustBuilds = import ./nix/backend.nix;
|
||||
packages = {
|
||||
linux-x86_64 = mkRustBuild targets.linux-x86_64;
|
||||
linux-aarch64 = mkRustBuild targets.linux-aarch64;
|
||||
x86_64 = rustBuilds targets.linux-x86_64;
|
||||
aarch64 = rustBuilds targets.linux-aarch64;
|
||||
};
|
||||
defaultBySystem = {
|
||||
"x86_64-linux" = packages.linux-x86_64;
|
||||
"aarch64-linux" = packages.linux-aarch64;
|
||||
x86_64-linux = packages.x86_64;
|
||||
aarch64-linux = packages.aarch64;
|
||||
};
|
||||
in {
|
||||
formatter = alejandra.defaultPackage.${system};
|
||||
packages.backend =
|
||||
packages
|
||||
// {
|
||||
default = defaultBySystem.${system} or packages.linux-x86_64;
|
||||
};
|
||||
packages = {
|
||||
backend = packages;
|
||||
default = defaultBySystem.${system}.backend or packages.x86_64.backend;
|
||||
};
|
||||
devShell = import ./nix/shell.nix {inherit pkgs rustVersion;};
|
||||
}
|
||||
);
|
||||
|
||||
+55
-16
@@ -1,19 +1,5 @@
|
||||
target: let
|
||||
cargoToml = fromTOML (builtins.readFile ../backend/Cargo.toml);
|
||||
inherit (cargoToml.package) name version;
|
||||
pkgs = target.crossPkgs;
|
||||
buildArgs = {
|
||||
pname = name;
|
||||
inherit version;
|
||||
src = pkgs.lib.cleanSource ../.;
|
||||
# cargoLock.lockFile = ../Cargo.lock;
|
||||
cargoVendorDir = "vendor";
|
||||
useNextest = true;
|
||||
meta = {
|
||||
inherit (cargoToml.package) description homepage;
|
||||
};
|
||||
postBuild = "${pkgs.upx}/bin/upx target/*/release/*${name}";
|
||||
};
|
||||
rustVersion = pkgs.rust-bin.stable.latest.default.override {
|
||||
targets = [target.triple];
|
||||
};
|
||||
@@ -21,5 +7,58 @@ target: let
|
||||
cargo = rustVersion;
|
||||
rustc = rustVersion;
|
||||
};
|
||||
in
|
||||
rustPlatform.buildRustPackage buildArgs
|
||||
cargoToml = fromTOML (builtins.readFile ../backend/Cargo.toml);
|
||||
inherit (cargoToml.package) name version;
|
||||
rustBuild = rustPlatform.buildRustPackage {
|
||||
pname = name;
|
||||
inherit version;
|
||||
src = pkgs.lib.cleanSource ../.;
|
||||
cargoLock.lockFile = ../Cargo.lock;
|
||||
# cargoVendorDir = "vendor";
|
||||
useNextest = true;
|
||||
meta = {
|
||||
inherit (cargoToml.package) description homepage;
|
||||
};
|
||||
};
|
||||
settingsDir = pkgs.runCommand "settings" {} ''
|
||||
mkdir -p $out/settings
|
||||
cp ${../backend/settings}/*.yaml $out/settings/
|
||||
'';
|
||||
makeDockerImage = tag:
|
||||
pkgs.dockerTools.buildLayeredImage {
|
||||
name = "phundrak/${name}";
|
||||
contents = [rustBuild pkgs.cacert settingsDir];
|
||||
config = {
|
||||
name = "phundrak/${name}";
|
||||
inherit tag;
|
||||
created = "now";
|
||||
};
|
||||
config = {
|
||||
Entrypoint = ["${rustBuild}/bin/${name}"];
|
||||
WorkingDir = "/";
|
||||
Env = [
|
||||
"SSL_CERT_FILE=${pkgs.cacert}/etc/ssl/certs/ca-bundle.crt"
|
||||
];
|
||||
ExposedPorts = {
|
||||
"3100/tcp" = {};
|
||||
};
|
||||
Labels = {
|
||||
"org.opencontainers.image.title" = name;
|
||||
"org.opencontainers.image.version" = version;
|
||||
"org.opencontainers.image.description" = "REST API backend for STA";
|
||||
"org.opencontainers.image.authors" = "Lucien Cartier-Tilet <lucien@phundrak.com>";
|
||||
"org.opencontainers.image.licenses" = "AGPL-3.0-only";
|
||||
"org.opencontainers.image.source" = "https://labs.phundrak.com/phundrak/sta";
|
||||
"org.opencontainers.image.url" = "https://labs.phundrak.com/phundrak/sta";
|
||||
"org.opencontainers.image.documentation" = "https://labs.phundrak.com/phundrak/sta";
|
||||
"org.opencontainers.image.vendor" = "Phundrak";
|
||||
};
|
||||
};
|
||||
};
|
||||
in {
|
||||
backend = rustBuild;
|
||||
docker = {
|
||||
default = makeDockerImage version;
|
||||
latest = makeDockerImage "latest";
|
||||
};
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user