mirror of
https://github.com/ansible/awx.git
synced 2026-01-10 15:32:07 -03:30
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:
commit
091027fefc
51
tools/ansible/roles/dockerfile/files/wait-for-migrations
Executable file
51
tools/ansible/roles/dockerfile/files/wait-for-migrations
Executable 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 "$@"
|
||||
@ -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 %}
|
||||
|
||||
@ -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 }}
|
||||
|
||||
@ -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
|
||||
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user