fix: staging packages, image URL and database scripts
All checks were successful
Deploy to Staging / Build Images (push) Successful in 3m28s
Deploy to Staging / Deploy to Staging (push) Successful in 27s
Deploy to Staging / Verify Staging (push) Successful in 5s
Deploy to Staging / Notify Staging Ready (push) Successful in 5s
Deploy to Staging / Notify Staging Failure (push) Has been skipped

This commit is contained in:
Eric Gullickson
2025-12-30 20:50:52 -06:00
parent 4e04d3915c
commit c9b756727e
4 changed files with 232 additions and 22 deletions

View File

@@ -9,6 +9,7 @@ set -e
RED='\033[0;31m'
GREEN='\033[0;32m'
YELLOW='\033[1;33m'
BLUE='\033[0;34m'
NC='\033[0m' # No Color
# Configuration
@@ -16,14 +17,17 @@ SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
PROJECT_ROOT="$(dirname "$SCRIPT_DIR")"
EXPORT_DIR="${PROJECT_ROOT}/database-exports"
TIMESTAMP=$(date +%Y%m%d_%H%M%S)
CONTAINER_NAME="mvp-postgres"
# Environment-based container names
CONTAINER_NAME="" # Will be set based on environment selection
ENVIRONMENT="" # production or staging
# Default values
EXPORT_FORMAT="sql"
COMPRESS=true
INCLUDE_SCHEMA=true
INCLUDE_DATA=true
EXPORT_NAME="motovaultpro_export_${TIMESTAMP}"
EXPORT_NAME="" # Will be set after environment selection
# Function to print colored output
print_info() {
@@ -38,6 +42,69 @@ print_error() {
echo -e "${RED}[ERROR]${NC} $1"
}
print_env() {
echo -e "${BLUE}[ENV]${NC} $1"
}
# Function to select environment
select_environment() {
if [ -n "$ENVIRONMENT" ]; then
# Environment already set via command line
return
fi
echo ""
echo -e "${BLUE}========================================${NC}"
echo -e "${BLUE} MotoVaultPro Database Export${NC}"
echo -e "${BLUE}========================================${NC}"
echo ""
echo "Select environment to export from:"
echo ""
echo " 1) Production (mvp-postgres)"
echo " 2) Staging (mvp-postgres-staging)"
echo ""
read -p "Enter choice [1-2]: " ENV_CHOICE
case $ENV_CHOICE in
1)
ENVIRONMENT="production"
CONTAINER_NAME="mvp-postgres"
;;
2)
ENVIRONMENT="staging"
CONTAINER_NAME="mvp-postgres-staging"
;;
*)
print_error "Invalid choice. Please enter 1 or 2."
exit 1
;;
esac
echo ""
print_env "Selected environment: ${ENVIRONMENT}"
print_env "Container: ${CONTAINER_NAME}"
echo ""
}
# Function to set container name based on environment
set_container_from_environment() {
case $ENVIRONMENT in
production|prod)
ENVIRONMENT="production"
CONTAINER_NAME="mvp-postgres"
;;
staging|stage)
ENVIRONMENT="staging"
CONTAINER_NAME="mvp-postgres-staging"
;;
*)
print_error "Invalid environment: $ENVIRONMENT"
print_error "Valid options: production, staging"
exit 1
;;
esac
}
# Function to show usage
show_usage() {
cat << EOF
@@ -47,6 +114,7 @@ Usage: $0 [options]
Options:
-h, --help Show this help message
-e, --env ENV Environment: production or staging (prompts if not specified)
-f, --format FORMAT Export format: sql, custom, directory (default: sql)
-o, --output NAME Custom export filename (without extension)
-n, --no-compress Don't compress the export
@@ -54,20 +122,30 @@ Options:
--data-only Export data only (no schema)
--exclude-table TABLE Exclude specific table(s) (can be used multiple times)
--include-table TABLE Include only specific table(s) (can be used multiple times)
-c, --container NAME Container name (default: mvp-postgres)
-c, --container NAME Override container name (ignores environment selection)
Environments:
production (prod) Uses container: mvp-postgres
staging (stage) Uses container: mvp-postgres-staging
Examples:
# Full database export with compression
# Interactive environment selection
$0
# Schema only export
$0 --schema-only
# Export from production
$0 --env production
# Export specific tables
$0 --include-table vehicles --include-table fuel_logs
# Export from staging
$0 --env staging
# Schema only export from production
$0 --env prod --schema-only
# Export specific tables from staging
$0 -e staging --include-table vehicles --include-table fuel_logs
# Custom format for pg_restore
$0 --format custom --output my_backup
$0 --env production --format custom --output my_backup
EOF
exit 0
@@ -76,12 +154,17 @@ EOF
# Parse command line arguments
EXCLUDE_TABLES=()
INCLUDE_TABLES=()
CONTAINER_OVERRIDE=""
while [[ $# -gt 0 ]]; do
case $1 in
-h|--help)
show_usage
;;
-e|--env)
ENVIRONMENT="$2"
shift 2
;;
-f|--format)
EXPORT_FORMAT="$2"
shift 2
@@ -111,7 +194,7 @@ while [[ $# -gt 0 ]]; do
shift 2
;;
-c|--container)
CONTAINER_NAME="$2"
CONTAINER_OVERRIDE="$2"
shift 2
;;
*)
@@ -121,6 +204,25 @@ while [[ $# -gt 0 ]]; do
esac
done
# Handle environment selection
if [ -n "$CONTAINER_OVERRIDE" ]; then
# Container explicitly specified, use it directly
CONTAINER_NAME="$CONTAINER_OVERRIDE"
ENVIRONMENT="custom"
print_info "Using custom container: $CONTAINER_NAME"
elif [ -n "$ENVIRONMENT" ]; then
# Environment specified via command line
set_container_from_environment
else
# No environment specified, prompt user
select_environment
fi
# Set default export name with environment prefix
if [ -z "$EXPORT_NAME" ]; then
EXPORT_NAME="motovaultpro_${ENVIRONMENT}_export_${TIMESTAMP}"
fi
# Create export directory if it doesn't exist
mkdir -p "${EXPORT_DIR}"
@@ -186,6 +288,7 @@ fi
# Export database
print_info "Starting database export..."
print_info "Environment: ${ENVIRONMENT}"
print_info "Container: ${CONTAINER_NAME}"
print_info "Format: ${EXPORT_FORMAT}"
print_info "Output: ${OUTPUT_PATH}"
@@ -221,6 +324,8 @@ METADATA_FILE="${EXPORT_DIR}/${EXPORT_NAME}_metadata.json"
cat > "${METADATA_FILE}" << EOF
{
"export_timestamp": "$(date -u +%Y-%m-%dT%H:%M:%SZ)",
"environment": "${ENVIRONMENT}",
"container_name": "${CONTAINER_NAME}",
"database_name": "motovaultpro",
"export_format": "${EXPORT_FORMAT}",
"compressed": ${COMPRESS},
@@ -324,6 +429,8 @@ echo ""
print_info "==============================================="
print_info "Database Export Complete!"
print_info "==============================================="
print_info "Environment: ${ENVIRONMENT}"
print_info "Container: ${CONTAINER_NAME}"
print_info "Export file: ${OUTPUT_PATH}"
print_info "Metadata: ${METADATA_FILE}"
print_info "Instructions: ${IMPORT_INSTRUCTIONS}"