-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathcompose
More file actions
executable file
·132 lines (116 loc) · 4.56 KB
/
compose
File metadata and controls
executable file
·132 lines (116 loc) · 4.56 KB
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
125
126
127
128
129
130
131
132
#!/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 = "ada" ] || [ $1 = "sci" ]; } || ! { [ $2 = "dev" ] || [ $2 = "staging" ] || [ $2 = "test" ]; } ; then
echo "Usage: compose [ada|sci] [staging|dev|test] [APP_VERSION] [DOCKER_ARGS]..."
exit 1
fi
DOCKER_REPO=ghcr.io/isaacphysics
# Extract args:
SITE=$1
SUBJECT=$1
ENV=$2
APP_VERSION=$3
# Whilst things are shared, some "sci" things are named "phy":
if [ "$SITE" == "sci" ]; then
SUBJECT="phy"
fi
# 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_REPO/isaac-$SUBJECT-app:$APP_VERSION
API_VERSION=$(docker inspect -f '{{.Config.Labels.apiVersion}}' $DOCKER_REPO/isaac-$SUBJECT-app:$APP_VERSION)
docker pull $DOCKER_REPO/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}}' $SITE-app-$ENV-$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-v8-live
# The content repo is named differently for both sites in a non-standard way:
if [ "$SUBJECT" == "ada" ]; then
CONTENT_REPO="ada-content"
elif [ "$SUBJECT" == "phy" ]; then
CONTENT_REPO="rutherford-content"
fi
docker compose -p dc-${APP_NAME//./-} -f - $@ << EOF
services:
$APP_NAME:
container_name: $APP_NAME
image: $DOCKER_REPO/isaac-$SUBJECT-app:$APP_VERSION
restart: "no"
networks:
default:
aliases:
- $SITE-app-$ENV
$API_NAME:
container_name: $API_NAME
image: $DOCKER_REPO/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/config/segue-config.dec.yaml
- JAVA_OPTIONS=-Dlog.path=/isaac-logs -Dsegue.version=$API_VERSION
volumes:
- /local/data/m2:/root/.m2:rw
- /local/data/isaac-sops-config-decrypted/$ENV/$SITE:/local/data/config:ro
- /local/data/$CONTENT_REPO:/local/data/$CONTENT_REPO:rw
- /local/data/maxmind-geolocation/geolite2-city.mmdb:/local/data/geolite2-city.mmdb: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:16
shm_size: 128M
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:
name: isaac
external: true
volumes:
$PG_CONTAINER_NAME:
name: $PG_CONTAINER_NAME
external: true
EOF
exit 0