This repository has been archived by the owner on Jun 6, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
scripts/prod/start: add full build & running process
- Loading branch information
1 parent
d7d4b21
commit 1459fdc
Showing
1 changed file
with
43 additions
and
5 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 |
---|---|---|
@@ -1,9 +1,47 @@ | ||
echo "Running master image..." | ||
# TODO Use env vars for ports instead of hard-written values. | ||
|
||
ENV_FILE="$PWD/.env" | ||
BLUE="\033[0;34m" | ||
GREEN="\033[0;32m" | ||
NC='\033[0m' | ||
|
||
# Load .env file variables if the file exists: | ||
echo $ENV_FILE | ||
if [ -f $ENV_FILE ] | ||
then | ||
echo "${GREEN}> Exporting .env file variables...${NC}" | ||
export $(cat $ENV_FILE | xargs) | ||
fi | ||
|
||
echo "${GREEN}> Stopping all existing containers...${NC}" | ||
docker stop $(docker ps -a -q) > /dev/null | ||
|
||
echo "${GREEN}> Starting master (and db) image...${NC}" | ||
docker-compose up -d master > /dev/null | ||
|
||
echo "Waiting for db image to start..." | ||
# Wait for the 5432 port to be used (= "db" image is running and ready): | ||
while ! lsof -Pi :5432 -sTCP:LISTEN -t; do sleep 1; done > /dev/null | ||
echo "${GREEN}> Waiting for db image to start...${NC}" | ||
while ! lsof -Pi :$DB_PORT -sTCP:LISTEN -t; do sleep 1; done > /dev/null | ||
|
||
echo "Migrating database structure..." | ||
echo "${GREEN}> Migrating database structure...${NC}" | ||
docker-compose exec master yarn db:migrate > /dev/null | ||
|
||
echo "${GREEN}> Stopping master image...${NC}" | ||
docker-compose stop master > /dev/null | ||
echo "${GREEN}> Stopping db image...${NC}" | ||
docker-compose stop db > /dev/null | ||
|
||
echo "${GREEN}> Starting api (and db) image...${NC}" | ||
docker-compose up -d api > /dev/null | ||
|
||
echo "${GREEN}> Waiting for api image to start...${NC}" | ||
while ! lsof -Pi :$API_PORT -sTCP:LISTEN -t; do sleep 1; done > /dev/null | ||
|
||
echo "${GREEN}> Starting web image...${NC}" | ||
docker-compose up -d web > /dev/null | ||
|
||
echo "${GREEN}> Waiting for web image to start...${NC}" | ||
while ! lsof -Pi :$WEB_PORT -sTCP:LISTEN -t; do sleep 1; done > /dev/null | ||
|
||
echo "${BLUE}The server is up:" | ||
echo "- api is running on port $API_PORT" | ||
echo "- web is running on port $WEB_PORT${NC}" |