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 32dd2e0
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 19 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/clear-environment.yml
Original file line number Diff line number Diff line change
Expand Up @@ -82,9 +82,9 @@ jobs:
MONGODB_ADMIN_PASSWORD=$MONGODB_ADMIN_PASSWORD \
MINIO_ROOT_USER=$MINIO_ROOT_USER \
MINIO_ROOT_PASSWORD=$MINIO_ROOT_PASSWORD \
/opt/opencrvs/infrastructure/clear-all-data.sh $REPLICAS ${{ inputs.stack }}"
/opt/opencrvs/${{ inputs.stack }}/infrastructure/clear-all-data.sh $REPLICAS ${{ inputs.stack }}"
echo "Running migrations..."
echo
ssh -p $SSH_PORT $SSH_USER@$SSH_HOST $SSH_ARGS "
/opt/opencrvs/infrastructure/run-migrations.sh ${{ inputs.stack }}"
/opt/opencrvs/${{ inputs.stack }}/infrastructure/run-migrations.sh ${{ inputs.stack }}"
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
8 changes: 4 additions & 4 deletions infrastructure/docker-compose.app.yml
Original file line number Diff line number Diff line change
Expand Up @@ -392,7 +392,7 @@ services:
- KIBANA_USERNAME=${KIBANA_USERNAME}
- KIBANA_PASSWORD=${KIBANA_PASSWORD}
volumes:
- '/opt/opencrvs/infrastructure/elasticsearch:/usr/app'
- '/opt/opencrvs/{{STACK}}/infrastructure/elasticsearch:/usr/app'
networks:
app_net:
dependencies_monitoring_net_2:
Expand Down Expand Up @@ -802,11 +802,11 @@ secrets:
external: true
configs:
hearth-dupe.{{ts}}:
file: /opt/opencrvs/infrastructure/hearth-plugins/checkDuplicateTask.js
file: /opt/opencrvs/{{STACK}}/infrastructure/hearth-plugins/checkDuplicateTask.js
hearth-ext-conf.{{ts}}:
file: /opt/opencrvs/infrastructure/hearth-queryparam-extensions.json
file: /opt/opencrvs/{{STACK}}/infrastructure/hearth-queryparam-extensions.json
mongo-on-deploy.{{ts}}:
file: /opt/opencrvs/infrastructure/mongodb/on-deploy.sh
file: /opt/opencrvs/{{STACK}}/infrastructure/mongodb/on-deploy.sh
networks:
dependencies_mongo_net:
external: true
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 32dd2e0

Please sign in to comment.