-
Notifications
You must be signed in to change notification settings - Fork 58
/
Makefile
154 lines (128 loc) · 6.01 KB
/
Makefile
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
SHELL := bash
.ONESHELL:
.NOTPARALLEL:
# use HIDE to run commands invisibly, unless VERBOSE defined
HIDE:=$(if $(VERBOSE),,@)
UNAME := $(shell uname)
.PHONY: kat update reset up stop down clean fetch pull upgrade env-if-empty env build debian-build-image ubuntu-build-image docs
# Export Docker buildkit options
export DOCKER_BUILDKIT=1
export COMPOSE_DOCKER_CLI_BUILD=1
# We can't really return an error here, so if settings-doc fails we delete the
# file which will result in sphinx-build returning an error later on
define build-settings-doc
echo "# $(4)" > docs/source/installation-and-deployment/environment-settings/$(3).md
DOCS=True PYTHONPATH=./$(1) settings-doc generate \
-f markdown -m $(2) \
--templates docs/settings-doc-templates \
>> docs/source/installation-and-deployment/environment-settings/$(3).md || exit 1
endef
# Build and bring up all containers (default target)
kat: env-if-empty build up
@echo
@echo "The KAT frontend is running at http://localhost:8000,"
@echo "An initial superuser has been created"
@echo "The username is stored in DJANGO_SUPERUSER_EMAIL in the .env-default file."
@echo "run 'grep 'DJANGO_SUPERUSER_EMAIL' .env-defaults' to find it."
@echo "The related password can be found as DJANGO_SUPERUSER_PASSWORD in the .env file."
@echo "run 'grep 'DJANGO_SUPERUSER_PASSWORD' .env' to find it."
@echo
@echo "WARNING: This is a development environment, do not use in production!"
@echo "See https://docs.openkat.nl/installation_and_deployment/install.html for production"
@echo "installation instructions."
# Remove containers, update using git pull and bring up containers
update: down pull kat
# Remove all containers and volumes, and bring containers up again (data loss!)
reset: clean kat
# Bring up containers
up:
docker compose up --detach
# Stop containers
stop:
-docker compose stop
# Remove containers but not volumes (no data loss)
down:
-docker compose down
# Remove containers and all volumes (data loss!)
clean:
-docker compose down --timeout 0 --volumes --remove-orphans
-rm -Rf rocky/node_modules rocky/assets/dist rocky/.parcel-cache rocky/static
# Fetch the latest changes from the Git remote
fetch:
git fetch --all --prune --tags
# Pull the latest changes from the default upstream
pull:
git pull
docker compose pull
# Upgrade to the latest release without losing persistent data. Usage: `make upgrade version=v1.5.0` (version is optional)
VERSION?=$(shell curl -sSf "https://api.github.com/repos/minvws/nl-kat-coordination/tags" | jq -r '[.[].name | select(. | contains("rc") | not)][0]')
upgrade: down fetch
git checkout $(VERSION)
make kat
# Create .env file only if it does not exist
env-if-empty:
ifeq ("$(wildcard .env)","")
make env
endif
# Create .env file from the env-dist with randomly generated credentials from vars annotated by "{%EXAMPLE_VAR}"
env:
cp .env-dist .env
echo "Initializing .env with random credentials"
ifeq ($(UNAME), Darwin) # Different sed on MacOS
$(HIDE) grep -o "{%\([_A-Z]*\)}" .env-dist | sort -u | while read v; do sed -i '' "s/$$v/$$(openssl rand -hex 25)/g" .env; done
else
$(HIDE) grep -o "{%\([_A-Z]*\)}" .env-dist | sort -u | while read v; do sed -i "s/$$v/$$(openssl rand -hex 25)/g" .env; done
endif
# Build will prepare all services: migrate them, seed them, etc.
build:
ifeq ($(UNAME),Darwin)
docker compose build --pull --parallel --build-arg USER_UID="$$(id -u)"
else
docker compose build --pull --parallel --build-arg USER_UID="$$(id -u)" --build-arg USER_GID="$$(id -g)"
endif
make -C rocky build
make -C boefjes build
# Build Debian 11 build image
debian12-build-image:
docker build -t kat-debian12-build-image packaging/debian12
# Build Ubuntu 22.04 build image
ubuntu22.04-build-image:
docker build -t kat-ubuntu22.04-build-image packaging/ubuntu22.04
docs:
$(call build-settings-doc,keiko,keiko.settings,keiko,Keiko)
$(call build-settings-doc,octopoes,octopoes.config.settings,octopoes,Octopoes)
$(call build-settings-doc,boefjes,boefjes.config,boefjes,Boefjes)
$(call build-settings-doc,bytes,bytes.config,bytes,Bytes)
$(call build-settings-doc,mula/scheduler,config.settings,mula,Mula)
curl -sL -o - https://registry.npmjs.org/d3/-/d3-7.9.0.tgz | tar -Oxzf - package/dist/d3.min.js > docs/source/_static/d3.min.js
curl -sL -o - https://registry.npmjs.org/mermaid/-/mermaid-11.3.0.tgz | tar -Oxzf - package/dist/mermaid.min.js > docs/source/_static/mermaid.min.js
echo "f2094bbf6141b359722c4fe454eb6c4b0f0e42cc10cc7af921fc158fceb86539 docs/source/_static/d3.min.js" | sha256sum --quiet --check || exit 1
echo "0d2b6f2361e7e0ce466a6ed458e03daa5584b42ef6926c3beb62eb64670ca261 docs/source/_static/mermaid.min.js" | sha256sum --quiet --check || exit 1
PYTHONPATH=$(PYTHONPATH):boefjes/:bytes/:keiko/:mula/:octopoes/ sphinx-build -b html --fail-on-warning docs/source docs/_build
poetry-dependencies:
files=$$(find . -name pyproject.toml -maxdepth 2); \
for path in $$files; do \
project_dir=$$(dirname $$path); \
echo "Processing $$path..."; \
poetry check --lock -C $$project_dir; \
echo "Exporting main dependencies..."; \
poetry export -C $$project_dir --only main -f requirements.txt -o $$project_dir/requirements.txt; \
if grep -q "tool.poetry.group.dev.dependencies" $$path; then \
echo "Exporting dev dependencies..."; \
poetry export -C $$project_dir --with dev -f requirements.txt -o $$project_dir/requirements-dev.txt; \
else \
echo "No dev group, skipping requirements-dev.txt..."; \
fi; \
done
fix-poetry-merge-conflict:
for path in `git diff --diff-filter=U --name-only | grep "poetry.lock" | cut -d / -f 1`; do \
echo $$path; \
git restore --staged $$path/poetry.lock $$path/requirements*; \
git checkout --theirs $$path/poetry.lock $$path/requirements*; \
poetry lock --no-update -C $$path; \
poetry export -C $$path --only main -f requirements.txt -o $$path/requirements.txt; \
if grep -q "tool.poetry.group.dev.dependencies" $$path/pyproject.toml; then \
poetry export -C $$path --with dev -f requirements.txt -o $$path/requirements-dev.txt; \
fi; \
git add $$path/poetry.lock $$path/requirements*; \
done