-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathMakefile
More file actions
129 lines (93 loc) · 3.74 KB
/
Copy pathMakefile
File metadata and controls
129 lines (93 loc) · 3.74 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
#.SILENT:
SHELL = /bin/bash
.PHONY: clean clean_build clean_pack clean_test clean_docker_test clean_venv test docker_test
all:
echo -e "Required section:\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 \"dtcd_simple_math_core_vX.Y.Z_BRANCHNAME.tar.gz\"\n\
Addition section:\n\
venv\n\
"
GENERATE_VERSION = $(shell cat setup.py | grep __version__ | head -n 1 | sed -re 's/[^"]+//' | sed -re 's/"//g' )
GENERATE_BRANCH = $(shell git name-rev $$(git rev-parse HEAD) | cut -d\ -f2 | sed -re 's/^(remotes\/)?origin\///' | tr '/' '_')
SET_VERSION = $(eval VERSION=$(GENERATE_VERSION))
SET_BRANCH = $(eval BRANCH=$(GENERATE_BRANCH))
CONDA = conda/miniconda/bin/conda
ENV_PYTHON = venv/bin/python3.9
define clean_docker_containers
@echo "Stopping and removing docker containers"
docker-compose -f docker-compose-test.yml stop
if [[ $$(docker ps -aq -f name=dtcd_simple_math_core) ]]; then \
docker rm $$(docker ps -aq -f name=dtcd_simple_math_core); \
else \
echo "No Docker containers found to remove."; \
fi;
endef
define clean_docker_images
@echo "Removing dtcd_simple_math_core docker images"
if [[ $$(docker images complex_rest_for_dtcd_simple_math_core -q) ]]; then \
docker image rm $$(docker image ls --quiet complex_rest_for_dtcd_simple_math_core); \
else \
echo "No Docker images found to remove."; \
fi
endef
pack:
#make_build
$(SET_VERSION)
$(SET_BRANCH)
rm -f dtcd_simple_math_core-*.tar.gz
rm -f *.tar.gz
echo Create archive \"dtcd_simple_math_core-$(VERSION)-$(BRANCH).tar.gz\"
cd make_build; tar czf ../dtcd_simple_math_core-$(VERSION)-$(BRANCH).tar.gz dtcd_simple_math_core
clean_pack:
rm -f dtcd_simple_math_core-*.tar.gz
dtcd_simple_math_core.tar.gz: build
cd make_build; tar czf ../dtcd_simple_math_core.tar.gz dtcd_simple_math_core && rm -rf ../make_build
build: make_build
make_build: venv venv.tar.gz
# required section
echo make_build
mkdir make_build
cp -R ./dtcd_simple_math_core make_build
rm -f make_build/dtcd_simple_math_core/dtcd_simple_math_core.conf
mv make_build/dtcd_simple_math_core/dtcd_simple_math_core.conf.example make_build/dtcd_simple_math_core/dtcd_simple_math_core.conf
cp *.md make_build/dtcd_simple_math_core/
cp *.py make_build/dtcd_simple_math_core/
mkdir make_build/dtcd_simple_math_core/venv
tar -xzf ./venv.tar.gz -C make_build/dtcd_simple_math_core/venv
conda/miniconda.sh:
echo Download Miniconda
mkdir -p conda
wget https://repo.anaconda.com/miniconda/Miniconda3-py39_4.12.0-Linux-x86_64.sh -O conda/miniconda.sh
conda/miniconda: conda/miniconda.sh
bash conda/miniconda.sh -b -p conda/miniconda
conda/miniconda/bin/conda-pack: conda/miniconda
conda/miniconda/bin/conda install conda-pack -c conda-forge -y
clean_build:
rm -rf make_build
venv: clean_venv conda/miniconda
echo Create venv
$(CONDA) create --copy -p ./venv -y
$(CONDA) install -p ./venv python==3.9.7 -y
$(ENV_PYTHON) -m pip install --no-input -r requirements.txt
venv.tar.gz: venv conda/miniconda/bin/conda-pack
$(CONDA) pack -p ./venv -o ./venv.tar.gz
clean_venv:
rm -rf venv
rm -f ./venv.tar.gz
clean: clean_build clean_venv clean_pack clean_test
test: docker_test
logs:
mkdir -p ./logs
docker_test: logs
$(call clean_docker_containers)
$(call clean_docker_images)
@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)
$(call clean_docker_images)
clean_docker_test:
$(call clean_docker_containers)
clean_test: clean_docker_test