about summary refs log tree commit diff stats
diff options
context:
space:
mode:
authorAlan Pearce2024-04-21 18:46:12 +0200
committerAlan Pearce2024-04-21 20:48:34 +0200
commitf334fc8d4caed2663ef3008f43d2f2fc48e3eaa9 (patch)
treef0942e920e8a2e4161f0a8dad3a15b9a7aff6d08
parent2c6722bd18097cdcbed23d526ace0b751caf324a (diff)
downloadwebsite-f334fc8d4caed2663ef3008f43d2f2fc48e3eaa9.tar.lz
website-f334fc8d4caed2663ef3008f43d2f2fc48e3eaa9.tar.zst
website-f334fc8d4caed2663ef3008f43d2f2fc48e3eaa9.zip
use justfile for scripting
-rw-r--r--flake.nix20
-rwxr-xr-xjustfile57
-rw-r--r--nix/scripts.nix55
3 files changed, 64 insertions, 68 deletions
diff --git a/flake.nix b/flake.nix
index 5416016..78fe189 100644
--- a/flake.nix
+++ b/flake.nix
@@ -24,18 +24,17 @@
           packages = import ./nix/default.nix {
             inherit pkgs self;
           };
+          commonShellPackages = with pkgs; [
+            just
+            skopeo
+            flyctl
+          ];
         in
         {
           inherit packages;
           devShells = {
             ci = pkgs.mkShell {
-              packages = with pkgs; [
-                skopeo
-                flyctl
-              ]
-              ++ (import ./nix/scripts.nix {
-                inherit pkgs;
-              });
+              packages = commonShellPackages;
             };
             default = pkgs.mkShell {
               inputsFrom = [ packages.builder ];
@@ -45,13 +44,8 @@
                 go-tools
                 gomod2nix.packages.${system}.default
                 gci
-                skopeo
                 netlify-cli
-                flyctl
-              ]
-              ++ (import ./nix/scripts.nix {
-                inherit pkgs;
-              });
+              ] ++ commonShellPackages;
             };
           };
         });
diff --git a/justfile b/justfile
new file mode 100755
index 0000000..3ebc592
--- /dev/null
+++ b/justfile
@@ -0,0 +1,57 @@
+#! /usr/bin/env -S nix develop . --command just --justfile
+
+fly-system := "x86_64-linux"
+fly-registry := "registry.fly.io/alanpearce-eu"
+docker-tag := env_var_or_default("DOCKER_TAG", `git rev-parse HEAD`)
+
+default:
+    @just --list --justfile {{ justfile() }} --unsorted
+
+check:
+    nix flake check . --print-build-logs
+
+check-licenses:
+    nix run nixpkgs#go-licenses
+
+update-all:
+    go get -u all
+    gomod2nix --outdir nix
+    nix flake update
+
+watch-flake command:
+    watchexec --restart -w flake.nix -w flake.lock direnv exec . {{ command }}
+
+watch-builder: (watch-flake "watchexec -i cmd/server -i public -r go run ./cmd/build")
+
+nix-build what:
+    nix build .#{{ what }}
+
+watch-server: (watch-flake "watchexec -r go run ./cmd/server")
+
+docker-stream system=(arch() + "-linux"):
+    @nix build --print-out-paths .#docker-stream-{{ system }} | sh
+
+docker-image system=(arch() + "-linux"):
+    nix build .#docker-image-{{ system }}
+
+docker-stream-fly:
+    just docker-stream fly-system
+
+docker-image-fly: (docker-image fly-system)
+
+docker-inspect image-path="result" *skopeo-flags="":
+    skopeo {{ skopeo-flags }} inspect docker-archive:{{ image-path }}
+
+print-docker-tag:
+    @echo {{ docker-tag }}
+
+# docker://some_docker_registry/myimage:tag
+stream-to-registry registry-and-tag=(fly-registry + ":" + docker-tag) *skopeo-flags="":
+    just docker-stream-fly | gzip --fast | skopeo {{ skopeo-flags }} copy docker-archive:/dev/stdin {{ registry-and-tag }}
+
+# docker://some_docker_registry/myimage:tag
+push-to-registry registry-and-tag=(fly-registry + ":" + docker-tag) image-path=`readlink -f result` *skopeo-flags="":
+    skopeo {{ skopeo-flags }} copy {{ registry-and-tag }} {{ registry-and-tag }}
+
+deploy registry-and-tag=(fly-registry + ":" + docker-tag):
+    fly deploy --image {{ registry-and-tag }}
diff --git a/nix/scripts.nix b/nix/scripts.nix
deleted file mode 100644
index e097648..0000000
--- a/nix/scripts.nix
+++ /dev/null
@@ -1,55 +0,0 @@
-{ pkgs ? import <nixpkgs> { }, ... }:
-let
-  watchFlake = with pkgs; ''
-    ${watchexec}/bin/watchexec --restart \
-     --watch flake.nix \
-     --watch flake.lock \
-  '';
-  imageName = (builtins.fromTOML (builtins.readFile ../fly.toml)).build.image;
-  nonDarwinSystem = builtins.replaceStrings [ "darwin" ] [ "linux" ] pkgs.stdenv.system;
-  flySystem = "x86_64-linux";
-  mkAttr = type: system: ".#docker-${type}-${system}";
-  sh = (pkgs.lib.optionalString pkgs.stdenv.isDarwin "ssh linux-builder ")
-    + "sh";
-  stream = system: "nix build --print-out-paths ${(mkAttr "stream") system} | ${sh}";
-  image = system: "nix build ${(mkAttr "image") system}";
-in
-with pkgs; [
-  (writeShellScriptBin "watch-builder" ''
-    ${watchFlake} "direnv exec . watchexec -i cmd/server -i public -r go run ./cmd/build $@"
-  '')
-  (writeShellScriptBin "watch-server" ''
-    ${watchFlake} "direnv exec . watchexec -r go run ./cmd/server $@"
-  '')
-  (writeShellScriptBin "check-licenses" ''
-    ${go-licenses}/bin/go-licenses check --include_tests ./... --disallowed_types=restricted,forbidden
-  '')
-  (writeShellScriptBin "stream" "${stream nonDarwinSystem}")
-  (writeShellScriptBin "stream-fly" "${stream flySystem}")
-  (writeShellScriptBin "image" "${image nonDarwinSystem}")
-  (writeShellScriptBin "image-fly" "${image flySystem}")
-  (writeShellScriptBin "load-locally" ''
-    stream | ${docker-client}/bin/docker load "$@"
-  '')
-  (writeShellScriptBin "push-to-registry" ''
-    if test -z "''${1:-}"; then
-    cat <<-EOF
-        USAGE: $0 <docker-url> [skopeo-copy-options]
-
-        Example: $0 docker://some_docker_registry/myimage:tag
-
-        See: https://github.com/containers/skopeo/blob/main/docs/skopeo-copy.1.md
-    EOF
-      exit 1
-    fi
-    echo skopeo copy docker-archive:/dev/stdin "$@"
-    stream fly | ${gzip}/bin/gzip --fast | ${skopeo}/bin/skopeo copy docker-archive:/dev/stdin "$@"
-  '')
-  (writeShellScriptBin "deploy" ''
-    set -eu
-    TAG=$(git rev-parse HEAD)
-    IMAGE=${imageName}:$TAG
-    push-to-registry docker://$IMAGE
-    ${pkgs.flyctl}/bin/flyctl deploy --image $IMAGE
-  '')
-]