generated from ExamProCo/aws-bootcamp-cruddur-2023
-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
restructure scripts and configure env vars
- Loading branch information
Beici Liang
committed
Apr 3, 2023
1 parent
c81f3b5
commit e2c6512
Showing
40 changed files
with
306 additions
and
51 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 +1,3 @@ | ||
docker/**/* | ||
docker/**/* | ||
frontend-react-js/build/* | ||
*.env |
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
This file was deleted.
Oops, something went wrong.
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,12 @@ | ||
#! /usr/bin/bash | ||
|
||
ABS_PATH=$(readlink -f "$0") | ||
BACKEND_PATH=$(dirname $ABS_PATH) | ||
BIN_PATH=$(dirname $BACKEND_PATH) | ||
PROJECT_PATH=$(dirname $BIN_PATH) | ||
BACKEND_FLASK_PATH="$PROJECT_PATH/backend-flask" | ||
|
||
docker build \ | ||
-f "$BACKEND_FLASK_PATH/Dockerfile.prod" \ | ||
-t backend-flask-prod \ | ||
"$BACKEND_FLASK_PATH/." |
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,19 @@ | ||
#! /usr/bin/bash | ||
if [ -z "$1" ]; then | ||
echo "No TASK_ID argument supplied eg ./bin/ecs/connect-to-backend-flask 99b2f8953616495e99545e5a6066fbb5d" | ||
exit 1 | ||
fi | ||
TASK_ID=$1 | ||
|
||
CONTAINER_NAME=backend-flask | ||
|
||
echo "TASK ID : $TASK_ID" | ||
echo "Container Name: $CONTAINER_NAME" | ||
|
||
aws ecs execute-command \ | ||
--region $AWS_DEFAULT_REGION \ | ||
--cluster cruddur \ | ||
--task $TASK_ID \ | ||
--container $CONTAINER_NAME \ | ||
--command "/bin/bash" \ | ||
--interactive |
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,26 @@ | ||
#! /usr/bin/bash | ||
|
||
CLUSTER_NAME="cruddur" | ||
SERVICE_NAME="backend-flask" | ||
TASK_DEFINTION_FAMILY="backend-flask" | ||
|
||
|
||
LATEST_TASK_DEFINITION_ARN=$(aws ecs describe-task-definition \ | ||
--task-definition $TASK_DEFINTION_FAMILY \ | ||
--query 'taskDefinition.taskDefinitionArn' \ | ||
--output text) | ||
|
||
echo "TASK DEF ARN:" | ||
echo $LATEST_TASK_DEFINITION_ARN | ||
|
||
aws ecs update-service \ | ||
--cluster $CLUSTER_NAME \ | ||
--service $SERVICE_NAME \ | ||
--task-definition $LATEST_TASK_DEFINITION_ARN \ | ||
--force-new-deployment | ||
|
||
#aws ecs describe-services \ | ||
#--cluster $CLUSTER_NAME \ | ||
#--service $SERVICE_NAME \ | ||
#--query 'services[0].deployments' \ | ||
#--output table |
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,8 @@ | ||
#!/usr/bin/env ruby | ||
|
||
require 'erb' | ||
|
||
template = File.read 'erb/backend-flask.env.erb' | ||
content = ERB.new(template).result(binding) | ||
filename = "backend-flask.env" | ||
File.write(filename, content) |
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,7 @@ | ||
#! /usr/bin/bash | ||
|
||
ECR_BACKEND_FLASK_URL="$AWS_ACCOUNT_ID.dkr.ecr.$AWS_DEFAULT_REGION.amazonaws.com/backend-flask" | ||
echo $ECR_BACKEND_FLASK_URL | ||
|
||
docker tag backend-flask-prod:latest $ECR_BACKEND_FLASK_URL:latest | ||
docker push $ECR_BACKEND_FLASK_URL:latest |
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,12 @@ | ||
#! /usr/bin/bash | ||
|
||
ABS_PATH=$(readlink -f "$0") | ||
FRONTEND_PATH=$(dirname $ABS_PATH) | ||
BIN_PATH=$(dirname $FRONTEND_PATH) | ||
PROJECT_PATH=$(dirname $BIN_PATH) | ||
TASK_DEF_PATH="$PROJECT_PATH/aws/task-definitions/backend-flask.json" | ||
|
||
echo $TASK_DEF_PATH | ||
|
||
aws ecs register-task-definition \ | ||
--cli-input-json "file://$TASK_DEF_PATH" |
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,13 @@ | ||
#! /usr/bin/bash | ||
|
||
ABS_PATH=$(readlink -f "$0") | ||
BACKEND_PATH=$(dirname $ABS_PATH) | ||
BIN_PATH=$(dirname $BACKEND_PATH) | ||
PROJECT_PATH=$(dirname $BIN_PATH) | ||
ENVFILE_PATH="$PROJECT_PATH/backend-flask.env" | ||
|
||
docker run --rm \ | ||
--env-file $ENVFILE_PATH \ | ||
--network cruddur-net \ | ||
--publish 4567:4567 \ | ||
-it backend-flask-prod |
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
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,16 @@ | ||
#! /usr/bin/bash | ||
|
||
CYAN='\033[1;36m' | ||
NO_COLOR='\033[0m' | ||
LABEL="db-kill-all" | ||
printf "${CYAN}== ${LABEL}${NO_COLOR}\n" | ||
|
||
ABS_PATH=$(readlink -f "$0") | ||
DB_PATH=$(dirname $ABS_PATH) | ||
BIN_PATH=$(dirname $DB_PATH) | ||
PROJECT_PATH=$(dirname $BIN_PATH) | ||
BACKEND_FLASK_PATH="$PROJECT_PATH/backend-flask" | ||
kill_path="$BACKEND_FLASK_PATH/db/kill-all-connections.sql" | ||
echo $kill_path | ||
|
||
psql $CONNECTION_URL cruddur < $kill_path |
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
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
File renamed without changes.
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,16 @@ | ||
#! /usr/bin/bash | ||
set -e # stop if it fails at any point | ||
|
||
CYAN='\033[1;36m' | ||
NO_COLOR='\033[0m' | ||
LABEL="db-setup" | ||
printf "${CYAN}==== ${LABEL}${NO_COLOR}\n" | ||
|
||
ABS_PATH=$(readlink -f "$0") | ||
DB_PATH=$(dirname $ABS_PATH) | ||
|
||
source "$DB_PATH/drop" | ||
source "$DB_PATH/create" | ||
source "$DB_PATH/schema-load" | ||
source "$DB_PATH/seed" | ||
python "$DB_PATH/update_cognito_user_ids" |
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,17 @@ | ||
#!/usr/bin/env python3 | ||
|
||
import psycopg | ||
import os | ||
import sys | ||
|
||
connection_url = os.getenv("CONNECTION_URL") | ||
|
||
conn = None | ||
try: | ||
print('attempting connection') | ||
conn = psycopg.connect(connection_url) | ||
print("Connection successful!") | ||
except psycopg.Error as e: | ||
print("Unable to connect to the database:", e) | ||
finally: | ||
conn.close() |
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
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
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
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,3 @@ | ||
#! /usr/bin/bash | ||
|
||
aws ecr get-login-password --region $AWS_DEFAULT_REGION | docker login --username AWS --password-stdin "$AWS_ACCOUNT_ID.dkr.ecr.$AWS_DEFAULT_REGION.amazonaws.com" |
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,17 @@ | ||
#! /usr/bin/bash | ||
|
||
ABS_PATH=$(readlink -f "$0") | ||
FRONTEND_PATH=$(dirname $ABS_PATH) | ||
BIN_PATH=$(dirname $FRONTEND_PATH) | ||
PROJECT_PATH=$(dirname $BIN_PATH) | ||
FRONTEND_REACT_JS_PATH="$PROJECT_PATH/frontend-react-js" | ||
|
||
docker build \ | ||
--build-arg REACT_APP_BACKEND_URL="https://api.beici-demo.xyz" \ | ||
--build-arg REACT_APP_AWS_PROJECT_REGION="$AWS_DEFAULT_REGION" \ | ||
--build-arg REACT_APP_AWS_COGNITO_REGION="$AWS_DEFAULT_REGION" \ | ||
--build-arg REACT_APP_AWS_USER_POOLS_ID="us-east-1_GN7uh5LmT" \ | ||
--build-arg REACT_APP_CLIENT_ID="3imco9n5ju2bngsltjdvfvnusl" \ | ||
-t frontend-react-js \ | ||
-f "$FRONTEND_REACT_JS_PATH/Dockerfile.prod" \ | ||
"$FRONTEND_REACT_JS_PATH/." |
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,19 @@ | ||
#! /usr/bin/bash | ||
if [ -z "$1" ]; then | ||
echo "No TASK_ID argument supplied eg ./bin/ecs/connect-to-frontend-react-js 99b2f8953616495e99545e5a6066fbb5d" | ||
exit 1 | ||
fi | ||
TASK_ID=$1 | ||
|
||
CONTAINER_NAME=frontend-react-js | ||
|
||
echo "TASK ID : $TASK_ID" | ||
echo "Container Name: $CONTAINER_NAME" | ||
|
||
aws ecs execute-command \ | ||
--region $AWS_DEFAULT_REGION \ | ||
--cluster cruddur \ | ||
--task $TASK_ID \ | ||
--container $CONTAINER_NAME \ | ||
--command "/bin/sh" \ | ||
--interactive |
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,19 @@ | ||
#! /usr/bin/bash | ||
|
||
CLUSTER_NAME="cruddur" | ||
SERVICE_NAME="frontend-react-js" | ||
TASK_DEFINTION_FAMILY="frontend-react-js" | ||
|
||
LATEST_TASK_DEFINITION_ARN=$(aws ecs describe-task-definition \ | ||
--task-definition $TASK_DEFINTION_FAMILY \ | ||
--query 'taskDefinition.taskDefinitionArn' \ | ||
--output text) | ||
|
||
echo "TASK DEF ARN:" | ||
echo $LATEST_TASK_DEFINITION_ARN | ||
|
||
aws ecs update-service \ | ||
--cluster $CLUSTER_NAME \ | ||
--service $SERVICE_NAME \ | ||
--task-definition $LATEST_TASK_DEFINITION_ARN \ | ||
--force-new-deployment |
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,8 @@ | ||
#!/usr/bin/env ruby | ||
|
||
require 'erb' | ||
|
||
template = File.read 'erb/frontend-react-js.env.erb' | ||
content = ERB.new(template).result(binding) | ||
filename = "frontend-react-js.env" | ||
File.write(filename, content) |
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,8 @@ | ||
#! /usr/bin/bash | ||
|
||
|
||
ECR_FRONTEND_REACT_URL="$AWS_ACCOUNT_ID.dkr.ecr.$AWS_DEFAULT_REGION.amazonaws.com/frontend-react-js" | ||
echo $ECR_FRONTEND_REACT_URL | ||
|
||
docker tag frontend-react-js:latest $ECR_FRONTEND_REACT_URL:latest | ||
docker push $ECR_FRONTEND_REACT_URL:latest |
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,12 @@ | ||
#! /usr/bin/bash | ||
|
||
ABS_PATH=$(readlink -f "$0") | ||
BACKEND_PATH=$(dirname $ABS_PATH) | ||
BIN_PATH=$(dirname $BACKEND_PATH) | ||
PROJECT_PATH=$(dirname $BIN_PATH) | ||
TASK_DEF_PATH="$PROJECT_PATH/aws/task-definitions/frontend-react-js.json" | ||
|
||
echo $TASK_DEF_PATH | ||
|
||
aws ecs register-task-definition \ | ||
--cli-input-json "file://$TASK_DEF_PATH" |
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,13 @@ | ||
#! /usr/bin/bash | ||
|
||
ABS_PATH=$(readlink -f "$0") | ||
BACKEND_PATH=$(dirname $ABS_PATH) | ||
BIN_PATH=$(dirname $BACKEND_PATH) | ||
PROJECT_PATH=$(dirname $BIN_PATH) | ||
ENVFILE_PATH="$PROJECT_PATH/frontend-react-js.env" | ||
|
||
docker run --rm \ | ||
--env-file $ENVFILE_PATH \ | ||
--network cruddur-net \ | ||
--publish 4567:4567 \ | ||
-it frontend-react-js-prod |
File renamed without changes.
Oops, something went wrong.