Merge pull request #9803 from shanemcd/cluster-migrate-once

Cluster dev env: only run migrations on first node

Reviewed-by: Ryan Petrello <None>
Reviewed-by: Shane McDonald <me@shanemcd.com>
This commit is contained in:
softwarefactory-project-zuul[bot] 2021-04-07 16:59:52 +00:00 committed by GitHub
commit 091027fefc
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 62 additions and 1 deletions

View File

@ -0,0 +1,51 @@
#!/bin/bash
set -o errexit
set -o nounset
readonly CMDNAME=$(basename "$0")
readonly MIN_SLEEP=0.5
readonly MAX_SLEEP=30
readonly ATTEMPTS=10
readonly TIMEOUT=60
log_message() { echo "[${CMDNAME}]" "$@" >&2; }
log_error() { echo "[${CMDNAME}] ERROR:" "$@" >&2; }
# Args: last_sleep
next_sleep() {
awk "BEGIN {ns = ${1} * 2; ns = ns > ${MAX_SLEEP} ? ${MAX_SLEEP} : ns; print(ns)}"
}
wait_for() {
local rc=1
local attempt=1
local next_sleep="${MIN_SLEEP}"
while true; do
log_message "Attempt ${attempt} of ${ATTEMPTS}"
timeout "${TIMEOUT}" \
/bin/bash -c "! awx-manage showmigrations | grep '\[ \]'" &>/dev/null \
&& return || rc=$?
(( ++attempt > ATTEMPTS )) && break
log_message "Waiting ${next_sleep} seconds before next attempt"
sleep "${next_sleep}"
next_sleep=$(next_sleep ${next_sleep})
done
return $rc
}
main() {
log_message "Waiting for database migrations..."
if ! wait_for "$@"; then
log_message "ERROR: Database migrations not applied"
exit 1
fi
}
main "$@"

View File

@ -181,6 +181,7 @@ RUN openssl req -nodes -newkey rsa:2048 -keyout /etc/nginx/nginx.key -out /etc/n
# Create default awx rsyslog config
ADD tools/ansible/roles/dockerfile/files/rsyslog.conf /var/lib/awx/rsyslog/rsyslog.conf
ADD tools/ansible/roles/dockerfile/files/wait-for-migrations /usr/local/bin/wait-for-migrations
## File mappings
{% if build_dev|bool %}

View File

@ -18,6 +18,9 @@ services:
SDB_PORT: {{ awx_sdb_port_start }}
AWX_GROUP_QUEUES: tower
RECEPTORCTL_SOCKET: /var/run/receptor/receptor.sock
{% if loop.index == 1 %}
RUN_MIGRATIONS: 1
{% endif %}
links:
- postgres
- redis_{{ container_postfix }}

View File

@ -12,7 +12,13 @@ make awx-link
# AWX bootstrapping
make version_file
make migrate
if [[ -n "$RUN_MIGRATIONS" ]]; then
make migrate
else
wait-for-migrations
fi
make init