Skip to content

Commit a84f09c

Browse files
committed
Add a version check for Frontend
1 parent 323b66d commit a84f09c

File tree

5 files changed

+43
-0
lines changed

5 files changed

+43
-0
lines changed

ch11/microservices/frontend/docker/app/Dockerfile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ RUN apk add --update python3 curl libffi postgresql-libs
3939
RUN mkdir -p /opt/uwsgi
4040
ADD docker/app/uwsgi.ini /opt/uwsgi/
4141
ADD docker/app/start_server.sh /opt/uwsgi/
42+
ADD docker/app/check_dependencies_services.py /opt/uwsgi/
4243

4344
# Create a user to run the service
4445
RUN addgroup -S uwsgi
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
import os
2+
import requests
3+
from natsort import natsorted
4+
5+
6+
VERSIONS = {
7+
'thoughts_backend': (f'{os.environ["USER_BACKEND_URL"]}/admin/version/',
8+
'v2.4'),
9+
}
10+
11+
12+
def check_version(min_version, version):
13+
versions = natsorted([min_version, version])
14+
# Return the lower is the minimum version
15+
return versions[0] == min_version
16+
17+
18+
def main():
19+
for service, (url, min_version) in VERSIONS.items():
20+
print(f'Checking minimum version for {service}')
21+
resp = requests.get(url)
22+
if resp.status_code != 200:
23+
print(f'Error connecting to {url}: {resp}')
24+
exit(-1)
25+
26+
result = resp.json()
27+
version = result['version']
28+
print(f'Minimum {min_version}, found {version}')
29+
if not check_version(min_version, version):
30+
msg = f'Version {version} is incorrect (min {min_version})'
31+
print(msg)
32+
exit(-1)
33+
34+
35+
if __name__ == '__main__':
36+
main()

ch11/microservices/frontend/docker/app/start_server.sh

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
#!/bin/sh
2+
set -e
23

34
_term() {
45
echo "Caught SIGTERM signal! Sending graceful stop to uWSGI through the master-fifo"
@@ -10,6 +11,8 @@ _term() {
1011

1112
trap _term SIGTERM
1213

14+
python3 /opt/uwsgi/check_dependencies_services.py
15+
1316
uwsgi --ini /opt/uwsgi/uwsgi.ini &
1417

1518
# We need to wait to properly catch the signal, that's why uWSGI is started
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,4 @@
1+
# Remember to tweak this parameters to point to your IP, as
2+
# describred in Chapter 6: Implementing multiple services
13
THOUGHTS_BACKEND_URL=http://10.0.10.5:8000
24
USER_BACKEND_URL=http://10.0.10.5:8001

ch11/microservices/frontend/requirements.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,3 +5,4 @@ requests==2.22.0
55
bcrypt==3.1.7
66
cryptography==2.6.1
77
django-prometheus==1.0.15
8+
natsort==6.0.0

0 commit comments

Comments
 (0)