-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathdeploy.sh
More file actions
executable file
·146 lines (120 loc) · 4.53 KB
/
Copy pathdeploy.sh
File metadata and controls
executable file
·146 lines (120 loc) · 4.53 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
#!/bin/bash
set -e
# BoxBoxBox F1 Platform Deployment Script
# This script helps with building and deploying the application
# Colors for output
GREEN='\033[0;32m'
BLUE='\033[0;34m'
RED='\033[0;31m'
YELLOW='\033[1;33m'
NC='\033[0m' # No Color
# Print header
echo -e "${BLUE}╔════════════════════════════════════════════════════╗${NC}"
echo -e "${BLUE}║ ║${NC}"
echo -e "${BLUE}║ ${YELLOW}BoxBoxBox F1 Platform - Deployment Script${BLUE} ║${NC}"
echo -e "${BLUE}║ ║${NC}"
echo -e "${BLUE}╚════════════════════════════════════════════════════╝${NC}"
echo
# Check for required environment variables
if [ -z "$DOCKER_REGISTRY" ]; then
echo -e "${RED}Error: DOCKER_REGISTRY environment variable is not set${NC}"
echo -e "Please set it with: ${YELLOW}export DOCKER_REGISTRY=your-registry.com${NC}"
exit 1
fi
# Parse command line arguments
COMMAND=${1:-"help"}
ENV=${2:-"dev"}
case $ENV in
dev)
KUBE_CONTEXT="minikube"
;;
staging)
KUBE_CONTEXT="staging-cluster"
;;
prod)
KUBE_CONTEXT="production-cluster"
;;
*)
echo -e "${RED}Invalid environment: $ENV${NC}"
echo -e "Valid environments are: ${YELLOW}dev, staging, prod${NC}"
exit 1
;;
esac
# Help command
function show_help {
echo -e "${GREEN}Usage:${NC} ./deploy.sh [command] [environment]"
echo
echo -e "${GREEN}Commands:${NC}"
echo -e " ${YELLOW}build${NC} Build Docker images"
echo -e " ${YELLOW}push${NC} Push Docker images to registry"
echo -e " ${YELLOW}deploy${NC} Deploy to Kubernetes"
echo -e " ${YELLOW}all${NC} Build, push and deploy"
echo -e " ${YELLOW}help${NC} Show this help message"
echo
echo -e "${GREEN}Environments:${NC}"
echo -e " ${YELLOW}dev${NC} Development environment (default)"
echo -e " ${YELLOW}staging${NC} Staging environment"
echo -e " ${YELLOW}prod${NC} Production environment"
echo
echo -e "${GREEN}Examples:${NC}"
echo -e " ${YELLOW}./deploy.sh build dev${NC} Build images for development"
echo -e " ${YELLOW}./deploy.sh all prod${NC} Build, push and deploy to production"
}
# Build Docker images
function build_images {
echo -e "${GREEN}Building Docker images for $ENV environment...${NC}"
echo -e "${BLUE}Building frontend image...${NC}"
docker build -t $DOCKER_REGISTRY/boxboxbox-frontend:latest -f Dockerfile.frontend .
echo -e "${BLUE}Building backend image...${NC}"
docker build -t $DOCKER_REGISTRY/boxboxbox-backend:latest -f backend/Dockerfile backend/
echo -e "${GREEN}Docker images built successfully!${NC}"
}
# Push Docker images to registry
function push_images {
echo -e "${GREEN}Pushing Docker images to registry...${NC}"
echo -e "${BLUE}Pushing frontend image...${NC}"
docker push $DOCKER_REGISTRY/boxboxbox-frontend:latest
echo -e "${BLUE}Pushing backend image...${NC}"
docker push $DOCKER_REGISTRY/boxboxbox-backend:latest
echo -e "${GREEN}Docker images pushed successfully!${NC}"
}
# Deploy to Kubernetes
function deploy_to_k8s {
echo -e "${GREEN}Deploying to $ENV environment...${NC}"
echo -e "${BLUE}Setting Kubernetes context to $KUBE_CONTEXT...${NC}"
kubectl config use-context $KUBE_CONTEXT
echo -e "${BLUE}Creating namespace if it doesn't exist...${NC}"
kubectl create namespace boxboxbox-$ENV --dry-run=client -o yaml | kubectl apply -f -
echo -e "${BLUE}Applying ConfigMap and Secrets...${NC}"
envsubst < k8s/config.yaml | kubectl apply -n boxboxbox-$ENV -f -
echo -e "${BLUE}Deploying database components...${NC}"
kubectl apply -n boxboxbox-$ENV -f k8s/database.yaml
echo -e "${BLUE}Deploying backend...${NC}"
envsubst < k8s/backend-deployment.yaml | kubectl apply -n boxboxbox-$ENV -f -
echo -e "${BLUE}Deploying frontend...${NC}"
envsubst < k8s/frontend-deployment.yaml | kubectl apply -n boxboxbox-$ENV -f -
echo -e "${BLUE}Deploying ingress...${NC}"
kubectl apply -n boxboxbox-$ENV -f k8s/ingress.yaml
echo -e "${GREEN}Deployment to $ENV completed successfully!${NC}"
}
# Execute command
case $COMMAND in
build)
build_images
;;
push)
push_images
;;
deploy)
deploy_to_k8s
;;
all)
build_images
push_images
deploy_to_k8s
;;
help|*)
show_help
;;
esac
echo -e "${GREEN}Done!${NC}"