forked from logto-io/logto
-
Notifications
You must be signed in to change notification settings - Fork 0
/
run-logto-remote.sh
80 lines (65 loc) · 1.96 KB
/
run-logto-remote.sh
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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
#!/bin/bash
if [ -z "$AWS_PROFILE" ]; then
echo "AWS_PROFILE environment variable is not set. Exiting..."
exit 1
fi
print_in_green() {
GREEN='\033[0;32m'
NC='\033[0m'
echo -e "${GREEN}$1${NC}"
}
print_in_blue() {
BLUE='\033[0;34m'
NC='\033[0m'
echo -e "${BLUE}$1${NC}"
}
print_in_red() {
RED='\033[0;31m'
NC='\033[0m'
echo -e "${RED}$1${NC}"
}
DOCKER_COMPOSE_FILE=${1:-docker-compose-ogcio-logto.yml}
if [ ! -f "$DOCKER_COMPOSE_FILE" ]; then
echo "Docker Compose file not found!"
exit 1
fi
aws_ecr_login() {
print_in_blue "Logging in to AWS ECR..."
aws sso login --profile $AWS_PROFILE
if [ $? -ne 0 ]; then
print_in_red "AWS SSO login failed. Exiting..."
exit 1
fi
aws ecr get-login-password --region eu-west-1 --profile $AWS_PROFILE | docker login --username AWS --password-stdin 730335224023.dkr.ecr.eu-west-1.amazonaws.com
if [ $? -ne 0 ]; then
print_in_red "Docker login to ECR failed. Exiting..."
exit 1
fi
}
create_docker_network() {
NETWORK_NAME="logto_network"
if ! docker network ls | grep -q "$NETWORK_NAME"; then
print_in_blue "Creating Docker network '$NETWORK_NAME'..."
docker network create $NETWORK_NAME
if [ $? -ne 0 ]; then
print_in_red "Failed to create Docker network '$NETWORK_NAME'. Exiting..."
exit 1
fi
else
print_in_blue "Docker network '$NETWORK_NAME' already exists."
fi
}
docker-compose -f "$DOCKER_COMPOSE_FILE" down
create_docker_network
docker-compose -f "$DOCKER_COMPOSE_FILE" up --detach
if [ $? -ne 0 ]; then
print_in_blue "docker-compose up failed. Trying to log in to AWS ECR..."
aws_ecr_login
print_in_blue "Retrying docker-compose up..."
docker-compose -f "$DOCKER_COMPOSE_FILE" up --detach
if [ $? -ne 0 ]; then
print_in_red "docker-compose up failed again. Exiting..."
exit 1
fi
fi
print_in_green "docker-compose up succeeded."