From 63f8df1e38c195feb37470a4ef012902a1fa719c Mon Sep 17 00:00:00 2001 From: root Date: Wed, 1 Jul 2026 22:06:02 -0400 Subject: [PATCH] fix production --- production/README.md | 7 +++++ production/deploy-production.sh | 52 +++++++++++++++++++++++++++++++-- 2 files changed, 56 insertions(+), 3 deletions(-) diff --git a/production/README.md b/production/README.md index 736ef51..d25a617 100644 --- a/production/README.md +++ b/production/README.md @@ -73,6 +73,13 @@ Or fetch the archive and deploy in one command: VPN_CONTAINER="6c5dca44e1c2" ./deploy-production.sh --fetch-through-vpn ``` +When `IMAGE_ARCHIVE_REQUIRED=true`, `./deploy-production.sh` will also fetch a +missing archive automatically if `VPN_CONTAINER` is set: + +```bash +VPN_CONTAINER="6c5dca44e1c2" ./deploy-production.sh +``` + Equivalent manual command: ```bash diff --git a/production/deploy-production.sh b/production/deploy-production.sh index 052fb69..cc1e6ff 100755 --- a/production/deploy-production.sh +++ b/production/deploy-production.sh @@ -21,8 +21,10 @@ What it does: 6. Waits for health checks and prints container status VPN/shared-folder image flow: - Put an archive matching IMAGE_TAG in ./image-archives before running this script. - Example: ./image-archives/carmanagement-latest.tar + Put an archive matching IMAGE_TAG in IMAGE_ARCHIVE_DIR before running this script. + Example: /opt/docker-image-transfer/carmanagement-latest.tar + When IMAGE_ARCHIVE_REQUIRED=true and VPN_CONTAINER is set, a missing archive is + fetched through the VPN container before loading the release image. Options: --image-tag Override IMAGE_TAG from .env.docker.production for this run @@ -96,10 +98,16 @@ require_command() { } fetch_release_archive_through_vpn() { - if [[ "${fetch_through_vpn}" -ne 1 ]]; then + if ! should_fetch_release_archive_through_vpn; then return 0 fi + if [[ -z "${VPN_CONTAINER:-}" ]]; then + echo "VPN_CONTAINER is required to fetch the image archive through VPN." >&2 + usage >&2 + exit 1 + fi + echo "Fetching image archive through VPN container" IMAGE_TAG="${IMAGE_TAG}" \ APP_IMAGE="${APP_IMAGE:-10.0.0.4/melabidi/carmanagement}" \ @@ -107,6 +115,44 @@ fetch_release_archive_through_vpn() { "${ROOT_DIR}/fetch-image-through-vpn.sh" "${IMAGE_TAG}" } +release_archive_exists() { + local archive_dir="${IMAGE_ARCHIVE_DIR:-}" + + if [[ -z "${archive_dir}" || ! -d "${archive_dir}" ]]; then + return 1 + fi + + shopt -s nullglob + local archives=( + "${archive_dir}"/*"${IMAGE_TAG}"*.tar + "${archive_dir}"/*"${IMAGE_TAG}"*.tar.gz + "${archive_dir}"/*"${IMAGE_TAG}"*.tgz + ) + shopt -u nullglob + + [[ ${#archives[@]} -gt 0 ]] +} + +should_fetch_release_archive_through_vpn() { + if [[ "${IMAGE_ARCHIVE_DISABLED:-false}" == "true" || "${IMAGE_ARCHIVE_DISABLED:-0}" == "1" ]]; then + return 1 + fi + + if [[ "${fetch_through_vpn}" -eq 1 ]]; then + return 0 + fi + + if [[ "${IMAGE_ARCHIVE_REQUIRED:-false}" != "true" && "${IMAGE_ARCHIVE_REQUIRED:-0}" != "1" ]]; then + return 1 + fi + + if [[ -z "${VPN_CONTAINER:-}" ]]; then + return 1 + fi + + ! release_archive_exists +} + normalize_archive_dir() { if [[ -z "${IMAGE_ARCHIVE_DIR:-}" ]]; then return 0