|
25 | 25 | #
|
26 | 26 | # all: Runs the commands 'web' 'db' and 'python'.
|
27 | 27 | #
|
28 |
| -# test: Runs test and integrations in delphi-epidata. If test |
| 28 | +# test: Runs test and integrations in delphi-epidata. If test |
29 | 29 | # optional arg is provided, then only the tests in that subdir
|
30 | 30 | # are run.
|
31 | 31 | #
|
@@ -65,140 +65,56 @@ NOW:=$(shell date "+%Y-%m-%d")
|
65 | 65 | LOG_WEB:=delphi_web_epidata_$(NOW).log
|
66 | 66 | LOG_DB:=delphi_database_epidata_$(NOW).log
|
67 | 67 | LOG_REDIS:=delphi_redis_instance_$(NOW).log
|
68 |
| -WEB_CONTAINER_ID:=$(shell docker ps -q --filter 'name=delphi_web_epidata') |
69 |
| -DATABASE_CONTAINER_ID:=$(shell docker ps -q --filter 'name=delphi_database_epidata') |
70 |
| -REDIS_CONTAINER_ID:=$(shell docker ps -q --filter 'name=delphi_redis') |
71 | 68 |
|
72 | 69 | M1=
|
73 | 70 | ifeq ($(shell uname -smp), Darwin arm64 arm)
|
74 | 71 | $(info M1 system detected, changing docker platform to linux/amd64.)
|
75 | 72 | override M1 =--platform linux/amd64
|
76 | 73 | endif
|
77 | 74 |
|
78 |
| -.PHONY=web |
79 |
| -web: |
80 |
| - @# Stop container if running |
81 |
| - @if [ $(WEB_CONTAINER_ID) ]; then\ |
82 |
| - docker stop $(WEB_CONTAINER_ID);\ |
83 |
| - fi |
84 |
| - |
85 |
| - @# Setup virtual network if it doesn't exist |
86 |
| - @docker network ls | grep delphi-net || docker network create --driver bridge delphi-net |
87 |
| - |
88 |
| - @# Build the web_epidata image |
89 |
| - @cd repos/delphi/delphi-epidata;\ |
90 |
| - docker build -t delphi_web_epidata\ |
91 |
| - $(M1) \ |
92 |
| - -f ./devops/Dockerfile .;\ |
93 |
| - cd - |
94 |
| - |
95 |
| - @# Run the web server |
96 |
| - @# MODULE_NAME specifies the location of the `app` variable, the actual WSGI application object to run. |
97 |
| - @# see https://github.com/tiangolo/meinheld-gunicorn-docker#module_name |
98 |
| - @docker run --rm -p 127.0.0.1:10080:80 \ |
99 |
| - $(M1) \ |
100 |
| - --env "MODULE_NAME=delphi.epidata.server.main" \ |
101 |
| - --env "SQLALCHEMY_DATABASE_URI=$(sqlalchemy_uri)" \ |
102 |
| - --env "FLASK_SECRET=abc" --env "FLASK_PREFIX=/epidata" --env "LOG_DEBUG" \ |
103 |
| - --env "REDIS_HOST=delphi_redis" \ |
104 |
| - --env "REDIS_PASSWORD=1234" \ |
105 |
| - --env "API_KEY_ADMIN_PASSWORD=test_admin_password" \ |
106 |
| - --env "API_KEY_REGISTER_WEBHOOK_TOKEN=abc" \ |
107 |
| - --env "TESTING_MODE=True" \ |
108 |
| - --network delphi-net --name delphi_web_epidata \ |
109 |
| - delphi_web_epidata >$(LOG_WEB) 2>&1 & |
110 |
| - |
111 | 75 | .PHONY=db
|
112 | 76 | db:
|
113 |
| - @# Stop container if running |
114 |
| - @if [ $(DATABASE_CONTAINER_ID) ]; then\ |
115 |
| - docker stop $(DATABASE_CONTAINER_ID);\ |
116 |
| - fi |
117 |
| - |
118 |
| - @# Setup virtual network if it doesn't exist |
119 |
| - @docker network ls | grep delphi-net || docker network create --driver bridge delphi-net |
120 |
| - |
121 |
| - @# Build the database_epidata image |
122 |
| - @docker build -t delphi_database_epidata \ |
123 |
| - $(M1) \ |
124 |
| - -f repos/delphi/delphi-epidata/dev/docker/database/epidata/Dockerfile . |
125 |
| - |
126 |
| - @# Run the database |
127 |
| - @docker run --rm -p 127.0.0.1:13306:3306 \ |
128 |
| - $(M1) \ |
129 |
| - --network delphi-net --name delphi_database_epidata \ |
130 |
| - --cap-add=sys_nice \ |
131 |
| - delphi_database_epidata >$(LOG_DB) 2>&1 & |
132 |
| - |
133 |
| - @# Block until DB is ready |
134 |
| - @while true; do \ |
135 |
| - sed -n '/mysqld: ready for connections/p' $(LOG_DB) | grep "ready for connections" && break; \ |
136 |
| - tail -1 $(LOG_DB); \ |
137 |
| - sleep 1; \ |
138 |
| - done |
139 |
| - |
140 |
| -.PHONY=py |
141 |
| -py: |
142 |
| - @docker build -t delphi_web_python \ |
143 |
| - $(M1) \ |
144 |
| - -f repos/delphi/delphi-epidata/dev/docker/python/Dockerfile . |
| 77 | + @docker compose up delphi_database_epidata $(M1) --detach |
| 78 | + @docker logs -f delphi_database_epidata >$(LOG_DB) 2>&1 & |
| 79 | + |
| 80 | +.PHONY=web |
| 81 | +web: |
| 82 | + @SQLALCHEMY_DATABASE_URI=$(sqlalchemy_uri) docker compose up delphi_web_epidata $(M1) --detach |
| 83 | + @docker logs -f delphi_web_epidata >$(LOG_WEB) 2>&1 & |
145 | 84 |
|
146 | 85 | .PHONY=redis
|
147 | 86 | redis:
|
148 |
| - @# Stop container if running |
149 |
| - @if [ $(REDIS_CONTAINER_ID) ]; then\ |
150 |
| - docker stop $(REDIS_CONTAINER_ID);\ |
151 |
| - fi |
152 |
| - |
153 |
| - @docker build -t delphi_redis \ |
154 |
| - $(M1) \ |
155 |
| - -f repos/delphi/delphi-epidata/dev/docker/redis/Dockerfile . |
156 |
| - |
157 |
| - @docker run --rm -d -p 127.0.0.1:6379:6379 \ |
158 |
| - $(M1) \ |
159 |
| - --network delphi-net \ |
160 |
| - --env "REDIS_PASSWORD=1234" \ |
161 |
| - --name delphi_redis delphi_redis >$(LOG_REDIS) 2>&1 & |
162 |
| - |
163 |
| -.PHONY=all |
164 |
| -all: db web py redis |
| 87 | + @docker compose up delphi_redis $(M1) --detach |
| 88 | + @docker logs -f delphi_redis >$(LOG_REDIS) 2>&1 & |
165 | 89 |
|
166 | 90 | .PHONY=test
|
167 | 91 | test:
|
168 |
| - @docker run -i --rm --network delphi-net \ |
169 |
| - $(M1) \ |
170 |
| - --mount type=bind,source=$(CWD)repos/delphi/delphi-epidata,target=/usr/src/app/repos/delphi/delphi-epidata,readonly \ |
171 |
| - --mount type=bind,source=$(CWD)repos/delphi/delphi-epidata/src,target=/usr/src/app/delphi/epidata,readonly \ |
172 |
| - --env "SQLALCHEMY_DATABASE_URI=$(sqlalchemy_uri)" \ |
173 |
| - --env "FLASK_SECRET=abc" \ |
174 |
| - delphi_web_python python -m pytest --import-mode importlib $(pdb) $(test) | tee test_output_$(NOW).log |
| 92 | + @SQLALCHEMY_DATABASE_URI=$(sqlalchemy_uri) docker compose run delphi_web_python $(M1) \ |
| 93 | + python -m pytest --import-mode importlib $(pdb) $(test) | tee test_output_$(NOW).log |
175 | 94 |
|
176 | 95 | .PHONY=r-test
|
177 | 96 | r-test:
|
178 |
| - @docker run -i --rm --network delphi-net \ |
179 |
| - $(M1) \ |
180 |
| - --mount type=bind,source=$(CWD)repos/delphi/delphi-epidata,target=/usr/src/app/repos/delphi/delphi-epidata,readonly \ |
181 |
| - --mount type=bind,source=$(CWD)repos/delphi/delphi-epidata/src,target=/usr/src/app/delphi/epidata,readonly \ |
182 |
| - --env "SQLALCHEMY_DATABASE_URI=$(sqlalchemy_uri)" \ |
183 |
| - --env "FLASK_SECRET=abc" \ |
184 |
| - delphi_web_python Rscript repos/delphi/delphi-epidata/integrations/client/test_delphi_epidata.R | tee r-test_output_$(NOW).log |
185 |
| - |
| 97 | + @SQLALCHEMY_DATABASE_URI=$(sqlalchemy_uri) docker compose run delphi_web_python $(M1) \ |
| 98 | + Rscript repos/delphi/delphi-epidata/integrations/client/test_delphi_epidata.R | tee r-test_output_$(NOW).log |
186 | 99 |
|
187 | 100 | .PHONY=bash
|
188 | 101 | bash:
|
189 |
| - @docker run -it --rm --network delphi-net \ |
190 |
| - $(M1) \ |
191 |
| - --mount type=bind,source=$(CWD)repos/delphi/delphi-epidata,target=/usr/src/app/repos/delphi/delphi-epidata,readonly \ |
192 |
| - --mount type=bind,source=$(CWD)repos/delphi/delphi-epidata/src,target=/usr/src/app/delphi/epidata,readonly \ |
193 |
| - --env "SQLALCHEMY_DATABASE_URI=$(sqlalchemy_uri)" \ |
194 |
| - --env "FLASK_SECRET=abc" \ |
195 |
| - delphi_web_python bash |
| 102 | + @SQLALCHEMY_DATABASE_URI=$(sqlalchemy_uri) docker compose run delphi_web_python $(M1) bash |
196 | 103 |
|
197 | 104 | .PHONY=sql
|
198 | 105 | sql:
|
199 | 106 | @docker run --rm -it --network delphi-net --cap-add=sys_nice \
|
200 | 107 | percona mysql --user=user --password=pass --port 3306 --host delphi_database_epidata epidata
|
201 | 108 |
|
| 109 | +.PHONY=down |
| 110 | +down: |
| 111 | + @docker compose down |
| 112 | + |
| 113 | +.PHONY=down-force-rebuild |
| 114 | +down-force-rebuild: |
| 115 | + @docker compose down --rmi all --volumes |
| 116 | + @docker compose up --build --force-recreate --detach |
| 117 | + |
202 | 118 | .PHONY=clean
|
203 | 119 | clean:
|
204 | 120 | @docker images -f "dangling=true" -q | xargs docker rmi >/dev/null 2>&1
|
0 commit comments