-
Notifications
You must be signed in to change notification settings - Fork 32
/
Makefile
175 lines (149 loc) · 5.64 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
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
#
#
# 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}')
all: run
.PHONY: clean coverage run debug shell sdist docker-build docker-test
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)
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
tox: venv
venv/bin/tox
coverage: venv
OTTERWIKI_SETTINGS="" venv/bin/coverage run --source=otterwiki -m pytest 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
tmp/codemirror-5.65.15:
mkdir -p tmp && \
cd tmp && \
test -f codemirror.zip || wget https://codemirror.net/5/codemirror.zip && \
unzip codemirror.zip
otterwiki/static/js/cm-modes.min.js: Makefile tmp/codemirror-5.65.15
cat tmp/codemirror-5.65.15/addon/mode/simple.js > otterwiki/static/js/cm-modes.js
cat tmp/codemirror-5.65.15/mode/meta.js >> otterwiki/static/js/cm-modes.js
for MODE in shell clike xml python javascript markdown yaml php sql \
toml cmake perl http go rust dockerfile powershell properties \
stex nginx haskell lua jinja2 ruby; do \
cat tmp/codemirror-5.65.15/mode/$$MODE/$$MODE.js \
>> otterwiki/static/js/cm-modes.js; \
done
./venv/bin/python -m rjsmin -p < otterwiki/static/js/cm-modes.js > otterwiki/static/js/cm-modes.min.js
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 $(shell git rev-parse --abbrev-ref HEAD)),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-$(shell git rev-parse --abbrev-ref HEAD)-slim \
--build-arg GIT_TAG="$(shell git describe --long)_$(shell git rev-parse --abbrev-ref HEAD)" \
--push .
@echo ""
@echo "-- Done dev-image: redimp/otterwiki:dev-$(shell git rev-parse --abbrev-ref HEAD)-slim"
@echo ""
endif
docker-push: test
# check if we are in the main branch (to avoid accidently pushing a feature branch
ifeq ($(strip $(shell git rev-parse --abbrev-ref HEAD)),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-$(shell git rev-parse --abbrev-ref HEAD) \
--build-arg GIT_TAG="$(shell git describe --long)_$(shell git rev-parse --abbrev-ref HEAD)" \
--push .
@echo ""
@echo "-- Done dev-image: redimp/otterwiki:dev-$(shell git rev-parse --abbrev-ref HEAD)"
@echo ""
endif
pypi: test
./venv/bin/python3 -m pip install --upgrade build twine
./venv/bin/python3 -m build
./venv/bin/python3 -m twine upload dist/*
helm-build:
cd helm/ && helm lint ./
cd helm/ && helm package ./
helm-push: helm-build
helm push helm/otterwiki-$(HELM_VERSION).tgz oci://registry-1.docker.io/redimp