-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbuild.sh
More file actions
executable file
·159 lines (135 loc) · 4.6 KB
/
Copy pathbuild.sh
File metadata and controls
executable file
·159 lines (135 loc) · 4.6 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
#!/bin/bash
# Krill Docker Build Script
# Usage: ./build.sh [development|testing|production|all]
set -e
# Colors for output
RED='\033[0;31m'
GREEN='\033[0;32m'
YELLOW='\033[1;33m'
BLUE='\033[0;34m'
NC='\033[0m' # No Color
# Function to print colored output
print_status() {
echo -e "${BLUE}[INFO]${NC} $1"
}
print_success() {
echo -e "${GREEN}[SUCCESS]${NC} $1"
}
print_warning() {
echo -e "${YELLOW}[WARNING]${NC} $1"
}
print_error() {
echo -e "${RED}[ERROR]${NC} $1"
}
# Function to build a specific target
build_target() {
local target=$1
local tag="krill:${target}"
print_status "Building ${target} image..."
docker build --target ${target} -t ${tag} .
if [ $? -eq 0 ]; then
print_success "Successfully built ${tag}"
# For production builds, also tag with DigitalOcean registry
if [ "$target" = "production" ]; then
local registry="registry.digitalocean.com/krill/krill"
local image_hash=$(docker images --quiet ${tag})
if [ -n "$image_hash" ]; then
print_status "Tagging production image with DigitalOcean registry..."
# Tag with image hash
docker tag ${tag} ${registry}:${image_hash}
print_success "Tagged as ${registry}:${image_hash}"
# Tag with latest
docker tag ${tag} ${registry}:latest
print_success "Tagged as ${registry}:latest"
print_success "Production image tagged for DigitalOcean registry"
else
print_warning "Could not determine image hash for tagging"
fi
fi
else
print_error "Failed to build ${tag}"
exit 1
fi
}
# Function to run tests in container
run_tests() {
print_status "Running tests in container..."
docker run --rm krill:testing
}
# Function to push production image to DigitalOcean registry
push_to_registry() {
local registry="registry.digitalocean.com/krill/krill"
local image_hash=$(docker images --quiet krill:production)
if [ -n "$image_hash" ]; then
print_status "Pushing production image to DigitalOcean registry..."
# Push both tags
docker push ${registry}:${image_hash}
docker push ${registry}:latest
print_success "Production image pushed to DigitalOcean registry"
else
print_error "Production image not found. Build it first with: $0 production"
exit 1
fi
}
# Function to show usage
show_usage() {
echo "Usage: $0 [development|testing|production|all|test|push]"
echo ""
echo "Targets:"
echo " development - Build development image with debug tools"
echo " testing - Build testing image with test dependencies"
echo " production - Build production image with security optimizations"
echo " all - Build all images"
echo " test - Build testing image and run tests"
echo " push - Push production image to DigitalOcean registry"
echo ""
echo "Examples:"
echo " $0 development # Build development image"
echo " $0 all # Build all images"
echo " $0 test # Build and run tests"
echo " $0 push # Push production image to registry"
}
# Check if Docker is running
if ! docker info > /dev/null 2>&1; then
print_error "Docker is not running. Please start Docker and try again."
exit 1
fi
# Parse command line arguments
case "${1:-all}" in
development)
build_target "development"
print_success "Development image ready. Run with: docker run -p 8000:8000 krill:development"
;;
testing)
build_target "testing"
print_success "Testing image ready. Run with: docker run --rm krill:testing"
;;
production)
build_target "production"
print_success "Production image ready. Run with: docker run -p 8000:8000 krill:production"
print_success "Image also tagged for DigitalOcean registry: registry.digitalocean.com/krill/krill"
;;
all)
print_status "Building all images..."
build_target "development"
build_target "testing"
build_target "production"
print_success "All images built successfully!"
;;
test)
build_target "testing"
run_tests
;;
push)
push_to_registry
;;
help|--help|-h)
show_usage
;;
*)
print_error "Unknown target: $1"
show_usage
exit 1
;;
esac
print_status "Build completed successfully!"