-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathinit.sh
executable file
·53 lines (48 loc) · 1.73 KB
/
init.sh
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
#!/bin/bash
manifest="/manifests"
# Check if Docker is installed and running
if ! command -v docker &> /dev/null
then
echo "Docker is not installed. Please install Docker and try again."
exit
fi
if ! docker info &> /dev/null
then
echo "Docker is not running. Please start Docker and try again."
exit
fi
# Check if kubectl is installed and connected to a cluster
if ! command -v kubectl &> /dev/null
then
echo "kubectl is not installed. Please install kubectl and try again."
exit
fi
if ! kubectl cluster-info &> /dev/null
then
echo "kubectl is not connected to a cluster. Please connect to a cluster and try again."
exit
fi
# Find Dockerfiles and build images
for dir in */ ; do
if [ -f "$dir/Dockerfile" ]; then
image_name=$(basename "$dir")
if docker build -t "$image_name" "$dir"; then
docker push "$image_name"
echo "Successfully built $image_name image." >> reports.txt
else
echo "Failed to build $image_name image." >> reports.txt
continue
fi
# Generate Kubernetes deployment manifest
# shellcheck disable=SC2094
cat cat $manifest + "/" + deployment.yaml.template | sed "s/{{MICROSERVICE}}/$MICROSERVICE/g" sed"s/{{IMAGE}}/$image_name/g" > $manifest + "/" + "$image_name-deployment.yaml"
# shellcheck disable=SC2094
cat cat $manifest + "/" + service.yaml.template | sed "s/{{MICROSERVICE}}/$MICROSERVICE/g" > $manifest + "/" + "$image_name-service.yaml"
# Apply Kubernetes deployment
if kubectl apply -f "$manifest"; then
echo "Successfully deployed $image_name." >> reports.txt
else
echo "Failed to deploy $image_name." >> reports.txt
fi
fi
done