-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbuild.sh
executable file
·80 lines (63 loc) · 2.18 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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
#!/bin/bash
# colors
bold='\033[0;1m'
italic='\033[0;3m'
underl='\033[0;4m'
red='\033[0;31m'
green='\033[0;32m'
blue='\033[0;34m'
yellow='\033[0;33m'
normal='\033[0m'
out=".bin/server"
help() {
echo -e "${underl}Usage:${normal}\n"
echo -e " ${bold}$0${normal} [${underl}command${normal}]\n"
echo -e "Here is a list of available commands\n"
echo -e " ${bold}deploy${normal} [${underl}branch${normal}] Run deploy script from current or provided branch"
echo -e " ${bold}image${normal} [push] Build docker image and (optional) push to container registry"
echo -e " ${bold}run${normal} [${underl}env${normal}] Run binary with provided environment (local - default)"
echo -e " ${bold}help${normal} Print this help messages to standard output"
}
build_executable() {
echo "Building executable..."
go build -o ${out} cmd/server/main.go
echo -e "Server successfully built into ${bold}\`${out}\`${normal}"
}
if [ "$1" == "image" ]; then
GIT_COMMIT=$(git rev-parse --short HEAD)
echo -e "Building a docker image from commit ${bold}$GIT_COMMIT${normal}"
docker build -t jus1d/void-server:latest .
if [ "$2" == "push" ]; then
docker tag jus1d/void-server:latest jus1d/void-server:$GIT_COMMIT
tags=("$GIT_COMMIT" "latest")
for tag in "${tags[@]}"; do
echo -e "Pushing ${bold}jus1d/void-server:$tag${normal} to hub"
docker push jus1d/void-server:"$tag"
done
echo "Built docker image was successfully pushed to dockerhub"
fi
elif [ "$1" == "deploy" ]; then
if [ -n "$2" ]; then
git checkout "$2"
fi
echo -e "Deploying ${bold}voidcontests/server${normal} from ${bold}$(git rev-parse --abbrev-ref HEAD)${normal} branch"
echo "Pulling latest image..."
docker pull jus1d/void-server:latest
echo "Stopping docker compose..."
docker compose down
echo "Starting docker compose..."
docker compose up -d
echo "Server running"
elif [ "$1" == "run" ]; then
build_executable
if [ -n "$2" ]; then
env="$2"
else
env="local"
fi
CONFIG_PATH="./config/${env}.yaml" ./.bin/server
elif [ "$1" == "help" ]; then
help
else
build
fi