Rework nix + docker

pull/1/head
mat ess 2022-08-27 15:08:42 -04:00
parent e8a2567cef
commit d709014b31
6 changed files with 24 additions and 14 deletions

View File

@ -8,7 +8,7 @@ http://static-mat-services.fly.dev {
}
:8080 {
root * /var/www
root * {$SITE_ROOT}
encode gzip
file_server

View File

@ -17,10 +17,9 @@
systems = inputs.nixpkgs.lib.systems.flakeExposed;
perSystem = { config, self', inputs', pkgs, system, ... }:
let
inherit (pkgs) callPackage;
optimize-images = callPackage ./nix/optimize-images.nix { };
inherit (callPackage ./nix/fonts.nix { }) copyFonts linkFonts;
inherit (callPackage ./nix/theme.nix {
inherit (pkgs.callPackage ./nix { }) deploy docker fonts optimize-images themes;
inherit (fonts) copyFonts linkFonts;
inherit (themes {
theme = inputs.apollo;
themeEnabled = false;
}) copyTheme linkTheme;
@ -38,17 +37,19 @@
'';
installPhase = ''
cp -r public $out
cp Caddyfile $out
'';
};
devShells.default = with pkgs; mkShell {
packages = [ flyctl optimize-images zola ];
shellHook = linkTheme + linkFonts;
};
packages.docker = callPackage ./nix/docker.nix { site = self'.packages.default; };
packages.docker = docker {
caddyfile = builtins.readFile ./Caddyfile;
site = self'.packages.default;
};
apps.deploy.program =
let deploy = callPackage ./nix/deploy.nix { dockerImg = self'.packages.docker; };
in "${deploy}/bin/deploy";
let deploy' = deploy { dockerImage = self'.packages.docker; };
in "${deploy'}/bin/deploy";
};
};
}

7
nix/default.nix Normal file
View File

@ -0,0 +1,7 @@
{ callPackage }: {
deploy = { dockerImage }: callPackage ./deploy.nix { inherit dockerImage; };
docker = { caddyfile, site }: callPackage ./docker.nix { inherit caddyfile site; };
fonts = callPackage ./fonts.nix { };
optimize-images = callPackage ./optimize-images.nix { };
themes = { theme, themeEnabled }: callPackage ./themes.nix { inherit theme themeEnabled; };
}

View File

@ -1,9 +1,9 @@
{ lib, docker, flyctl, formats, writeShellScriptBin, dockerImg }:
{ lib, docker, flyctl, formats, writeShellScriptBin, dockerImage }:
writeShellScriptBin "deploy" ''
set -euxo pipefail
export PATH="${lib.makeBinPath [(docker.override { clientOnly = true; }) flyctl]}:$PATH"
archive=${dockerImg}
archive=${dockerImage}
image=$(docker load < $archive | awk '{ print $3; }')
flyctl deploy -i $image
''

View File

@ -1,11 +1,13 @@
{ dockerTools, caddy, site }:
{ dockerTools, caddy, caddyfile, site }:
dockerTools.buildLayeredImage {
name = site.pname;
tag = site.version;
contents = [ site caddy ];
config = {
Cmd = [ "${caddy}/bin/caddy" "run" "-config" "${site}/Caddyfile" ];
Cmd = [ "${caddy}/bin/caddy" "run" "-config" "${caddyfile}" ];
Env = [
"SITE_ROOT=${site}"
];
};
}