Skip to content

Commit db9b844

Browse files
authored
Merge pull request #176 from mapswipe/dev
deployment
2 parents 905583f + 9feb195 commit db9b844

File tree

3 files changed

+121
-35
lines changed

3 files changed

+121
-35
lines changed

deploy.sh

Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,88 @@
11
git pull
2+
if [[ $? = 0 ]]; then
3+
echo "success"
4+
else
5+
echo "failure: $?"
6+
exit
7+
fi
8+
29
python3 test_config.py
10+
if [[ $? = 0 ]]; then
11+
echo "success"
12+
else
13+
echo "failure: $?"
14+
exit
15+
fi
16+
317
docker-compose build --no-cache postgres
18+
if [[ $? = 0 ]]; then
19+
echo "success"
20+
else
21+
echo "failure: $?"
22+
exit
23+
fi
24+
425
docker-compose build --no-cache firebase_deploy
26+
if [[ $? = 0 ]]; then
27+
echo "success"
28+
else
29+
echo "failure: $?"
30+
exit
31+
fi
32+
533
docker-compose build --no-cache mapswipe_workers
34+
if [[ $? = 0 ]]; then
35+
echo "success"
36+
else
37+
echo "failure: $?"
38+
exit
39+
fi
40+
641
docker-compose build --no-cache manager_dashboard
42+
if [[ $? = 0 ]]; then
43+
echo "success"
44+
else
45+
echo "failure: $?"
46+
exit
47+
fi
48+
749
docker-compose build --no-cache nginx
50+
if [[ $? = 0 ]]; then
51+
echo "success"
52+
else
53+
echo "failure: $?"
54+
exit
55+
fi
56+
857
docker-compose build --no-cache api
58+
if [[ $? = 0 ]]; then
59+
echo "success"
60+
else
61+
echo "failure: $?"
62+
exit
63+
fi
64+
965
docker-compose up -d --force-recreate postgres firebase_deploy mapswipe_workers manager_dashboard nginx api
66+
if [[ $? = 0 ]]; then
67+
echo "success"
68+
else
69+
echo "failure: $?"
70+
exit
71+
fi
72+
1073
docker logs firebase_deploy
74+
if [[ $? = 0 ]]; then
75+
echo "success"
76+
else
77+
echo "failure: $?"
78+
exit
79+
fi
80+
1181
docker ps -a
82+
if [[ $? = 0 ]]; then
83+
echo "success"
84+
else
85+
echo "failure: $?"
86+
exit
87+
fi
88+

mapswipe_workers/mapswipe_workers/firebase_to_postgres/update_data.py

Lines changed: 35 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -47,40 +47,41 @@ def update_user_data(user_ids=None):
4747
users[user_id] = user
4848
logger.info(f"added user {user_id}")
4949

50-
for user_id, user in users.items():
51-
# Convert timestamp (ISO 8601) from string to a datetime object.
52-
try:
53-
created = dt.datetime.strptime(
54-
user['created'].replace('Z', ''),
55-
'%Y-%m-%dT%H:%M:%S.%f'
56-
)
57-
except KeyError:
58-
# if user has no "created" attribute, we set it to current time
59-
created = dt.datetime.utcnow().isoformat()[0:-3]+'Z'
60-
logger.info(f"user {user_id} didn't have a created attribute set it to {created}")
61-
62-
try:
63-
username = user['username']
64-
except KeyError:
65-
# if user has no "username" attribute, we set it to None
66-
username = None
67-
logger.info(f"user {user_id} didn't have a created attribute set it to {username}")
68-
69-
query_update_user = '''
70-
INSERT INTO users (user_id, username, created)
71-
VALUES(%s, %s, %s)
72-
ON CONFLICT (user_id) DO UPDATE
73-
SET username=%s,
74-
created=%s;
75-
'''
76-
data_update_user = [
77-
user_id,
78-
username,
79-
created,
80-
username,
81-
created,
82-
]
83-
pg_db.query(query_update_user, data_update_user)
50+
if users:
51+
for user_id, user in users.items():
52+
# Convert timestamp (ISO 8601) from string to a datetime object.
53+
try:
54+
created = dt.datetime.strptime(
55+
user['created'].replace('Z', ''),
56+
'%Y-%m-%dT%H:%M:%S.%f'
57+
)
58+
except KeyError:
59+
# if user has no "created" attribute, we set it to current time
60+
created = dt.datetime.utcnow().isoformat()[0:-3]+'Z'
61+
logger.info(f"user {user_id} didn't have a created attribute set it to {created}")
62+
63+
try:
64+
username = user['username']
65+
except KeyError:
66+
# if user has no "username" attribute, we set it to None
67+
username = None
68+
logger.info(f"user {user_id} didn't have a created attribute set it to {username}")
69+
70+
query_update_user = '''
71+
INSERT INTO users (user_id, username, created)
72+
VALUES(%s, %s, %s)
73+
ON CONFLICT (user_id) DO UPDATE
74+
SET username=%s,
75+
created=%s;
76+
'''
77+
data_update_user = [
78+
user_id,
79+
username,
80+
created,
81+
username,
82+
created,
83+
]
84+
pg_db.query(query_update_user, data_update_user)
8485

8586
del(pg_db)
8687

test_config.py

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -143,6 +143,14 @@ def test_manager_dashboard_config():
143143

144144

145145
def test_nginx_config():
146+
file_path = '.env'
147+
148+
with open(file_path, 'r') as f:
149+
env_variables = f.read()
150+
151+
assert 'SERVER_NAME' in env_variables, \
152+
f"you didn't set a SERVER_NAME in {file_path}"
153+
146154
file_path = 'nginx/nginx.conf'
147155
assert os.path.isfile(file_path), \
148156
f"you didn't set up config file: {file_path}"
@@ -153,7 +161,7 @@ def test_nginx_config():
153161
assert 'server_name' in nginx_config, \
154162
f"you didn't set server_name in: {file_path}"
155163

156-
# TODO: get server name from nginx config file
164+
# TODO: get server name from nginx config file or .env
157165
server_name = 'dev.mapswipe.org'
158166

159167
file_path = f'/etc/letsencrypt/live/{server_name}/fullchain.pem'

0 commit comments

Comments
 (0)