@@ -10,15 +10,50 @@ BLUE='\033[0;34m'
1010RED=' \033[0;31m'
1111NC=' \033[0m' # No Color
1212
13- # Read build mode from the first argument (prod or dev)
14- MODE=$1
15- if [[ " $MODE " != " prod" && " $MODE " != " dev" ]]; then
16- echo -e " ${RED} ❌ Error: Invalid mode specified. Use 'prod' or 'dev'.${NC} "
17- echo " Usage: $0 <prod|dev>"
13+ # Parse command line arguments
14+ ONLY_PUSH=false
15+ USE_CACHE=false
16+ MODE=" "
17+
18+ # Parse arguments
19+ while [[ $# -gt 0 ]]; do
20+ case $1 in
21+ --only-push)
22+ ONLY_PUSH=true
23+ shift
24+ ;;
25+ --cache)
26+ USE_CACHE=true
27+ shift
28+ ;;
29+ prod|dev)
30+ if [[ -n " $MODE " ]]; then
31+ echo -e " ${RED} ❌ Error: Multiple modes specified. Use only one mode.${NC} "
32+ exit 1
33+ fi
34+ MODE=$1
35+ shift
36+ ;;
37+ * )
38+ echo -e " ${RED} ❌ Error: Unknown option '$1 '${NC} "
39+ echo " Usage: $0 [--only-push] [--cache] <prod|dev>"
40+ exit 1
41+ ;;
42+ esac
43+ done
44+
45+ # Check if mode is specified
46+ if [[ -z " $MODE " ]]; then
47+ echo -e " ${RED} ❌ Error: Mode not specified. Use 'prod' or 'dev'.${NC} "
48+ echo " Usage: $0 [--only-push] [--cache] <prod|dev>"
1849 exit 1
1950fi
2051
21- echo -e " ${BLUE} 🚀 Starting build and push process in '${MODE} ' mode...${NC} "
52+ if [[ " $ONLY_PUSH " == " true" ]]; then
53+ echo -e " ${BLUE} 🚀 Starting push process in '${MODE} ' mode (skipping build)...${NC} "
54+ else
55+ echo -e " ${BLUE} 🚀 Starting build and push process in '${MODE} ' mode...${NC} "
56+ fi
2257
2358# Set environment file and tag based on mode
2459if [[ " $MODE " == " prod" ]]; then
@@ -66,9 +101,18 @@ tag_and_push() {
66101# Trap to capture ctrl+c and exit gracefully
67102trap ' echo -e "${RED}🛑 Build and push aborted${NC}"; exit 1' INT
68103
69- # Build all services using docker compose
70- echo -e " ${BLUE} 🏗️ Building Docker images for AMD64 architecture...${NC} "
71- docker compose --env-file " ${ENV_FILE} " build --no-cache
104+ # Build all services using docker compose (skip if --only-push is used)
105+ if [[ " $ONLY_PUSH " != " true" ]]; then
106+ if [[ " $USE_CACHE " == " true" ]]; then
107+ echo -e " ${BLUE} 🏗️ Building Docker images for AMD64 architecture (with cache)...${NC} "
108+ docker compose --env-file " ${ENV_FILE} " build
109+ else
110+ echo -e " ${BLUE} 🏗️ Building Docker images for AMD64 architecture (no cache)...${NC} "
111+ docker compose --env-file " ${ENV_FILE} " build --no-cache
112+ fi
113+ else
114+ echo -e " ${BLUE} ⏭️ Skipping build step (--only-push mode)${NC} "
115+ fi
72116
73117# Tag and push images to registry in parallel
74118echo -e " ${BLUE} 📦 Tagging and pushing images with tag '${TAG} ' to registry in parallel...${NC} "
0 commit comments