From b3ba34d980b2305bbe00b305d3d8c3826ce93628 Mon Sep 17 00:00:00 2001 From: sadnub Date: Wed, 25 Oct 2023 23:30:20 -0400 Subject: [PATCH] update docker to support reporting --- .../containers/tactical-frontend/dockerfile | 3 +- .../tactical-frontend/entrypoint.sh | 36 ++++++++++++++++++- docker/containers/tactical/dockerfile | 2 +- docker/containers/tactical/entrypoint.sh | 2 +- 4 files changed, 39 insertions(+), 4 deletions(-) diff --git a/docker/containers/tactical-frontend/dockerfile b/docker/containers/tactical-frontend/dockerfile index bacd8238..49d99cc7 100644 --- a/docker/containers/tactical-frontend/dockerfile +++ b/docker/containers/tactical-frontend/dockerfile @@ -1,7 +1,8 @@ FROM nginxinc/nginx-unprivileged:stable-alpine ENV PUBLIC_DIR /usr/share/nginx/html - +ENV TACTICAL_DIR /opt/tactical +ENV TACTICAL_READY_FILE ${TACTICAL_DIR}/tmp/tactical.ready USER root RUN deluser --remove-home nginx \ diff --git a/docker/containers/tactical-frontend/entrypoint.sh b/docker/containers/tactical-frontend/entrypoint.sh index 1b9a9988..685f8090 100644 --- a/docker/containers/tactical-frontend/entrypoint.sh +++ b/docker/containers/tactical-frontend/entrypoint.sh @@ -2,6 +2,15 @@ # # https://www.freecodecamp.org/news/how-to-implement-runtime-environment-variables-with-create-react-app-docker-and-nginx-7f9d42a91d70/ # +set -e + +function check_tactical_ready { + sleep 15 + until [ -f "${TACTICAL_READY_FILE}" ]; do + echo "waiting for init container to finish install or update..." + sleep 10 + done +} # Recreate js config file on start rm -rf ${PUBLIC_DIR}/env-config.js @@ -25,4 +34,29 @@ server { EOF )" -echo "${nginx_config}" > /etc/nginx/conf.d/default.conf \ No newline at end of file +echo "${nginx_config}" > /etc/nginx/conf.d/default.conf + +check_tactical_ready + +URL_PATH="${TACTICAL_DIR}/tmp/web_tar_url" +AGENT_BASE=$(grep -o 'AGENT_BASE_URL.*' /tmp/settings.py | cut -d'"' -f 2) +WEB_VERSION=$(grep -o 'WEB_VERSION.*' /tmp/settings.py | cut -d'"' -f 2) + +# add dynamic web tar if configured +if [ -f "$URL_PATH" ]; then + START_STRING=$(head -c ${#AGENT_BASE} "$URL_PATH") + if [ "$START_STRING" == "${AGENT_BASE}" ]; then + echo "Attempting to pull dynamic web tar from ${AGENT_BASE}" + webtar="trmm-web-v${WEB_VERSION}.tar.gz" + wget -q $(cat "${URL_PATH}") -O /tmp/${webtar} + tar -xzf /tmp/${webtar} -C /tmp/ + rm -rf ${PUBLIC_DIR}/* + mv /tmp/dist/* ${PUBLIC_DIR} + + rm -f /tmp/${webtar} + rm -rf /tmp/dist + + chown -R nginx:nginx /etc/nginx && chown -R nginx:nginx ${PUBLIC_DIR} + echo "Success!" + fi +fi diff --git a/docker/containers/tactical/dockerfile b/docker/containers/tactical/dockerfile index f7a0af84..dd13d025 100644 --- a/docker/containers/tactical/dockerfile +++ b/docker/containers/tactical/dockerfile @@ -48,7 +48,7 @@ COPY --from=CREATE_VENV_STAGE ${VIRTUAL_ENV} ${VIRTUAL_ENV} # install deps RUN apt-get update && \ apt-get upgrade -y && \ - apt-get install -y --no-install-recommends rsync && \ + apt-get install -y --no-install-recommends rsync weasyprint && \ rm -rf /var/lib/apt/lists/* && \ groupadd -g 1000 "${TACTICAL_USER}" && \ useradd -M -d "${TACTICAL_DIR}" -s /bin/bash -u 1000 -g 1000 "${TACTICAL_USER}" diff --git a/docker/containers/tactical/entrypoint.sh b/docker/containers/tactical/entrypoint.sh index bfd0903a..4e1761dc 100644 --- a/docker/containers/tactical/entrypoint.sh +++ b/docker/containers/tactical/entrypoint.sh @@ -118,6 +118,7 @@ EOF python manage.py pre_update_tasks python manage.py migrate --no-input python manage.py generate_json_schemas + python manage.py get_webtar_url > ${TACTICAL_DIR}/tmp/web_tar_url python manage.py collectstatic --no-input python manage.py initial_db_setup python manage.py initial_mesh_setup @@ -127,7 +128,6 @@ EOF python manage.py create_natsapi_conf python manage.py create_uwsgi_conf python manage.py create_installer_user - python manage.py setup_reporting_permissions python manage.py clear_redis_celery_locks python manage.py post_update_tasks