This repository has been archived by the owner on May 9, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
/
compose
executable file
·113 lines (102 loc) · 3.59 KB
/
compose
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
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
#!/bin/bash
if [ $# -eq 0 ]
then
echo "Usage: compose [dev|staging|test] VERSION"
exit 1
fi
ENV=$1
APP_VERSION=$2
if [ $2 = "dev" ] || [ $2 = "staging" ] || [ $2 = "test" ] || [ $2 = "live" ]; then
echo "Environment is now first argument to this script. Sorry James."
echo "Usage: compose [dev|staging|test] VERSION"
exit 1
fi
shift 2
if [ $1 = "create" ] || [ $1 = "exec" ] || [ $1 = "pull" ] || [ $1 = "push" ] || [ $1 = "run" ] || [ $1 = "start" ] || [ $1 = "up" ]; then
docker pull docker.isaacscience.org/isaac-app:$APP_VERSION
API_VERSION=`docker inspect -f '{{.Config.Labels.apiVersion}}' docker.isaacscience.org/isaac-app:$APP_VERSION`
docker pull docker.isaacscience.org/isaac-api:$API_VERSION
else
API_VERSION=`docker inspect -f '{{.Config.Labels.apiVersion}}' docker.isaacscience.org/isaac-app:$APP_VERSION`
fi
API_NAME=phy-api-$ENV-$API_VERSION
APP_NAME=phy-app-$ENV-$APP_VERSION
# Define the Postgres YML. Note that when ENV is "test" an additional volume line is appended to the end!
read -r -d '' PG_SERVICE << EOM
phy-pg-$ENV:
container_name: phy-pg-$ENV
restart: unless-stopped
image: postgres:12
environment:
POSTGRES_USER: rutherford
POSTGRES_PASSWORD: rutherf0rd
volumes:
- phy-pg-$ENV:/var/lib/postgresql/data
- ../isaac-api/src/main/resources/db_scripts/postgres-rutherford-create-script.sql:/docker-entrypoint-initdb.d/00-isaac-create.sql:ro
- ../isaac-api/src/main/resources/db_scripts/postgres-rutherford-functions.sql:/docker-entrypoint-initdb.d/01-isaac-functions.sql:ro
- ../isaac-api/src/main/resources/db_scripts/quartz_scheduler_create_script.sql:/docker-entrypoint-initdb.d/02-isaac-quartz.sql:ro
EOM
if [ "$ENV" == "dev" ]; then
: # Continue
elif [ "$ENV" == "staging" ]; then
: # Continue
elif [ "$ENV" == "live" ]; then
echo "Cannot manage live deployment with this script any more. Please use compose-live."
exit 1
elif [ "$ENV" == "test" ]; then
# Need to add the SQL script that loads the test data to pg-test:
TEST_INIT_DATA=" - /local/data/test-phy-db-schema.sql:/docker-entrypoint-initdb.d/test-db-schema.sql"
PG_SERVICE="$PG_SERVICE"$'\n'"$TEST_INIT_DATA"
else
echo "Must set environment to dev, staging or test"
exit 1
fi
cat << EOF | docker-compose -p dc-$APP_NAME -f - $@
version: '2'
services:
$APP_NAME:
container_name: $APP_NAME
image: docker.isaacscience.org/isaac-app:$APP_VERSION
restart: unless-stopped
networks:
default:
aliases:
- phy-app-$ENV
$API_NAME:
container_name: $API_NAME
image: docker.isaacscience.org/isaac-api:$API_VERSION
restart: unless-stopped
extra_hosts:
- local-smtp:$LOCAL_SMTP
links:
- phy-pg-$ENV:postgres
external_links:
- phy-elasticsearch-live:elasticsearch
environment:
- SEGUE_CONFIG_LOCATION=/local/data/conf/segue-config.properties
- JAVA_OPTIONS=-Dlog.path=/isaac-logs -Dsegue.version=$API_VERSION
volumes:
- /local/data/m2:/root/.m2:rw
- /local/data/isaac-config/phy/segue-config.$ENV.properties:/local/data/conf/segue-config.properties:ro
- /local/data/rutherford-content:/local/data/rutherford-content:rw
- /local/data/keys:/local/data/keys:ro
- /local/data/school_list_2019.csv:/local/data/school_list_2019.csv:ro
- /var/log/isaac/phy-$ENV:/isaac-logs:rw
networks:
default:
aliases:
- phy-api-$ENV-any
logging:
driver: journald
options:
tag: phy-isaac-api-$ENV
$PG_SERVICE
networks:
default:
external:
name: isaac
volumes:
phy-pg-$ENV:
external: true
EOF
exit 0