-
Notifications
You must be signed in to change notification settings - Fork 125
Expand file tree
/
Copy pathMakefile
More file actions
177 lines (150 loc) · 5.5 KB
/
Copy pathMakefile
File metadata and controls
177 lines (150 loc) · 5.5 KB
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
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
#
#
# Makefile for developing and building An Otter Wiki
#
# Please read the Installation guide <https://otterwiki.com/Installation>
# to get started.
#
#
PORT ?= 8080
VERSION := $(shell python3 -c "with open('otterwiki/version.py') as f: exec(f.read()); print(__version__);")
VERSION_MAJOR_MINOR := $(shell python3 -c "with open('otterwiki/version.py') as f: exec(f.read()); print('.'.join(__version__.split('.')[0:2]));")
VERSION_MAJOR := $(shell python3 -c "with open('otterwiki/version.py') as f: exec(f.read()); print('.'.join(__version__.split('.')[0:1]));")
PLATFORM ?= "linux/arm64,linux/amd64,linux/arm/v7,linux/arm/v6"
PLATFORM_QUICK ?= "linux/arm64,linux/amd64"
HELM_VERSION := $(shell grep ^version helm/Chart.yaml | awk '{print $$2}')
BRANCH := $(shell git rev-parse --abbrev-ref HEAD)
# sanitize the branch name into a valid docker tag (replace invalid chars with -)
BRANCH_TAG := $(shell git rev-parse --abbrev-ref HEAD | sed 's/[^a-zA-Z0-9_.-]/-/g')
all: run
.PHONY: clean coverage run debug cli shell sdist docker-build docker-test frontend
ARGS ?=
clean:
rm -rf venv *.egg-info dist *.log* otterwiki/__pycache__ tests/__pycache__
rm -rf .pytest_cache .tox
rm -rf coverage_html
venv: pyproject.toml
rm -rf venv
python3 -m venv venv
venv/bin/pip install -U pip wheel
venv/bin/pip install -e '.[dev]'
venv/bin/pre-commit install
run: venv settings.cfg
GIT_TAG=$(shell git describe --long) FLASK_APP=otterwiki.server OTTERWIKI_SETTINGS=$(PWD)/settings.cfg venv/bin/flask run --host 0.0.0.0 --port $(PORT)
debug: venv settings.cfg
FLASK_ENV=development FLASK_DEBUG=True FLASK_APP=otterwiki.server OTTERWIKI_SETTINGS=../settings.cfg venv/bin/flask run --port $(PORT)
cli: venv settings.cfg
FLASK_APP=otterwiki.server OTTERWIKI_SETTINGS=$(PWD)/settings.cfg venv/bin/flask $(ARGS)
profiler: venv settings.cfg
FLASK_DEBUG=True FLASK_APP=otterwiki.server OTTERWIKI_SETTINGS=../settings.cfg \
venv/bin/python otterwiki/profiler.py
shell: venv
FLASK_DEBUG=True FLASK_APP=otterwiki.server OTTERWIKI_SETTINGS=../settings.cfg venv/bin/flask shell
test: venv
OTTERWIKI_SETTINGS="" venv/bin/pytest tests docs/plugin_examples/tests
tox: venv
venv/bin/tox
coverage: venv
OTTERWIKI_SETTINGS="" venv/bin/coverage run --source=otterwiki -m pytest tests docs/plugin_examples/tests
venv/bin/coverage report
venv/bin/coverage html
black:
venv/bin/black setup.py otterwiki/ tests/
sdist: venv test
venv/bin/python setup.py sdist
settings.cfg:
@echo ""
@echo " Please create the settings.cfg. You find an example in the"
@echo " settings.cfg.skeleton"
@echo ""
@false
frontend:
cd frontend && npm install --include=dev && node esbuild.config.mjs
docker-test:
# make sure the image is rebuild
docker build -t otterwiki:_test --target test-stage .
docker run -it --rm otterwiki:_test
docker-run:
docker build -t otterwiki:_build .
docker run -p 8080:80 otterwiki:_build
docker-run-slim:
docker build -t otterwiki:_build-slim \
-f docker/Dockerfile.slim \
.
docker run -p 8080:8080 otterwiki:_build-slim
docker-platform-test:
ifeq ($(strip $(shell git rev-parse --abbrev-ref HEAD)),main)
docker buildx build --platform $(PLATFORM) --target test-stage .
else
docker buildx build --platform $(PLATFORM_QUICK) --target test-stage .
endif
docker-push-slim: test
ifeq ($(strip $(BRANCH)),main)
# check if git is clean
ifneq ($(strip $(shell git status --porcelain)),)
$(error Error: Uncommitted changes in found)
endif
docker buildx build \
--platform $(PLATFORM) \
-f docker/Dockerfile.slim \
-t redimp/otterwiki:$(VERSION)-slim \
-t redimp/otterwiki:$(VERSION_MAJOR)-slim \
-t redimp/otterwiki:$(VERSION_MAJOR_MINOR)-slim \
--build-arg GIT_TAG="$(shell git describe --long)" \
--push .
else
@echo ""
@echo "-- Building dev image"
@echo ""
docker buildx build --platform $(PLATFORM_QUICK) \
-f docker/Dockerfile.slim \
-t redimp/otterwiki:dev-$(BRANCH_TAG)-slim \
--build-arg GIT_TAG="$(shell git describe --long)_$(BRANCH)" \
--push .
@echo ""
@echo "-- Done dev-image: redimp/otterwiki:dev-$(BRANCH_TAG)-slim"
@echo ""
endif
docker-push: test
# check if we are in the main branch (to avoid accidentally pushing a feature branch
ifeq ($(strip $(BRANCH)),main)
# check if git is clean
ifneq ($(strip $(shell git status --porcelain)),)
$(error Error: Uncommitted changes in found)
endif
docker buildx build --platform $(PLATFORM) \
-t redimp/otterwiki:latest \
-t redimp/otterwiki:$(VERSION) \
-t redimp/otterwiki:$(VERSION_MAJOR) \
-t redimp/otterwiki:$(VERSION_MAJOR_MINOR) \
--build-arg GIT_TAG="$(shell git describe --long)" \
--push .
else
@echo ""
@echo "-- Building dev image"
@echo ""
docker buildx build --platform $(PLATFORM_QUICK) \
-t redimp/otterwiki:dev-$(BRANCH_TAG) \
--build-arg GIT_TAG="$(shell git describe --long)_$(BRANCH)" \
--push .
@echo ""
@echo "-- Done dev-image: redimp/otterwiki:dev-$(BRANCH_TAG)"
@echo ""
endif
pypi: test
./venv/bin/python3 -m pip install --upgrade build twine
./venv/bin/python3 -m build
./venv/bin/python3 -m twine upload -r pypi dist/*
helm-build:
cd helm/ && helm lint ./
cd helm/ && helm package ./
helm-test:
cd helm/ && \
helm template otterwiki \
--set config.SITE_NAME=Template \
./
helm-push: helm-build
set -e; \
CHARTS_POD=$$(kubectl get pods -n 'otterwiki' -l 'app.kubernetes.io/name=charts-otterwiki-com' -o jsonpath='{.items[0].metadata.name}'); \
kubectl cp -c chartexhibiton helm/otterwiki-$(HELM_VERSION).tgz otterwiki/$$CHARTS_POD:/data; \
kubectl rollout restart deployment -n otterwiki -l app.kubernetes.io/name=charts-otterwiki-com