2026-07-10 17:06:01 -07:00
|
|
|
# Copyright 2025-2026 Thomas Hintz
|
|
|
|
|
|
|
|
|
|
# This file is part of Nassella.
|
|
|
|
|
|
|
|
|
|
# Nassella is free software: you can redistribute it and/or modify it under the
|
|
|
|
|
# terms of the GNU Affero General Public License as published by the Free
|
|
|
|
|
# Software Foundation, either version 3 of the License, or (at your option) any
|
|
|
|
|
# later version.
|
|
|
|
|
|
|
|
|
|
# Nassella is distributed in the hope that it will be useful, but WITHOUT ANY
|
|
|
|
|
# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
|
|
|
|
|
# FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
|
|
|
|
|
|
|
|
|
|
# You should have received a copy of the GNU Affero General Public License
|
|
|
|
|
# along with Nassella. If not, see <https://www.gnu.org/licenses/>.
|
|
|
|
|
|
2025-09-15 15:00:26 -07:00
|
|
|
TERRAFORM_ENV := production
|
|
|
|
|
|
2025-09-15 15:14:03 -07:00
|
|
|
config_dir := ./config/
|
2025-09-15 15:00:26 -07:00
|
|
|
apps_config := $(config_dir)apps.config
|
2025-08-11 13:26:21 -07:00
|
|
|
|
2026-07-15 15:18:34 -07:00
|
|
|
BUTANE := butane -d ${PWD}
|
|
|
|
|
|
|
|
|
|
ifeq ($(shell command -v docker >/dev/null 2>&1 && echo yes),yes)
|
|
|
|
|
BUTANE := docker run --rm --volume ${PWD}:/pwd --workdir /pwd -i quay.io/coreos/butane:latest -d /pwd
|
|
|
|
|
endif
|
|
|
|
|
|
2026-07-03 10:14:03 -07:00
|
|
|
IMAGE_DEPS :=
|
|
|
|
|
|
|
|
|
|
COMPOSE_ENVS := $(shell if [ -d app/ ]; then find app/ -type f -name '.compose-env'; fi)
|
|
|
|
|
|
2026-07-02 19:39:56 -07:00
|
|
|
ALL_APPS_FILES = $(shell find all-apps/ -type f -name '*')
|
|
|
|
|
|
2026-07-03 10:14:03 -07:00
|
|
|
APP_MAKEFILES := $(shell if [ -d app/ ]; then find app/ -type f -name 'Makefile'; fi)
|
|
|
|
|
-include $(APP_MAKEFILES)
|
|
|
|
|
|
2025-08-16 15:50:14 -07:00
|
|
|
# .dirstamp plus && $@ is like make magic to get this rule
|
|
|
|
|
# to only run if the contents of all-apps changes
|
2026-07-02 19:39:56 -07:00
|
|
|
app/.dirstamp: copy-apps.sh $(apps_config) $(ALL_APPS_FILES)
|
2025-08-16 15:50:14 -07:00
|
|
|
rm -Rf app/
|
2026-01-18 08:20:56 -08:00
|
|
|
mkdir app/
|
|
|
|
|
cp all-apps/app.service app/
|
2026-05-07 08:45:55 -07:00
|
|
|
cp all-apps/restic-snapshot.service app/
|
2026-07-08 15:20:41 -07:00
|
|
|
./make-top-level-docker-compose.sh $(apps_config) > app/docker-compose.yaml
|
2026-01-18 08:20:56 -08:00
|
|
|
./copy-apps.sh $(apps_config) && touch $@
|
2025-08-11 13:26:21 -07:00
|
|
|
|
2026-07-02 19:39:56 -07:00
|
|
|
# # compose .env files
|
|
|
|
|
# # (compose only supports one .env file at the root by default)
|
2026-07-03 10:14:03 -07:00
|
|
|
app/.env: $(apps_config) $(COMPOSE_ENVS)
|
2026-07-02 19:39:56 -07:00
|
|
|
find app/ -name ".compose-env" -exec cat > app/.env {} +
|
2025-12-07 10:38:36 -08:00
|
|
|
|
2025-08-31 09:32:11 -07:00
|
|
|
# Caddy / lb
|
2026-07-08 15:20:41 -07:00
|
|
|
app/lb/lb.env: $(apps_config) app/.dirstamp make-caddyfile-env.sh
|
2026-07-02 19:39:56 -07:00
|
|
|
mkdir -p app/lb
|
2026-07-08 15:20:41 -07:00
|
|
|
./make-caddyfile-env.sh $(apps_config) > $@
|
2026-07-03 10:14:03 -07:00
|
|
|
|
|
|
|
|
app/lb/Caddyfile: $(apps_config) app/.dirstamp
|
|
|
|
|
echo "(maintenance_intercept) {" > app/lb/Caddyfile-tmp
|
|
|
|
|
echo "@maintenanceModeActive file /maintenance/maintenance.on {" >> app/lb/Caddyfile-tmp
|
|
|
|
|
echo " root /" >> app/lb/Caddyfile-tmp
|
|
|
|
|
echo "}" >> app/lb/Caddyfile-tmp
|
|
|
|
|
echo "handle @maintenanceModeActive {" >> app/lb/Caddyfile-tmp
|
|
|
|
|
echo " respond \"We are performing a maintenance, come back later\" 503" >> app/lb/Caddyfile-tmp
|
|
|
|
|
echo "}" >> app/lb/Caddyfile-tmp
|
|
|
|
|
echo "}" >> app/lb/Caddyfile-tmp
|
|
|
|
|
find app/ -name "Caddyfile" -exec cat >> app/lb/Caddyfile-tmp {} +
|
|
|
|
|
mv app/lb/Caddyfile-tmp $@
|
2025-12-08 11:32:30 -08:00
|
|
|
|
2025-09-15 15:49:25 -07:00
|
|
|
# Backups / Restic / Backblaze
|
|
|
|
|
restic-env: $(apps_config) make-restic-generated.sh
|
|
|
|
|
./make-restic-generated.sh $(apps_config) > restic-env
|
|
|
|
|
restic-password: $(apps_config) make-restic-password.sh
|
|
|
|
|
./make-restic-password.sh $(apps_config) > restic-password
|
|
|
|
|
|
2026-07-10 18:04:13 -07:00
|
|
|
app.tar.gz: app/.dirstamp \
|
|
|
|
|
app/.env \
|
|
|
|
|
app/lb/lb.env \
|
|
|
|
|
app/lb/Caddyfile
|
|
|
|
|
tar cfz app.tar.gz app/
|
|
|
|
|
|
2025-08-31 09:32:11 -07:00
|
|
|
ignition.json: cl.yaml app/.dirstamp \
|
2026-07-03 10:14:03 -07:00
|
|
|
$(IMAGE_DEPS) \
|
|
|
|
|
app/lb/lb.env \
|
2026-07-02 19:39:56 -07:00
|
|
|
app/lb/Caddyfile \
|
2025-09-15 15:49:25 -07:00
|
|
|
restic-env \
|
2025-09-15 15:56:55 -07:00
|
|
|
restic-password \
|
2026-04-23 19:01:12 -07:00
|
|
|
restic-restore.sh \
|
2026-05-07 08:45:55 -07:00
|
|
|
restic-snapshot.sh \
|
2026-07-11 13:44:26 -07:00
|
|
|
restic-scheduled-snapshot.sh \
|
2026-07-02 19:39:56 -07:00
|
|
|
app/.env \
|
2026-07-10 18:04:13 -07:00
|
|
|
$(config_dir)ssh-keys \
|
|
|
|
|
app.tar.gz
|
2026-07-15 15:18:34 -07:00
|
|
|
cat cl.yaml | $(BUTANE) > ignition.json
|
2025-08-11 13:26:21 -07:00
|
|
|
|
2025-09-15 15:00:26 -07:00
|
|
|
generated.tfvars: $(apps_config) make-generated.sh
|
|
|
|
|
./make-generated.sh $(apps_config) > generated.tfvars
|
2025-08-16 15:50:14 -07:00
|
|
|
|
2025-09-15 15:00:26 -07:00
|
|
|
plan: ignition.json $(config_dir)$(TERRAFORM_ENV).tfvars generated.tfvars
|
2026-02-21 08:39:32 -08:00
|
|
|
terraform init
|
2025-09-15 15:00:26 -07:00
|
|
|
bash -c "terraform plan -var-file=<(cat $(config_dir)$(TERRAFORM_ENV).tfvars generated.tfvars)"
|
2025-08-19 17:18:04 -07:00
|
|
|
|
2025-11-12 13:22:25 -08:00
|
|
|
.PHONY: announce-start
|
|
|
|
|
announce-start:
|
|
|
|
|
echo "NASSELLA_CONFIG: start"
|
|
|
|
|
|
2026-07-03 10:14:03 -07:00
|
|
|
# run this first to generate the all/ dir
|
|
|
|
|
# then we can 'include' all the Makefiles in all/
|
|
|
|
|
.PHONY: preapply
|
|
|
|
|
preapply: app/.dirstamp
|
|
|
|
|
echo "app generated"
|
|
|
|
|
|
2026-04-22 14:56:54 -07:00
|
|
|
apply: announce-start restic-init ignition.json $(config_dir)$(TERRAFORM_ENV).tfvars generated.tfvars
|
2025-11-12 13:22:25 -08:00
|
|
|
echo "NASSELLA_CONFIG: end"
|
2026-02-21 08:39:32 -08:00
|
|
|
terraform init
|
2025-11-12 13:22:25 -08:00
|
|
|
bash -c "terraform apply -auto-approve -input=false -var-file=<(cat $(config_dir)$(TERRAFORM_ENV).tfvars generated.tfvars)"
|
2025-08-16 15:50:14 -07:00
|
|
|
|
2025-09-15 15:00:26 -07:00
|
|
|
destroy: ignition.json $(config_dir)$(TERRAFORM_ENV).tfvars generated.tfvars
|
2026-02-21 08:39:32 -08:00
|
|
|
terraform init
|
2026-02-09 08:30:39 -08:00
|
|
|
bash -c "terraform destroy -auto-approve -input=false -var-file=<(cat $(config_dir)$(TERRAFORM_ENV).tfvars generated.tfvars)"
|
2025-08-31 09:01:01 -07:00
|
|
|
|
2025-09-15 16:17:59 -07:00
|
|
|
.PHONY: restic-init
|
|
|
|
|
restic-init: $(apps_config) restic-password
|
|
|
|
|
./init-restic.sh $(apps_config)
|
|
|
|
|
|
2025-09-17 15:58:54 -07:00
|
|
|
## just an easy way to see snapshots that have been taken
|
|
|
|
|
.PHONY: restic-snapshots
|
|
|
|
|
restic-snapshots: $(apps_config) restic-password
|
|
|
|
|
./restic-snapshots.sh $(apps_config)
|
|
|
|
|
|
2025-11-12 07:31:23 -08:00
|
|
|
.PHONY: archive
|
|
|
|
|
archive:
|
2026-07-03 10:14:03 -07:00
|
|
|
echo "(" > all-apps/root-napp.scm
|
|
|
|
|
find all-apps/ -name "napp.scm" -exec cat >> all-apps/root-napp.scm {} +
|
|
|
|
|
echo ")" >> all-apps/root-napp.scm
|
2026-07-08 15:20:41 -07:00
|
|
|
tar -cf nassella-latest.tar all-apps cl.yaml init-restic.sh main.tf make-caddyfile-env.sh make-top-level-docker-compose.sh Makefile \
|
2026-07-03 10:14:03 -07:00
|
|
|
make-generated.sh make-restic-generated.sh make-restic-password.sh restic-snapshots.sh copy-apps.sh restic-restore.sh restic-snapshot.sh \
|
2026-07-11 13:44:26 -07:00
|
|
|
restic-scheduled-snapshot.sh \
|
2026-07-03 10:14:03 -07:00
|
|
|
.terraform.lock.hcl
|
2025-11-12 07:31:23 -08:00
|
|
|
cp nassella-latest.tar src/
|
|
|
|
|
|
2025-08-16 15:50:14 -07:00
|
|
|
## to help me remember the command to run to test the config locally
|
2025-08-11 13:26:21 -07:00
|
|
|
testlocalhost:
|
|
|
|
|
curl -k --resolve localhost:443:146.190.12.129 https://localhost
|
2025-08-16 15:50:14 -07:00
|
|
|
|
|
|
|
|
flatcarbuild: ignition.json
|
|
|
|
|
cp --reflink=auto flatcar/flatcar_production_qemu_image.img.fresh flatcar/flatcar_production_qemu_image.img
|
|
|
|
|
|
|
|
|
|
flatcarrun:
|
|
|
|
|
./flatcar/flatcar_production_qemu.sh -i ignition.json
|
2025-09-15 10:49:10 -07:00
|
|
|
|