-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathbuild.sh
executable file
·64 lines (51 loc) · 1.92 KB
/
build.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
54
55
56
57
58
59
60
61
62
63
64
#!/bin/bash
# Define colors
GREEN='\033[0;32m'
RED='\033[0;31m'
NC='\033[0m' # No Color
# Enable immediate exit if any command has a non-zero exit status
set -e
# Function to extract the tag name
get_tag_name() {
local directory=$1
local tag_name=$(basename "$directory")
# Check if there are subdirectories
if [[ "$directory" != "$tag_name" ]]; then
tag_name=${directory//\//:}
fi
tag_name="copex/$tag_name"
echo "$tag_name"
}
# Check if at least one argument is provided
if [ $# -eq 0 ]; then
directories=("php" "php/7.4" "php/8.0" "php/8.1" "php/8.2" "php/8.3" "nginx-php-fpm")
echo -e "${GREEN}No arguments provided. Using default directories: ${directories[*]}${NC}"
else
directories=("$@")
fi
# Loop through each provided directory and build the Docker image
for directory in "${directories[@]}"; do
if [ -d "$directory" ]; then
echo -e "${GREEN}Entering directory: $directory${NC}"
cd "$directory" || { echo -e "${RED}Could not enter directory: $directory${NC}"; exit 1; }
tag_name=$(get_tag_name "$directory")
echo -e "${GREEN}Building Docker container in $directory...${NC}"
if docker build -t "$tag_name" . --squash; then
echo -e "${GREEN}Build, Squashed and Tagged the container with $tag_name...${NC}"
else
echo -e "${RED}Failed to build $directory.${NC}"
exit 1
fi
cd - > /dev/null || { echo -e "${RED}Could not return to the previous directory.${NC}"; exit 1; }
else
echo -e "${RED}Directory $directory not found.${NC}"
fi
done
# Loop through each provided directory and push the Docker images
for directory in "${directories[@]}"; do
tag_name=$(get_tag_name "$directory")
# Pushing the container if the build was successful
echo -e "${GREEN}Pushing the container $tag_name ${NC}"
docker push "$tag_name"
echo -e "${GREEN}Successfully pushed $tag_name!${NC}"
done