-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbuild-and-push.sh
More file actions
executable file
·177 lines (156 loc) · 6.45 KB
/
build-and-push.sh
File metadata and controls
executable file
·177 lines (156 loc) · 6.45 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
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
#!/bin/bash
#=============================================================#
# StreamerHelper Docker Images Build & Push Script #
# Usage: ./build-and-push.sh [version] [options] #
# #
# Examples: #
# ./build-and-push.sh v0.0.2 #
# ./build-and-push.sh v0.0.2 --no-cache #
# ./build-and-push.sh --skip-push #
#=============================================================#
set -e
# Configuration
REGISTRY=${DOCKER_REGISTRY:-docker.io}
ORG=${DOCKER_ORG:-umuoy1}
IMAGE_PREFIX=${IMAGE_PREFIX:-streamerhelper}
VERSION="latest"
NO_CACHE=""
SKIP_PUSH=""
# Script directory (for relative paths)
SCRIPT_DIR="$(cd "$(dirname "$0")" && pwd)"
ROOT_DIR="$(dirname "$SCRIPT_DIR")"
# Parse arguments
while [[ $# -gt 0 ]]; do
case $1 in
--no-cache)
NO_CACHE="--no-cache"
shift
;;
--skip-push)
SKIP_PUSH=1
shift
;;
-h|--help)
echo "Usage: ./build-and-push.sh [version] [options]"
echo ""
echo "Arguments:"
echo " version Image tag (default: latest)"
echo ""
echo "Options:"
echo " --no-cache Build without cache"
echo " --skip-push Build only, skip pushing to registry"
echo " -h, --help Show this help"
echo ""
echo "Environment variables:"
echo " DOCKER_REGISTRY Docker registry (default: docker.io)"
echo " DOCKER_ORG Docker org/username (default: umuoy1)"
echo " IMAGE_PREFIX Image name prefix (default: streamerhelper)"
echo ""
echo "Examples:"
echo " ./build-and-push.sh v1.0.0"
echo " ./build-and-push.sh v1.0.0 --no-cache"
echo " ./build-and-push.sh --skip-push"
exit 0
;;
-*)
echo "Unknown option: $1"
exit 1
;;
*)
# Positional argument - version
VERSION=$1
shift
;;
esac
done
# Colors
RED='\033[0;31m'
GREEN='\033[0;32m'
YELLOW='\033[1;33m'
BLUE='\033[0;34m'
NC='\033[0m'
log_info() { echo -e "${GREEN}[INFO]${NC} $1"; }
log_warn() { echo -e "${YELLOW}[WARN]${NC} $1"; }
log_error() { echo -e "${RED}[ERROR]${NC} $1"; }
log_build() { echo -e "${BLUE}[BUILD]${NC} $1"; }
# Check directories - use actual project structure
BACKEND_DIR="$ROOT_DIR/web-server"
FRONTEND_DIR="$ROOT_DIR/web"
if [ ! -d "$BACKEND_DIR" ]; then
log_error "Backend directory not found: $BACKEND_DIR"
log_error "Expected structure: infra/ (this script), web-server/ (backend), web/ (frontend)"
exit 1
fi
if [ ! -d "$FRONTEND_DIR" ]; then
log_error "Frontend directory not found: $FRONTEND_DIR"
log_error "Expected structure: infra/ (this script), web-server/ (backend), web/ (frontend)"
exit 1
fi
# Verify required files exist
if [ ! -f "$BACKEND_DIR/docker-entrypoint.sh" ]; then
log_error "Missing: $BACKEND_DIR/docker-entrypoint.sh"
exit 1
fi
if [ ! -f "$BACKEND_DIR/bootstrap.js" ]; then
log_error "Missing: $BACKEND_DIR/bootstrap.js"
exit 1
fi
if [ ! -f "$FRONTEND_DIR/package.json" ]; then
log_error "Missing: $FRONTEND_DIR/package.json"
exit 1
fi
# Check docker login (skip if --skip-push)
if [ -z "${SKIP_PUSH:-}" ]; then
log_info "Checking Docker login status..."
if ! docker pull busybox:latest >/dev/null 2>&1; then
log_warn "Not logged in to Docker registry"
log_info "Running docker login..."
docker login $REGISTRY
fi
fi
# Banner
echo ""
echo "╔═══════════════════════════════════════════════════════════╗"
echo "║ StreamerHelper Build & Push ║"
echo "╠═══════════════════════════════════════════════════════════╣"
echo "║ Version: $VERSION"
echo "║ Registry: $REGISTRY/$ORG"
echo "║ No Cache: ${NO_CACHE:-false}"
echo "║ Skip Push: ${SKIP_PUSH:-false}"
echo "╚═══════════════════════════════════════════════════════════╝"
echo ""
# Build and push function
build_and_push() {
local name=$1
local dockerfile=$2
local context=$3
local image_name="$IMAGE_PREFIX-$name"
log_build "Building $image_name..."
docker build $NO_CACHE -f "$dockerfile" -t "$REGISTRY/$ORG/$image_name:$VERSION" "$context"
docker tag "$REGISTRY/$ORG/$image_name:$VERSION" "$REGISTRY/$ORG/$image_name:latest"
if [ -z "${SKIP_PUSH:-}" ]; then
log_info "Pushing $image_name:$VERSION..."
docker push "$REGISTRY/$ORG/$image_name:$VERSION"
docker push "$REGISTRY/$ORG/$image_name:latest"
else
log_info "Skipping push (--skip-push)"
fi
echo ""
}
# Build all images
# Note: Dockerfiles are in infra/, but build context is the respective app directory
build_and_push "backend" "$SCRIPT_DIR/Dockerfile.backend" "$BACKEND_DIR"
build_and_push "frontend" "$SCRIPT_DIR/Dockerfile.frontend" "$FRONTEND_DIR"
# Done
echo "╔═══════════════════════════════════════════════════════════╗"
echo "║ Build Complete! ║"
echo "╠═══════════════════════════════════════════════════════════╣"
echo "║ Images built: ║"
echo "║ - $REGISTRY/$ORG/$IMAGE_PREFIX-backend:$VERSION "
echo "║ - $REGISTRY/$ORG/$IMAGE_PREFIX-frontend:$VERSION "
if [ -z "${SKIP_PUSH:-}" ]; then
echo "║ ║"
echo "║ Images pushed to registry ║"
fi
echo "╚═══════════════════════════════════════════════════════════╝"
echo ""