Parallelize make deploy across languages
Split the deploy Nix app into a per-language invocation and let Make fan the five Cloudflare Pages pushes out in parallel via a --output-sync=target sub-make, instead of deploying them one at a time.
47c5f42 parent: 51380a7 modified
Makefile +10 -2 | @@ -7,6 +7,11 @@ include .env | ||
| 7 | 7 | export |
| 8 | 8 | endif |
| 9 | 9 | |
| 10 | +LANGS := en fr pt ja es | |
| 11 | + | |
| 12 | +# deploy-% targets aren't listed here: giving an instantiated pattern target | |
| 13 | +# (e.g. deploy-en) to .PHONY creates an explicit no-recipe rule for it, which | |
| 14 | +# then blocks the deploy-% pattern rule below from ever supplying a recipe. | |
| 10 | 15 | .PHONY: help dev build serve infra-plan infra-apply deploy clean |
| 11 | 16 | |
| 12 | 17 | help: |
| @@ -27,8 +32,11 @@ infra-plan: ## Show what infra-apply would change on Cloudflare | ||
| 27 | 32 | infra-apply: ## Apply infra/ changes to Cloudflare |
| 28 | 33 | nix run .#infra -- apply |
| 29 | 34 | |
| 30 | -deploy: ## Build the site and push it to Cloudflare Pages (all languages) | |
| 31 | - nix run .#deploy | |
| 35 | +deploy: build ## Build the site and push it to Cloudflare Pages (all languages, in parallel) | |
| 36 | + $(MAKE) --no-print-directory --output-sync=target -j$(words $(LANGS)) $(addprefix deploy-,$(LANGS)) | |
| 37 | + | |
| 38 | +deploy-%: ## Deploy a single language to Cloudflare Pages, e.g. `make deploy-en` (assumes `make build` already ran) | |
| 39 | + nix run .#deploy -- $* | |
| 32 | 40 | |
| 33 | 41 | clean: ## Remove build outputs |
| 34 | 42 | rm -rf result blog/public blog/resources |
| @@ -7,6 +7,11 @@ include .env | |||
| 7 | export | 7 | export |
| 8 | endif | 8 | endif |
| 9 | 9 | ||
| 10 | +LANGS := en fr pt ja es | ||
| 11 | + | ||
| 12 | +# deploy-% targets aren't listed here: giving an instantiated pattern target | ||
| 13 | +# (e.g. deploy-en) to .PHONY creates an explicit no-recipe rule for it, which | ||
| 14 | +# then blocks the deploy-% pattern rule below from ever supplying a recipe. | ||
| 10 | .PHONY: help dev build serve infra-plan infra-apply deploy clean | 15 | .PHONY: help dev build serve infra-plan infra-apply deploy clean |
| 11 | 16 | ||
| 12 | help: | 17 | help: |
| @@ -27,8 +32,11 @@ infra-plan: ## Show what infra-apply would change on Cloudflare | |||
| 27 | infra-apply: ## Apply infra/ changes to Cloudflare | 32 | infra-apply: ## Apply infra/ changes to Cloudflare |
| 28 | nix run .#infra -- apply | 33 | nix run .#infra -- apply |
| 29 | 34 | ||
| 30 | -deploy: ## Build the site and push it to Cloudflare Pages (all languages) | 35 | +deploy: build ## Build the site and push it to Cloudflare Pages (all languages, in parallel) |
| 31 | - nix run .#deploy | 36 | + $(MAKE) --no-print-directory --output-sync=target -j$(words $(LANGS)) $(addprefix deploy-,$(LANGS)) |
| 37 | + | ||
| 38 | +deploy-%: ## Deploy a single language to Cloudflare Pages, e.g. `make deploy-en` (assumes `make build` already ran) | ||
| 39 | + nix run .#deploy -- $* | ||
| 32 | 40 | ||
| 33 | clean: ## Remove build outputs | 41 | clean: ## Remove build outputs |
| 34 | rm -rf result blog/public blog/resources | 42 | rm -rf result blog/public blog/resources |
modified
flake.nix +10 -12 | @@ -77,24 +77,22 @@ | ||
| 77 | 77 | }}/bin/mykiwi-blog-infra"; |
| 78 | 78 | }; |
| 79 | 79 | |
| 80 | - # `nix run .#deploy` - builds the site (the same `packages.default` | |
| 81 | - # derivation `nix build` uses) and pushes each language's output | |
| 82 | - # folder to its matching Cloudflare Pages project. Needs | |
| 83 | - # CLOUDFLARE_API_TOKEN, same as `infra`. | |
| 80 | + # `nix run .#deploy -- <lang>` - pushes the already-built `./result/<lang>` | |
| 81 | + # folder (built separately via `make build` / `nix build`, the same | |
| 82 | + # `packages.default` derivation) to its matching Cloudflare Pages | |
| 83 | + # project. Needs CLOUDFLARE_API_TOKEN, same as `infra`. Takes a single | |
| 84 | + # language so the Makefile can fan out `make deploy` across languages | |
| 85 | + # in parallel via `make -j`. | |
| 84 | 86 | deploy = { |
| 85 | 87 | type = "app"; |
| 86 | 88 | program = "${pkgs.writeShellApplication { |
| 87 | 89 | name = "mykiwi-blog-deploy"; |
| 88 | - runtimeInputs = [ wrangler pkgs.git pkgs.nix ]; | |
| 90 | + runtimeInputs = [ wrangler pkgs.git ]; | |
| 89 | 91 | text = '' |
| 92 | + lang="''${1:?usage: nix run .#deploy -- <lang>}" | |
| 90 | 93 | root="$(git rev-parse --show-toplevel)" |
| 91 | - link="$(mktemp -d)/result" | |
| 92 | - nix build "$root#default" --out-link "$link" | |
| 93 | - for lang in en fr pt ja es; do | |
| 94 | - project="mykiwi-blog-$lang" | |
| 95 | - echo "==> deploying $lang -> $project" | |
| 96 | - wrangler pages deploy "$link/$lang" --project-name="$project" --branch=main | |
| 97 | - done | |
| 94 | + project="mykiwi-blog-$lang" | |
| 95 | + wrangler pages deploy "$root/result/$lang" --project-name="$project" --branch=main | |
| 98 | 96 | ''; |
| 99 | 97 | }}/bin/mykiwi-blog-deploy"; |
| 100 | 98 | }; |
| @@ -77,24 +77,22 @@ | |||
| 77 | }}/bin/mykiwi-blog-infra"; | 77 | }}/bin/mykiwi-blog-infra"; |
| 78 | }; | 78 | }; |
| 79 | 79 | ||
| 80 | - # `nix run .#deploy` - builds the site (the same `packages.default` | 80 | + # `nix run .#deploy -- <lang>` - pushes the already-built `./result/<lang>` |
| 81 | - # derivation `nix build` uses) and pushes each language's output | 81 | + # folder (built separately via `make build` / `nix build`, the same |
| 82 | - # folder to its matching Cloudflare Pages project. Needs | 82 | + # `packages.default` derivation) to its matching Cloudflare Pages |
| 83 | - # CLOUDFLARE_API_TOKEN, same as `infra`. | 83 | + # project. Needs CLOUDFLARE_API_TOKEN, same as `infra`. Takes a single |
| 84 | + # language so the Makefile can fan out `make deploy` across languages | ||
| 85 | + # in parallel via `make -j`. | ||
| 84 | deploy = { | 86 | deploy = { |
| 85 | type = "app"; | 87 | type = "app"; |
| 86 | program = "${pkgs.writeShellApplication { | 88 | program = "${pkgs.writeShellApplication { |
| 87 | name = "mykiwi-blog-deploy"; | 89 | name = "mykiwi-blog-deploy"; |
| 88 | - runtimeInputs = [ wrangler pkgs.git pkgs.nix ]; | 90 | + runtimeInputs = [ wrangler pkgs.git ]; |
| 89 | text = '' | 91 | text = '' |
| 92 | + lang="''${1:?usage: nix run .#deploy -- <lang>}" | ||
| 90 | root="$(git rev-parse --show-toplevel)" | 93 | root="$(git rev-parse --show-toplevel)" |
| 91 | - link="$(mktemp -d)/result" | 94 | + project="mykiwi-blog-$lang" |
| 92 | - nix build "$root#default" --out-link "$link" | 95 | + wrangler pages deploy "$root/result/$lang" --project-name="$project" --branch=main |
| 93 | - for lang in en fr pt ja es; do | ||
| 94 | - project="mykiwi-blog-$lang" | ||
| 95 | - echo "==> deploying $lang -> $project" | ||
| 96 | - wrangler pages deploy "$link/$lang" --project-name="$project" --branch=main | ||
| 97 | - done | ||
| 98 | ''; | 96 | ''; |
| 99 | }}/bin/mykiwi-blog-deploy"; | 97 | }}/bin/mykiwi-blog-deploy"; |
| 100 | }; | 98 | }; |