-
Notifications
You must be signed in to change notification settings - Fork 0
/
build-musicbot.sh
executable file
·134 lines (111 loc) · 3.12 KB
/
build-musicbot.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
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
#!/bin/sh
set -e
ARG_MUSICBOT_VERSION="1.9.7"
ARG_DIST="alpine-3.6"
IS_FORCED_REBUILD_BASE="false"
ARCH=""
ARG_ARCH=""
ARG_TAG=""
ARG_TAG_LATEST=""
DOCKER_USERNAME=${DOCKER_USERNAME}
DOCKER_PASSWORD=${DOCKER_PASSWORD}
SCRIPT=$(readlink -f "$0")
SCRIPT_PATH=$(dirname "$SCRIPT")
BUILD_PATH=$SCRIPT_PATH
check_attributes(){
if [ "$DOCKER_USERNAME" = "" ];then
echo "ERROR: Please provide a valid docker username."
exit 1
fi
if [ "$DOCKER_PASSWORD" = "" ];then
echo "ERROR: Please provide a valid docker password."
exit 1
fi
}
get_cpu_architecture()
{
# Get CPU Architecture
ARCH=$(lscpu | grep "Architecture" | awk '{print $2}')
echo "Architecture: $ARCH"
if [ "$ARCH" = "armv7l" ];then
ARG_ARCH="arm32v6"
ARG_TAG="$ARG_ARCH-$ARG_DIST-$ARG_MUSICBOT_VERSION"
ARG_TAG_LATEST="$ARG_ARCH-latest"
elif [ "$ARCH" = "x86_64" ];then
ARG_ARCH="x86_64"
ARG_TAG="$ARG_DIST-$ARG_MUSICBOT_VERSION"
ARG_TAG_LATEST="latest"
else
echo "ERROR: Could not find any valid architecture..."
exit 1 # Exit the script
fi
}
print_build_banner(){
echo "********************************"
echo "Building $1"
echo "Distribution: $ARG_DIST"
echo "Architecture: $ARG_ARCH"
echo "Musicbot: $ARG_MUSICBOT_VERSION"
echo "Tag: $ARG_TAG"
echo "Tag: $ARG_TAG_LATEST"
echo "********************************"
echo " "
}
build_musicbot()
{
print_build_banner "musicbot"
cd "$BUILD_PATH"
# musicbot
docker build --no-cache \
-t glego/musicbot:$ARG_TAG \
-t glego/musicbot:$ARG_TAG_LATEST \
--build-arg ARG_MUSICBOT_VERSION=$ARG_MUSICBOT_VERSION \
-f ./dockerfiles/$ARG_DIST/$ARG_ARCH/Dockerfile .
docker_push "musicbot"
}
build_musicbot_base()
{
print_build_banner "musicbot-base"
cd "$BUILD_PATH"
# musicbot-base
docker build --no-cache \
-t glego/musicbot-base:$ARG_TAG \
-t glego/musicbot-base:$ARG_TAG_LATEST \
--build-arg ARG_MUSICBOT_VERSION=$ARG_MUSICBOT_VERSION \
-f ./dockerfiles/$ARG_DIST-base/$ARG_ARCH/Dockerfile .
docker_push "musicbot-base"
}
# Check if musicbot base needs to be rebuild
check_musicbot_base()
{
if [ "$IS_FORCED_REBUILD_BASE" = "true" ];then
echo "Force rebuilding base..."
build_musicbot_base
return 0
fi
rm -rf "/tmp/"*
cd "/tmp/"
docker run --rm glego/musicbot-base:$ARG_TAG_LATEST cat /app/requirements.sha1 > ./requirements.sha1 || build_musicbot_base
wget "https://raw.githubusercontent.com/Just-Some-Bots/MusicBot/$ARG_MUSICBOT_VERSION/requirements.txt"
sha1sum -c requirements.sha1 || build_musicbot_base
echo "Checksum OK, no need to rebuild base..."
}
docker_login ()
{
echo "$DOCKER_PASSWORD" | docker login --username "$DOCKER_USERNAME" --password-stdin
}
docker_push ()
{
repo=$1
docker_login
docker push glego/$repo:$ARG_TAG
docker push glego/$repo:$ARG_TAG_LATEST
}
main()
{
check_attributes
get_cpu_architecture
check_musicbot_base
build_musicbot
}
main