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 { :8080 {
root * /var/www root * {$SITE_ROOT}
encode gzip encode gzip
file_server file_server

View File

@ -17,10 +17,9 @@
systems = inputs.nixpkgs.lib.systems.flakeExposed; systems = inputs.nixpkgs.lib.systems.flakeExposed;
perSystem = { config, self', inputs', pkgs, system, ... }: perSystem = { config, self', inputs', pkgs, system, ... }:
let let
inherit (pkgs) callPackage; inherit (pkgs.callPackage ./nix { }) deploy docker fonts optimize-images themes;
optimize-images = callPackage ./nix/optimize-images.nix { }; inherit (fonts) copyFonts linkFonts;
inherit (callPackage ./nix/fonts.nix { }) copyFonts linkFonts; inherit (themes {
inherit (callPackage ./nix/theme.nix {
theme = inputs.apollo; theme = inputs.apollo;
themeEnabled = false; themeEnabled = false;
}) copyTheme linkTheme; }) copyTheme linkTheme;
@ -38,17 +37,19 @@
''; '';
installPhase = '' installPhase = ''
cp -r public $out cp -r public $out
cp Caddyfile $out
''; '';
}; };
devShells.default = with pkgs; mkShell { devShells.default = with pkgs; mkShell {
packages = [ flyctl optimize-images zola ]; packages = [ flyctl optimize-images zola ];
shellHook = linkTheme + linkFonts; 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 = apps.deploy.program =
let deploy = callPackage ./nix/deploy.nix { dockerImg = self'.packages.docker; }; let deploy' = deploy { dockerImage = self'.packages.docker; };
in "${deploy}/bin/deploy"; 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" '' writeShellScriptBin "deploy" ''
set -euxo pipefail set -euxo pipefail
export PATH="${lib.makeBinPath [(docker.override { clientOnly = true; }) flyctl]}:$PATH" export PATH="${lib.makeBinPath [(docker.override { clientOnly = true; }) flyctl]}:$PATH"
archive=${dockerImg} archive=${dockerImage}
image=$(docker load < $archive | awk '{ print $3; }') image=$(docker load < $archive | awk '{ print $3; }')
flyctl deploy -i $image flyctl deploy -i $image
'' ''

View File

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