forked from isaacphysics/isaac-react-app
-
Notifications
You must be signed in to change notification settings - Fork 0
/
compose
executable file
·124 lines (111 loc) · 4.55 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
114
115
116
117
118
119
120
121
122
123
124
#!/bin/bash
# Fail on error, so this script can be chained safely:
set -e
# Cannot manage live deployment with the script!
if [ "$2" == "live" ]; then
echo "Cannot manage live deployment with this script any more. Please use ./compose-live"
exit 1
fi
# Need at least four args and the first argument to be the site:
if [ $# -lt 4 ] || ! { [ $1 = "cs" ] || [ $1 = "phy" ]; } || ! { [ $2 = "dev" ] || [ $2 = "staging" ] || [ $2 = "test" ]; } ; then
echo "Usage: compose [cs|phy] [staging|dev|test] [APP_VERSION] [DOCKER_ARGS]..."
exit 1
fi
# Extract args:
SITE=$1
ENV=$2
APP_VERSION=$3
# We're done with the first three args. The remainder will be passed to docker-compose:
shift 3
# Use the app image to find the correct API version to use:
if [ $1 = "create" ] || [ $1 = "pull" ] || [ $1 = "push" ] || [ $1 = "run" ] || [ $1 = "start" ] || [ $1 = "up" ]; then
# This will cause new containers or should update containers, so pull newer images if possible:
docker pull docker.isaacscience.org/isaac-$SITE-app:$APP_VERSION
API_VERSION=$(docker inspect -f '{{.Config.Labels.apiVersion}}' docker.isaacscience.org/isaac-$SITE-app:$APP_VERSION)
docker pull docker.isaacscience.org/isaac-api:$API_VERSION
elif [ $1 = "down" ] || [ $1 = "stop" ] || [ $1 = "restart" ] || [ $1 = "exec" ] || [ $1 = "config" ] || [ $1 = "logs" ] || [ $1 = "kill" ] || [ $1 = "ps" ]; then
# This affects existing containers, so don't pull newer images:
API_VERSION=$(docker inspect -f '{{.Config.Labels.apiVersion}}' docker.isaacscience.org/isaac-$SITE-app:$APP_VERSION)
else
# This might not be a docker-compose operation. If it is, it could be added above to the correct branch.
echo "Error: Unsupported docker-compose operation '$1'!"
exit 1
fi
# Ensure we actually _have_ an API_VERSION before we continue, though the "set -e" might avoid this:
if [ -z $API_VERSION ]; then
echo "Error: Cannot extract API version from APP image!"
exit 1
fi
API_NAME=$SITE-api-$ENV-$API_VERSION
APP_NAME=$SITE-app-$ENV-$APP_VERSION
PG_CONTAINER_NAME=$SITE-pg-$ENV
ES_CONTAINER_NAME=$SITE-elasticsearch-live
# The content repo is named differently for both sites in a non-standard way:
if [ "$SITE" == "cs" ]; then
CONTENT_REPO="cs-content"
elif [ "$SITE" == "phy" ]; then
CONTENT_REPO="rutherford-content"
fi
docker-compose -p dc-$APP_NAME -f - $@ << EOF
version: '2'
services:
$APP_NAME:
container_name: $APP_NAME
image: docker.isaacscience.org/isaac-$SITE-app:$APP_VERSION
restart: "no"
networks:
default:
aliases:
- $SITE-app-$ENV
$API_NAME:
container_name: $API_NAME
image: docker.isaacscience.org/isaac-api:$API_VERSION
restart: "no"
extra_hosts:
- local-smtp:$LOCAL_SMTP
links:
- $PG_CONTAINER_NAME:postgres
external_links:
- $ES_CONTAINER_NAME: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/$SITE/segue-config.$ENV.properties:/local/data/conf/segue-config.properties:ro
- /local/data/$CONTENT_REPO:/local/data/$CONTENT_REPO:rw
- /local/data/keys:/local/data/keys:ro
- /local/data/school_list_2019.csv:/local/data/school_list_2019.csv:ro
- /local/data/school_list_2022.csv:/local/data/school_list_2022.csv:ro
- /var/log/isaac/$SITE-$ENV:/isaac-logs:rw
networks:
default:
aliases:
- $SITE-api-$ENV-any
logging:
driver: journald
options:
tag: $SITE-isaac-api-$ENV
$PG_CONTAINER_NAME:
container_name: $PG_CONTAINER_NAME
restart: "no"
image: postgres:13
environment:
POSTGRES_USER: rutherford
POSTGRES_PASSWORD: rutherf0rd
volumes:
- $PG_CONTAINER_NAME:/var/lib/postgresql/data
- /local/src/isaac-api/src/main/resources/db_scripts/postgres-rutherford-create-script.sql:/docker-entrypoint-initdb.d/00-isaac-create.sql:ro
- /local/src/isaac-api/src/main/resources/db_scripts/postgres-rutherford-functions.sql:/docker-entrypoint-initdb.d/01-isaac-functions.sql:ro
- /local/src/isaac-api/src/main/resources/db_scripts/quartz_scheduler_create_script.sql:/docker-entrypoint-initdb.d/02-isaac-quartz.sql:ro
# The initialisation for the test DB, which is ignored with non-empty database volumes anyway:
- /local/data/test-$SITE-db-schema.sql:/docker-entrypoint-initdb.d/99-test-db-schema.sql:ro
networks:
default:
external:
name: isaac
volumes:
$PG_CONTAINER_NAME:
external: true
EOF
exit 0