Repository navigation
Expand file tree
/
Copy pathbuild-and-push.sh
More file actions
executable file
·151 lines (126 loc) · 4.16 KB
/
Copy pathbuild-and-push.sh
File metadata and controls
executable file
·151 lines (126 loc) · 4.16 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
#!/bin/bash
set -e
# Configuration
REGISTRY="ghcr.io/fredrikburmester"
VERSION=${VERSION:-latest}
# Colors
RED='\033[0;31m'
GREEN='\033[0;32m'
YELLOW='\033[1;33m'
BLUE='\033[0;34m'
CYAN='\033[0;36m'
WHITE='\033[1;37m'
NC='\033[0m'
# Hide cursor
tput civis
# Show cursor on exit
trap 'tput cnorm' EXIT
echo -e "${BLUE}Streamystats v2 Docker Build & Push${NC}"
echo -e "${BLUE}=================================${NC}"
echo "Registry: $REGISTRY"
echo "Version: $VERSION"
echo ""
# Menu options
options=("NextJS App" "Job Server" "All Services")
selected=0
# Function to display menu
display_menu() {
echo -e "${WHITE}Select which service(s) to build and push:${NC}"
echo ""
for i in "${!options[@]}"; do
if [ $i -eq $selected ]; then
echo -e "${CYAN} ▶ ${options[$i]}${NC}"
else
echo " ${options[$i]}"
fi
done
echo ""
echo -e "${WHITE}Use ↑/↓ arrows to navigate, Enter to select, q to quit${NC}"
}
# Function to build and push
build_and_push() {
local dockerfile=$1
local image_name=$2
local display_name=$3
echo -e "${YELLOW}Building $display_name...${NC}"
if docker buildx build --platform linux/amd64,linux/arm64 -f "$dockerfile" -t "$REGISTRY/$image_name:$VERSION" --push .; then
echo -e "${GREEN}✅ $display_name built and pushed successfully${NC}"
return 0
else
echo -e "${RED}❌ Failed to build/push $display_name${NC}"
return 1
fi
}
# Main menu loop
while true; do
clear
echo -e "${BLUE}Streamystats v2 Docker Build & Push${NC}"
echo -e "${BLUE}=================================${NC}"
echo "Registry: $REGISTRY"
echo "Version: $VERSION"
echo ""
display_menu
# Read single keypress
read -rsn1 key
case "$key" in
A) # Up arrow
((selected--))
if [ $selected -lt 0 ]; then
selected=$((${#options[@]} - 1))
fi
;;
B) # Down arrow
((selected++))
if [ $selected -ge ${#options[@]} ]; then
selected=0
fi
;;
"") # Enter key
clear
tput cnorm # Show cursor during build
case $selected in
0) # NextJS App
echo -e "${BLUE}Building NextJS App only...${NC}\n"
build_and_push "apps/nextjs-app/Dockerfile" "streamystats-nextjs" "NextJS app"
;;
1) # Job Server
echo -e "${BLUE}Building Job Server only...${NC}\n"
build_and_push "apps/job-server/Dockerfile" "streamystats-job-server" "Job server"
;;
2) # All Services
echo -e "${BLUE}Building all services...${NC}\n"
# Build in parallel
build_and_push "apps/nextjs-app/Dockerfile" "streamystats-nextjs" "NextJS app" &
NEXTJS_PID=$!
build_and_push "apps/job-server/Dockerfile" "streamystats-job-server" "Job server" &
JOBSERVER_PID=$!
echo -e "\n${YELLOW}Waiting for all builds to complete...${NC}\n"
FAILED=0
wait $NEXTJS_PID || FAILED=1
wait $JOBSERVER_PID || FAILED=1
if [ $FAILED -eq 1 ]; then
echo -e "\n${RED}❌ One or more builds failed${NC}"
exit 1
fi
;;
esac
echo -e "\n${GREEN}🚀 Build completed!${NC}"
echo ""
echo "Built images:"
case $selected in
0) echo " - $REGISTRY/streamystats-nextjs:$VERSION" ;;
1) echo " - $REGISTRY/streamystats-job-server:$VERSION" ;;
2)
echo " - $REGISTRY/streamystats-nextjs:$VERSION"
echo " - $REGISTRY/streamystats-job-server:$VERSION"
;;
esac
break
;;
q|Q) # Quit
echo -e "\n${YELLOW}Build cancelled.${NC}"
exit 0
;;
esac
done
tput cnorm # Restore cursor