|
| 1 | +#!/usr/bin/env bash |
| 2 | +# pull-and-save-images.sh |
| 3 | +# |
| 4 | +# Run this on an internet-connected machine BEFORE transferring to the offline host. |
| 5 | +# |
| 6 | +# What it does: |
| 7 | +# 1. Pulls all third-party images from Docker Hub |
| 8 | +# 2. Builds the backend and nginx images locally |
| 9 | +# 3. Saves every image as a .tar file under ./images/ |
| 10 | +# |
| 11 | +# Usage: |
| 12 | +# bash scripts/pull-and-save-images.sh |
| 13 | +# |
| 14 | +# Build args for nginx are read from .env (if present) — copy .env.example first |
| 15 | +# if you haven't already configured it. |
| 16 | + |
| 17 | +set -euo pipefail |
| 18 | + |
| 19 | +SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" |
| 20 | +ROOT_DIR="$(dirname "$SCRIPT_DIR")" |
| 21 | +IMAGES_DIR="$ROOT_DIR/images" |
| 22 | + |
| 23 | +BACKEND_IMAGE="tracepcap-backend:latest" |
| 24 | +NGINX_IMAGE="tracepcap-nginx:latest" |
| 25 | + |
| 26 | +# --------------------------------------------------------------------------- |
| 27 | +# Helper |
| 28 | +# --------------------------------------------------------------------------- |
| 29 | +save_image() { |
| 30 | + local image="$1" |
| 31 | + local filename="$2" |
| 32 | + echo " Saving $image -> images/$filename" |
| 33 | + docker save "$image" -o "$IMAGES_DIR/$filename" |
| 34 | +} |
| 35 | + |
| 36 | +# --------------------------------------------------------------------------- |
| 37 | +# Load build-arg overrides from .env when available |
| 38 | +# --------------------------------------------------------------------------- |
| 39 | +if [ -f "$ROOT_DIR/.env" ]; then |
| 40 | + echo "Loading build args from .env" |
| 41 | + set -a |
| 42 | + # shellcheck source=/dev/null |
| 43 | + source "$ROOT_DIR/.env" |
| 44 | + set +a |
| 45 | +fi |
| 46 | + |
| 47 | +mkdir -p "$IMAGES_DIR" |
| 48 | + |
| 49 | +# --------------------------------------------------------------------------- |
| 50 | +# 1. Pull third-party images |
| 51 | +# --------------------------------------------------------------------------- |
| 52 | +echo "" |
| 53 | +echo "=== [1/3] Pulling third-party images ===" |
| 54 | + |
| 55 | +# --- Docker Hub --- |
| 56 | +DOCKERHUB_IMAGES=( |
| 57 | + "postgres:15-alpine" |
| 58 | + "minio/minio:RELEASE.2024-11-07T00-52-20Z" |
| 59 | + "minio/mc:RELEASE.2024-11-21T17-21-54Z" |
| 60 | +) |
| 61 | + |
| 62 | +for img in "${DOCKERHUB_IMAGES[@]}"; do |
| 63 | + echo " Pulling $img (Docker Hub)..." |
| 64 | + docker pull "$img" |
| 65 | +done |
| 66 | + |
| 67 | +# --------------------------------------------------------------------------- |
| 68 | +# 2. Build local images |
| 69 | +# --------------------------------------------------------------------------- |
| 70 | +echo "" |
| 71 | +echo "=== [2/3] Building local images ===" |
| 72 | +cd "$ROOT_DIR" |
| 73 | + |
| 74 | +echo " Building backend..." |
| 75 | +docker build \ |
| 76 | + -t "$BACKEND_IMAGE" \ |
| 77 | + ./backend |
| 78 | + |
| 79 | +echo " Building nginx (frontend)..." |
| 80 | +docker build \ |
| 81 | + --build-arg "VITE_API_BASE_URL=${VITE_API_BASE_URL:-/api}" \ |
| 82 | + --build-arg "VITE_SUPPORTED_FILE_TYPES=${VITE_SUPPORTED_FILE_TYPES:-.pcap,.pcapng,.cap}" \ |
| 83 | + --build-arg "VITE_ANALYSIS_OPTIONS=${VITE_ANALYSIS_OPTIONS:-false}" \ |
| 84 | + --build-arg "VITE_NETWORK_DIAGRAM_CONVERSATION_LIMIT=${VITE_NETWORK_DIAGRAM_CONVERSATION_LIMIT:-false}" \ |
| 85 | + -t "$NGINX_IMAGE" \ |
| 86 | + -f ./nginx/Dockerfile \ |
| 87 | + . |
| 88 | + |
| 89 | +# --------------------------------------------------------------------------- |
| 90 | +# 3. Save all images as tars |
| 91 | +# --------------------------------------------------------------------------- |
| 92 | +echo "" |
| 93 | +echo "=== [3/3] Saving images to images/ ===" |
| 94 | + |
| 95 | +for img in "${DOCKERHUB_IMAGES[@]}"; do |
| 96 | + filename="$(echo "$img" | tr '/:' '_').tar" |
| 97 | + save_image "$img" "$filename" |
| 98 | +done |
| 99 | +save_image "$BACKEND_IMAGE" "tracepcap-backend.tar" |
| 100 | +save_image "$NGINX_IMAGE" "tracepcap-nginx.tar" |
| 101 | + |
| 102 | +# --------------------------------------------------------------------------- |
| 103 | +# Summary |
| 104 | +# --------------------------------------------------------------------------- |
| 105 | +echo "" |
| 106 | +echo "=== Done ===" |
| 107 | +echo "" |
| 108 | +echo "Transfer the following to the offline machine:" |
| 109 | +echo " images/ (all .tar files)" |
| 110 | +echo " docker-compose.offline.yml" |
| 111 | +echo " .env (or .env.example — configure before starting)" |
| 112 | +echo " scripts/load-images.sh" |
| 113 | +echo "" |
| 114 | +echo "Then on the offline machine run:" |
| 115 | +echo " bash scripts/load-images.sh" |
| 116 | +echo " docker compose -f docker-compose.offline.yml up -d" |
0 commit comments