-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
added script for deployment to prompt for db readiness
- Loading branch information
Showing
1 changed file
with
20 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
import os | ||
import pymongo | ||
import sys | ||
|
||
mongo_host = os.environ.get('MONGO_HOST') | ||
mongo_port = os.environ.get('MONGO_PORT') | ||
mongo_user = os.environ.get('MONGO_USER') | ||
mongo_pass = os.environ.get('MONGO_PASSWORD') | ||
|
||
|
||
try: | ||
client = pymongo.MongoClient(f'mongodb://{mongo_user}:{mongo_pass}@{mongo_host}:{mongo_port}/') | ||
|
||
client.server_info() | ||
print(f"Connection à MongoDB réussie sur {mongo_host}:{mongo_port}") | ||
sys.exit(0) | ||
|
||
except Exception as e: | ||
# En cas d'erreur, imprimez l'erreur (optionnel) et sortez avec un code de sortie 1 | ||
print(f"Erreur lors de la connexion à MongoDB : {e}") |