-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathMakefile
More file actions
184 lines (133 loc) · 5.22 KB
/
Copy pathMakefile
File metadata and controls
184 lines (133 loc) · 5.22 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
178
179
180
181
#.SILENT:
SHELL = /bin/bash
.PHONY: clean clean_build clean_venv.tar.gz clean_pack clean_kafka clean_unit test docker_test clean_docker_test
all:
echo -e "Sections:\n\
build - build project into build directory, with configuration file and environment\n\
clean - clean all addition file, build directory and output archive file\n\
test - run all tests\n\
pack - make output archive, file name format \"complex_rest_vX.Y.Z_BRANCHNAME.tar.gz\"\n\
dev - deploy for developing \n\
"
VERSION := $(shell cat setup.py | grep version | head -n 1 | sed -re "s/[^\"']+//" | sed -re "s/[\"',]//g")
BRANCH := $(shell git name-rev $$(git rev-parse HEAD) | cut -d\ -f2 | sed -re 's/^(remotes\/)?origin\///' | tr '/' '_')
define clean_docker_containers
@echo "Stopping and removing docker containers"
docker-compose -f docker-compose-test.yml stop
if [[ $$(docker ps -aq -f name=complex_rest) ]]; then docker rm $$(docker ps -aq -f name=complex_rest); fi;
endef
pack: make_build
rm -f complex_rest-*.tar.gz
echo Create archive \"complex_rest-$(VERSION)-$(BRANCH).tar.gz\"
cd make_build; tar czf ../complex_rest-$(VERSION)-$(BRANCH).tar.gz complex_rest
clean_pack:
rm -f complex_rest-*.tar.gz
complex_rest.tar.gz: build
cd make_build; tar czf ../complex_rest.tar.gz complex_rest && rm -rf ../make_build
build: make_build
make_build: venv.tar.gz
# required section
echo make_build
mkdir -p make_build/complex_rest
cp ./*.md make_build/complex_rest/
echo $(BRANCH) > make_build/complex_rest/.commit
git rev-parse --verify HEAD >> make_build/complex_rest/.commit
cp -R ./complex_rest make_build/complex_rest
cp ./docs/deploy/rest.conf make_build/complex_rest/complex_rest/rest.conf
rm -rf make_build/complex_rest/complex_rest/plugins/plugin_example*
cp ./docs/deploy/django_settings/production.py make_build/complex_rest/complex_rest/core/settings/production.py
mkdir -p make_build/complex_rest/logs
mkdir -p make_build/complex_rest/logs/redis
mkdir -p make_build/complex_rest/logs/nginx-unit
mkdir -p make_build/complex_rest/logs/celery
mkdir -p make_build/complex_rest/logs/zookeeper
mkdir -p make_build/complex_rest/logs/kafka
mkdir -p make_build/complex_rest/logs/postgres
mkdir -p make_build/complex_rest/plugins
mkdir -p make_build/complex_rest/deploy_state
cp ./docs/deploy/nginx-unit*.json make_build/complex_rest/
touch make_build/complex_rest/deploy_state/supervisord-control.sock
cp ./docs/deploy/*.sh make_build/complex_rest/
cp ./docs/deploy/*.py make_build/complex_rest/
cp ./docs/deploy/supervisord_base.conf make_build/complex_rest/supervisord_base.conf
cp -R ./docs/deploy/postgres_config make_build/complex_rest/postgres_config
cp ./docs/deploy/database_init.sh make_build/complex_rest/database_init.sh
cp ./docs/deploy/collectstatic.sh make_build/complex_rest/collectstatic.sh
mkdir make_build/complex_rest/venv
tar -xzf ./venv.tar.gz -C make_build/complex_rest/venv
venv.tar.gz: unit/venv
conda pack -p ./unit/venv -o ./venv.tar.gz
unit/venv: unit kafka.tar.gz
./docs/scripts/create_conda_env_with_all_dependences.sh
unit:
git clone --depth 1 --branch 1.29.0 https://github.com/nginx/unit unit
kafka.tar.gz:
curl https://archive.apache.org/dist/kafka/3.0.0/kafka_2.13-3.0.0.tgz --output kafka.tar.gz
clean_kafka:
rm -f kafka.tar.gz
clean_unit:
rm -rf ./unit/
clean_venv.tar.gz:
rm -f ./venv.tar.gz
clean_build:
rm -rf make_build
clean: clean_build clean_venv.tar.gz clean_pack clean_kafka clean_unit clean_docker_test clean_dev
test: docker_test
docker_test:
$(call clean_docker_containers)
@echo "Testing..."
CURRENT_UID=$$(id -u):$$(id -g) docker-compose -f docker-compose-test.yml run --rm complex_rest python ./complex_rest/manage.py test ./tests --settings=core.settings.test --no-input
$(call clean_docker_containers)
clean_docker_test:
$(call clean_docker_containers)
dev: venv logs
mkdir -p ./plugins
mkdir -p ./plugin_dev
cp ./docs/deploy/start_dev.sh ./start.sh
cp ./docs/deploy/stop.sh ./stop.sh
cp -R ./docs/deploy/postgres_config ./postgres_config
cp ./docs/deploy/rest_dev.conf ./complex_rest/rest.conf
./docs/deploy/database_init_dev.sh
touch dev
deploy_state/supervisord.pid: dev
./start.sh
sleep 5
dev_test: deploy_state/supervisord.pid
./venv/bin/python ./complex_rest/manage.py test ./tests --settings=core.settings.test
logs:
mkdir -p ./logs
mkdir -p ./logs/redis
mkdir -p ./logs/complex_rest
mkdir -p ./logs/celery
mkdir -p ./logs/zookeeper
mkdir -p ./logs/kafka
mkdir -p ./logs/postgres
venv: venv_dev_pack.tar.gz
mkdir -p ./venv
tar -xzf ./venv_dev_pack.tar.gz -C ./venv
venv_dev_pack.tar.gz: venv_dev
conda pack -p ./venv_dev -o ./venv_dev_pack.tar.gz
venv_dev: kafka.tar.gz
conda create --copy -p ./venv_dev -y
conda install -p ./venv_dev python==3.9.7 -y
conda install -p ./venv_dev redis -y
conda install -p ./venv_dev postgresql==12.9 -y
./venv_dev/bin/pip install --no-input -r ./requirements.txt
mkdir ./venv_dev/apps
tar zxf ./kafka.tar.gz -C ./venv_dev/apps/
clean_venv:
rm -rf ./venv
rm -rf ./venv_dev
rm -rf ./venv_dev_pack.tar.gz
clean_dev: clean_venv
-./stop.sh
rm -rf ./deploy_state
rm -rf ./logs
rm -rf ./postgres_config
rm -f stop.sh
rm -f start.sh
rm -rf ./complex_rest_db
rm -f ./complex_rest/rest.conf
rm -f ./supervisord.conf
rm -rf ./plugins
rm -f dev