Skip to content

Commit

Permalink
deploy each env to its own directory
Browse files Browse the repository at this point in the history
  • Loading branch information
rikukissa committed Oct 1, 2024
1 parent 7f8de50 commit a002c75
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 13 deletions.
15 changes: 8 additions & 7 deletions infrastructure/deployment/deploy.sh
Original file line number Diff line number Diff line change
Expand Up @@ -208,12 +208,12 @@ generate_password() {

to_remote_paths() {
paths=$@
echo "$paths" | sed "s|/tmp/|/opt/opencrvs/infrastructure/|g" | sed "s|$INFRASTRUCTURE_DIRECTORY/docker-compose|/opt/opencrvs/infrastructure/docker-compose|g"
echo "$paths" | sed "s|/tmp/|/opt/opencrvs/$STACK/infrastructure/|g" | sed "s|$INFRASTRUCTURE_DIRECTORY/docker-compose|/opt/opencrvs/$STACK/infrastructure/docker-compose|g"
}

rotate_secrets() {
files_to_rotate=$(to_remote_paths $COMPOSE_FILES_USED)
configured_ssh '/opt/opencrvs/infrastructure/rotate-secrets.sh '$files_to_rotate' | tee -a '$LOG_LOCATION'/rotate-secrets.log'
configured_ssh '/opt/opencrvs/$STACK/infrastructure/rotate-secrets.sh '$files_to_rotate' | tee -a '$LOG_LOCATION'/rotate-secrets.log'
}


Expand Down Expand Up @@ -412,14 +412,15 @@ echo "Deploying COUNTRY_CONFIG_VERSION $COUNTRY_CONFIG_VERSION to $SSH_HOST..."
echo
echo "Syncing configuration files to the target server"

configured_rsync -rlD $PROJECT_ROOT/infrastructure $SSH_USER@$SSH_HOST:/opt/opencrvs/ --delete --no-perms --omit-dir-times --verbose
configured_rsync -rlD $PROJECT_ROOT/infrastructure $SSH_USER@$SSH_HOST:/opt/opencrvs/$STACK --delete --no-perms --omit-dir-times --verbose

echo "Logging to Dockerhub"

configured_ssh "docker login -u $DOCKER_USERNAME -p $DOCKER_TOKEN"


# Setup configuration files and compose file for the deployment domain
configured_ssh "/opt/opencrvs/infrastructure/setup-deploy-config.sh $HOST"
configured_ssh "/opt/opencrvs/$STACK/infrastructure/setup-deploy-config.sh $HOST $STACK"

rotate_secrets

Expand All @@ -436,7 +437,7 @@ if [ "$UPDATE_DEPENDENCIES" = true ]; then
echo 'Setting up elastalert indices'

while true; do
if configured_ssh "/opt/opencrvs/infrastructure/elasticsearch/setup-elastalert-indices.sh"; then
if configured_ssh "/opt/opencrvs/$STACK/infrastructure/elasticsearch/setup-elastalert-indices.sh"; then
break
fi
sleep 5
Expand All @@ -445,7 +446,7 @@ if [ "$UPDATE_DEPENDENCIES" = true ]; then
echo "Setting up Kibana config & alerts"

while true; do
if configured_ssh "HOST=kibana.$HOST /opt/opencrvs/infrastructure/monitoring/kibana/setup-config.sh"; then
if configured_ssh "HOST=kibana.$HOST /opt/opencrvs/$STACK/infrastructure/monitoring/kibana/setup-config.sh"; then
break
fi
sleep 5
Expand All @@ -454,7 +455,7 @@ else
echo 'Waiting for Elasticsearch to be ready'

while true; do
if configured_ssh "/opt/opencrvs/infrastructure/elasticsearch/wait-for-elasticsearch.sh"; then
if configured_ssh "/opt/opencrvs/$STACK/infrastructure/elasticsearch/wait-for-elasticsearch.sh"; then
break
fi
sleep 5
Expand Down
2 changes: 1 addition & 1 deletion infrastructure/monitoring/kibana/setup-config.sh
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ response_text_from_curl_output() {
}

curl_raw() {
docker run --rm -v /opt/opencrvs/infrastructure/monitoring/kibana/config.ndjson:/config.ndjson --network=dependencies_elasticsearch_net curlimages/curl -s -w "\n%{http_code}" "$@"
docker run --rm -v /opt/opencrvs/$STACK/infrastructure/monitoring/kibana/config.ndjson:/config.ndjson --network=dependencies_elasticsearch_net curlimages/curl -s -w "\n%{http_code}" "$@"
}

parse_url_from_string() {
Expand Down
10 changes: 5 additions & 5 deletions infrastructure/setup-deploy-config.sh
Original file line number Diff line number Diff line change
Expand Up @@ -10,20 +10,20 @@ set -e
echo

HOST=$1

STACK=$2
echo "Setting up deployment config for $HOST - `date --iso-8601=ns`"

# Set hostname in compose file
for file in /opt/opencrvs/infrastructure/docker-compose*.yml; do
for file in /opt/opencrvs/$STACK/infrastructure/docker-compose*.yml; do
sed -i "s/{{hostname}}/$HOST/g" "$file"
done

# Setup an encryption key for Kibana
KIBANA_ENCRYPTION_KEY=`uuidgen`
sed -i "s/{{KIBANA_ENCRYPTION_KEY}}/$KIBANA_ENCRYPTION_KEY/g" /opt/opencrvs/infrastructure/monitoring/kibana/kibana.yml
sed -i "s/{{KIBANA_ENCRYPTION_KEY}}/$KIBANA_ENCRYPTION_KEY/g" /opt/opencrvs/$STACK/infrastructure/monitoring/kibana/kibana.yml

sed -i -e "s%{{MINIO_ROOT_USER}}%$MINIO_ROOT_USER%" /opt/opencrvs/infrastructure/mc-config/config.json
sed -i -e "s%{{MINIO_ROOT_PASSWORD}}%$MINIO_ROOT_PASSWORD%" /opt/opencrvs/infrastructure/mc-config/config.json
sed -i -e "s%{{MINIO_ROOT_USER}}%$MINIO_ROOT_USER%" /opt/opencrvs/$STACK/infrastructure/mc-config/config.json
sed -i -e "s%{{MINIO_ROOT_PASSWORD}}%$MINIO_ROOT_PASSWORD%" /opt/opencrvs/$STACK/infrastructure/mc-config/config.json

echo "DONE - `date --iso-8601=ns`"
echo

0 comments on commit a002c75

Please sign in to comment.