|
1 | 1 | #!/bin/bash |
2 | 2 |
|
3 | | -# Run configuration |
4 | | -source ./configure-environment.sh "$@" |
5 | | -if [ $? -ne 0 ]; then |
6 | | - echo "❌ Configuration failed" |
| 3 | +# Parse arguments to check for dev mode and other flags |
| 4 | +DEV_MODE=false |
| 5 | +SETUP_ARGS="" |
| 6 | + |
| 7 | +for arg in "$@"; do |
| 8 | + case $arg in |
| 9 | + --dev-mode) |
| 10 | + DEV_MODE=true |
| 11 | + ;; |
| 12 | + *) |
| 13 | + SETUP_ARGS="$SETUP_ARGS $arg" |
| 14 | + ;; |
| 15 | + esac |
| 16 | +done |
| 17 | + |
| 18 | +# Build the setup container first |
| 19 | +echo "🏗️ Building setup container..." |
| 20 | +docker build -f Dockerfile.setup -t snapshotter-lite-setup:latest . |
| 21 | + |
| 22 | +# Create a temporary file to capture the env file path from setup |
| 23 | +SETUP_RESULT_FILE=$(mktemp) |
| 24 | + |
| 25 | +# Run setup container directly |
| 26 | +echo "🔧 Running setup container to configure environment..." |
| 27 | +docker run --rm -it \ |
| 28 | + -v "$(pwd):/app" \ |
| 29 | + -v "$SETUP_RESULT_FILE:/tmp/setup_result" \ |
| 30 | + -w /app \ |
| 31 | + snapshotter-lite-setup:latest \ |
| 32 | + bash -c "./configure-environment.sh $SETUP_ARGS --docker-mode" |
| 33 | + |
| 34 | +# Remove the setup container image |
| 35 | +docker rmi snapshotter-lite-setup:latest |
| 36 | + |
| 37 | +# Check if setup was successful by reading the result file |
| 38 | +if [ -f "$SETUP_RESULT_FILE" ] && [ -s "$SETUP_RESULT_FILE" ]; then |
| 39 | + SELECTED_ENV_FILE=$(cat "$SETUP_RESULT_FILE") |
| 40 | + rm -f "$SETUP_RESULT_FILE" |
| 41 | + |
| 42 | + if [ -n "$SELECTED_ENV_FILE" ] && [ -f "$SELECTED_ENV_FILE" ]; then |
| 43 | + echo "ℹ️ Setup container configured: $SELECTED_ENV_FILE" |
| 44 | + else |
| 45 | + echo "❌ Setup container failed to report a valid env file." |
| 46 | + echo " Reported: '$SELECTED_ENV_FILE'" |
| 47 | + echo " This indicates a problem with the configuration process." |
| 48 | + exit 1 |
| 49 | + fi |
| 50 | +else |
| 51 | + echo "❌ Setup container did not complete successfully or failed to report results." |
| 52 | + rm -f "$SETUP_RESULT_FILE" |
7 | 53 | exit 1 |
8 | 54 | fi |
9 | 55 |
|
| 56 | +# Source the environment file to get variables |
| 57 | +source "$SELECTED_ENV_FILE" |
| 58 | + |
| 59 | +# Ensure FULL_NAMESPACE is available |
| 60 | +if [ -z "$FULL_NAMESPACE" ]; then |
| 61 | + echo "❌ FULL_NAMESPACE not found in $SELECTED_ENV_FILE" |
| 62 | + exit 1 |
| 63 | +fi |
10 | 64 |
|
11 | | -# Source the environment file |
12 | | -source ".env-${FULL_NAMESPACE}" |
| 65 | +# Export variables so they're available to child scripts |
| 66 | +export FULL_NAMESPACE |
| 67 | +export NO_COLLECTOR |
13 | 68 |
|
14 | 69 | if [ "$DEV_MODE" != "true" ]; then |
15 | 70 | # Set image tag based on git branch |
@@ -65,14 +120,14 @@ export FULL_NAMESPACE_LOWER |
65 | 120 |
|
66 | 121 | COMPOSE_PROFILES="${COLLECTOR_PROFILE_STRING}" |
67 | 122 |
|
68 | | -# Modify the deploy-services call to use the profiles |
| 123 | +# Modify the deploy-services call to use the profiles (setup already ran) |
69 | 124 | if [ "$DEV_MODE" == "true" ]; then |
70 | | - ./deploy-services.sh --env-file ".env-${FULL_NAMESPACE}" \ |
| 125 | + ./deploy-services.sh --env-file "$SELECTED_ENV_FILE" \ |
71 | 126 | --project-name "$PROJECT_NAME_LOWER" \ |
72 | 127 | --collector-profile "$COMPOSE_PROFILES" \ |
73 | 128 | --dev-mode |
74 | 129 | else |
75 | | - ./deploy-services.sh --env-file ".env-${FULL_NAMESPACE}" \ |
| 130 | + ./deploy-services.sh --env-file "$SELECTED_ENV_FILE" \ |
76 | 131 | --project-name "$PROJECT_NAME_LOWER" \ |
77 | 132 | --collector-profile "$COMPOSE_PROFILES" \ |
78 | 133 | --image-tag "$IMAGE_TAG" |
|
0 commit comments