forked from gofireflyio/terraform-firefly-aws-onboarding
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpost_release.py
55 lines (49 loc) · 1.75 KB
/
post_release.py
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
import os
from pymongo import MongoClient
from pymongo.database import Database
from pymongo.collection import Collection
collection_name = "fireflyReleases"
document_name = "firefly_aws_terraform_module_latest"
def write_relase(mongo_uri: str, release_tag: str):
try:
mongo_client: MongoClient = MongoClient(mongo_uri)
mongo_db: Database = mongo_client.get_database("infralight")
collection: Collection = mongo_db.get_collection(collection_name)
except Exception as ex:
print("Could not connect to MongoDB")
raise ex
try:
collection.update_one({'name': document_name}, {"$set": {'tag': release_tag}}, upsert=True)
cursor = collection.find()
for record in cursor:
print(record)
except Exception as ex:
raise ex
finally:
mongo_client.close()
def main():
release_tag = os.getenv("TAG")
print(release_tag)
if release_tag:
try:
prod_mongo_uri = os.getenv("PROD_MONGO_URI")
if prod_mongo_uri:
write_relase(prod_mongo_uri, release_tag)
else:
print("prod mongo uri is empty")
except Exception as ex:
print("Could not updates releases to MongoDB")
raise ex
# try:
# stag_mongo_uri = os.getenv("STAG_MONGO_URI")
# if stag_mongo_uri:
# write_relase(stag_mongo_uri, release_tag)
# else:
# print("stag mongo uri is empty")
# except Exception as ex:
# print("Could not updates releases to MongoDB")
# raise ex
else:
print("release tag is empty")
if __name__ == '__main__':
main()