forked from Mejiro-McQueen/AIT-Deploy
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMakefile
214 lines (155 loc) · 5.34 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
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
## Your project adaptation, otherwise comment the line
#PROJECT_URL = https://github.jpl.nasa.gov/SunRISE-Ops/SunRISE-AIT.git
MINICONDA_URL = https://repo.anaconda.com/miniconda/Miniconda3-latest-Linux-x86_64.sh
AIT_CORE_URL = https://github.com/Mejiro-McQueen/AIT-Core.git
AIT_GUI_URL = https://github.com/Mejiro-McQueen/AIT-GUI.git
AIT_DSN_URL = https://github.com/Mejiro-McQueen/AIT-DSN.git
## Choose a branch for each component
AIT_CORE_BRANCH := master
AIT_GUI_BRANCH := master
AIT_DSN_BRANCH := master
PROJECT_BRANCH := master
## Attempt to switch branches after first clone
## Useful for development
BRANCH_SWITCH = False
## Python version must be compatible between componenets
PYTHON_VERSION = 3.8
## Useful Options for Debugging AIT
# DEV=true
# TOX=true
KMC_CLIENT := /ammos/kmc-crypto-client/lib/python$(PYTHON_VERSION)/site-packages
#!----- End of User Configuration -----!#
## Useful for debugging makefile
#.SHELLFLAGS = -vc
PATH := $(HOME)/miniconda3/bin:$(PATH)
SHELL := env PATH=$(PATH) /usr/bin/env bash
PYTHONPATH := $(KMC_CLIENT):$(PYTHONPATH)
AWS = $(findstring ec2, $(shell cat /sys/hypervisor/uuid))
CONDA_ACTIVATE = source $$(conda info --base)/etc/profile.d/conda.sh ; conda activate \
; conda activate $(project_name) &> /dev/null
ifdef PROJECT_URL
project_name := $(shell basename $(PROJECT_URL) .git)
else
project_name = "AIT-Core"
endif
ifdef TEST
project_name = "AIT-Core"
endif
#--------- Important Targets -------------#
server: virtual-env AIT-Core AIT-Project
$(CONDA_ACTIVATE)&& \
ait-server&
nofork: virtual-env AIT-Core AIT-Project
$(CONDA_ACTIVATE)&& \
traceback-with-variables ait-server
kmc_shell: virtual-env AIT-Core
$(CONDA_ACTIVATE)&& \
LD_PRELOAD=/usr/lib64/libcrypto.so.1.1 bash -c python \
kmc_nofork: create_db nofork
$(CONDA_ACTIVATE)&& \
LD_PRELOAD=/usr/lib64/libcrypto.so.1.1 traceback-wth-variables ait-server
kmc_server:
$(CONDA_ACTIVATE)&& \
LD_PRELOAD=/usr/lib64/libcrypto.so.1.1 ait-server
create_db:
$(MAKE) -C ./sql_scripts
clean_db:
$(MAKE) -C ./sql_scripts clean
clean: clean_db
pkill ait-server || true
conda env remove --name $(project_name) &> /dev/null || true
conda env remove --name AIT-Core &> /dev/null || true
#--------- AUX TARGETS -------------#
AIT-Project: virtual-env AIT-DSN AIT-GUI AIT-Core
ifdef PROJECT_URL
test ! -d $(project_name) && git clone -q --branch $(PROJECT_BRANCH) $(PROJECT_URL) || true
ifeq ($(BRANCH_SWITCH), True)
cd $(project_name) && git checkout $(PROJECT_BRANCH)
endif
$(CONDA_ACTIVATE) && pip install -q -q ./$(project_name)
endif
AIT-Core: virtual-env
test ! -d $@ && git clone -q --branch $(AIT_CORE_BRANCH) $(AIT_CORE_URL) || true
ifeq ($(BRANCH_SWITCH), True)
cd $@ && git checkout $(AIT_CORE_BRANCH)
endif
ifndef DEV
$(CONDA_ACTIVATE) && pip install -q -q ./$@
endif
ifdef TEST
$(CONDA_ACTIVATE) && \
pytest -v -s -o log_cli=true ./AIT-Core/tests/
endif
ifdef DEV
$(CONDA_ACTIVATE) && cd ./$@ && poetry install > /dev/null && \
pre-commit install > /dev/null && pre-commit install -t pre-push > /dev/null
ifdef TOX
$(CONDA_ACTIVATE) && cd ./$&& tox
endif
endif
AIT-DSN: virtual-env AIT-Core
ifdef AIT_DSN_URL
test ! -d $@ && git clone -q --branch $(AIT_DSN_BRANCH) $(AIT_DSN_URL) || true
ifeq ($(BRANCH_SWITCH), True)
cd $@ && git checkout $(AIT_DSN_BRANCH)
endif
$(CONDA_ACTIVATE) && pip install -q -q ./$@
endif
AIT-GUI: virtual-env AIT-Core
ifdef AIT_GUI_URL
test ! -d $@ && git clone -q --branch $(AIT_GUI_BRANCH) $(AIT_GUI_URL) || true
ifeq ($(BRANCH_SWITCH), True)
cd $@ && git checkout $(AIT_GUI_BRANCH)
endif
$(CONDA_ACTIVATE) && pip install -q -q ./$@
endif
conda:
ifeq ($(shell command -v conda 2>&1 /dev/null),)
ifeq ($(wildcard *conda3-*-Linux-x86_64.sh),)
wget -q $(MINICONDA_URL)
endif
bash *conda3-*-Linux-x86_64.sh -b > /dev/null || true
endif
virtual-env: conda
conda create -y -q --name $(project_name) python=$(PYTHON_VERSION) pytest pytest-cov cffi > /dev/null || true
conda install -y -q -c conda-forge --name $(project_name) traceback-with-variables > /dev/null
$(CONDA_ACTIVATE) && \
conda env config vars set PYTHONPATH=$(PYTHONPATH) AIT_ROOT=./AIT-Core AIT_CONFIG=./$(project_name)/config/config.yaml > /dev/null
ifdef DEV
ifeq ($(shell command -v poetry 2>&1 /dev/null),)
# Cache the install
conda install -y -q -c conda-forge --name base poetry mypy flake8 > /dev/null
echo "Installed poetry globally."
endif
conda install -y -q -c conda-forge --name $(project_name) poetry mypy flake8 > /dev/null
endif
#----------------- Convenience Targets (May be deleted soon)-------------#
touch-paths: AIT-Core AIT-Project
# Run to supress nonexistent path warnings
$(CONDA_ACTIVATE) && \
ait-create-dirs || true
start_sims:
sleep 5
cd /opt/sunrise/ && ./startupGse.sh
cd /mnt/fsw/ && ./startup.sh
stop_sims:
cd /opt/sunrise/ && ./shutdownGse.sh
cd /mnt/fsw/ && ./shutdown.sh
interactive: server start_sims
echo "Starting AIT Server and Sims!"
xdg-open http://localhost:8080
kmc_interactive: kmc_nofork start_sims
echo "Starting AIT Server and Sims!"
xdg-open http://localhost:8080
start_sim_tunnel:
ssh -g -L 42401:localhost:42401 -N alma-ait
open-port:
ifneq ($(AWS), ec2)
sudo firewall-cmd --zone=public --permanent --add-port=8080/tcp
sudo firewall-cmd --reload
endif
close-port:
ifneq ($(AWS), ec2)
sudo firewall-cmd --zone=public --permanent --remove-port=8080/tcp
sudo firewall-cmd --reload
endif