Skip to content

Add a temporary script for deploying sci sites #1549

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
117 changes: 9 additions & 108 deletions compose
Original file line number Diff line number Diff line change
Expand Up @@ -5,120 +5,21 @@ 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"
echo "Cannot manage live deployment with this script. 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 = "phy" ]; } || ! { [ $2 = "dev" ] || [ $2 = "staging" ] || [ $2 = "test" ]; } ; then
echo "Usage: compose [ada|phy] [staging|dev|test] [APP_VERSION] [DOCKER_ARGS]..."
if [ $# -lt 4 ] || ! { [ "$1" = "ada" ] || [ "$1" = "phy" ] || [ "$1" = "sci" ]; } || ! { [ "$2" = "dev" ] || [ "$2" = "staging" ] || [ "$2" = "test" ]; } ; then
echo "Usage: compose [ada|phy|sci] [staging|dev|test] [APP_VERSION] [DOCKER_ARGS]..."
exit 1
fi

DOCKER_REPO=ghcr.io/isaacphysics
# Delegate to the correct script:
if { [ "$1" = "ada" ] || [ "$1" = "phy" ]; } ; then
./compose-dev "$@"

# 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_REPO/isaac-$SITE-app:$APP_VERSION
API_VERSION=$(docker inspect -f '{{.Config.Labels.apiVersion}}' $DOCKER_REPO/isaac-$SITE-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
elif [ "$1" = "sci" ]; then
shift 1
./compose-sci "$@"
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" == "ada" ]; then
CONTENT_REPO="ada-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_REPO/isaac-$SITE-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: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
124 changes: 124 additions & 0 deletions compose-dev
Original file line number Diff line number Diff line change
@@ -0,0 +1,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 = "ada" ] || [ $1 = "phy" ]; } || ! { [ $2 = "dev" ] || [ $2 = "staging" ] || [ $2 = "test" ]; } ; then
echo "Usage: compose [ada|phy] [staging|dev|test] [APP_VERSION] [DOCKER_ARGS]..."
exit 1
fi

DOCKER_REPO=ghcr.io/isaacphysics

# 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_REPO/isaac-$SITE-app:$APP_VERSION
API_VERSION=$(docker inspect -f '{{.Config.Labels.apiVersion}}' $DOCKER_REPO/isaac-$SITE-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-live

# The content repo is named differently for both sites in a non-standard way:
if [ "$SITE" == "ada" ]; then
CONTENT_REPO="ada-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_REPO/isaac-$SITE-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: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
94 changes: 94 additions & 0 deletions compose-sci
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
#!/bin/bash

# FIXME: TEMPORARY deployment script for sci whilst it shares phy databases!

# Fail on error, so this script can be chained safely:
set -e

# Need at least three args and the first argument to be the environment:
if [ $# -lt 3 ] || ! { [ $1 = "dev" ] || [ $1 = "staging" ] || [ $1 = "test" ]; } ; then
echo "Usage: ./compose-sci [staging|dev|test] [APP_VERSION] [DOCKER_ARGS]..."
exit 1
fi

DOCKER_REPO=ghcr.io/isaacphysics

# Extract args:
ENV=$1
APP_VERSION=$2
# 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_REPO/isaac-phy-app:$APP_VERSION
API_VERSION=$(docker inspect -f '{{.Config.Labels.apiVersion}}' $DOCKER_REPO/isaac-phy-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}}' $DOCKER_REPO/isaac-phy-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=sci-api-$ENV-$API_VERSION
APP_NAME=sci-app-$ENV-$APP_VERSION
PG_CONTAINER_NAME=phy-pg-$ENV
ES_CONTAINER_NAME=phy-elasticsearch-live
CONTENT_REPO="rutherford-content"

docker compose -p dc-${APP_NAME//./-} -f - $@ << EOF
services:
$APP_NAME:
container_name: $APP_NAME
image: $DOCKER_REPO/isaac-phy-app:$APP_VERSION
restart: "no"
networks:
default:
aliases:
- sci-app-$ENV
$API_NAME:
container_name: $API_NAME
image: $DOCKER_REPO/isaac-api:$API_VERSION
restart: "no"
extra_hosts:
- local-smtp:$LOCAL_SMTP
external_links:
- $ES_CONTAINER_NAME:elasticsearch
- $PG_CONTAINER_NAME:postgres
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/sci:/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/sci-$ENV:/isaac-logs:rw
networks:
default:
aliases:
- sci-api-$ENV-any
logging:
driver: journald
options:
tag: sci-isaac-api-$ENV
networks:
default:
name: isaac
external: true
EOF

exit 0