forked from isaacphysics/isaac-react-app
-
Notifications
You must be signed in to change notification settings - Fork 0
/
compose-live
executable file
·105 lines (93 loc) · 3.59 KB
/
compose-live
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
#!/bin/bash
# Fail on error, so this script can be chained safely:
set -e
# Need at least three args and the first argument to be the site:
if [ $# -lt 3 ] || ! { [ $1 = "cs" ] || [ $1 = "phy" ]; }; then
echo "Usage: compose-live [cs|phy] [APP_VERSION] [DOCKER_ARGS]..."
exit 1
fi
# Extract args:
SITE=$1
APP_VERSION=$2
ENV=live
# We're done with the first two args. The remainder will be passed to docker-compose:
shift 2
# 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
docker pull docker.isaacscience.org/isaac-$SITE-app-renderer:$APP_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=$SITE-pg-$ENV
ES_CONTAINER=$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: unless-stopped
networks:
default:
aliases:
- $SITE-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
external_links:
- $PG_CONTAINER:postgres
- $ES_CONTAINER: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: isaac-$SITE-api-$ENV
$SITE-renderer:
container_name: $SITE-renderer
image: docker.isaacscience.org/isaac-$SITE-app-renderer:$APP_VERSION
restart: unless-stopped
networks:
default:
external:
name: isaac
EOF
exit 0