-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathutils.sh
84 lines (69 loc) · 2.19 KB
/
utils.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
#!/bin/bash
rmI () {
local imageName=$1
if [[ "$(docker images -q $imageName 2> /dev/null)" != "" ]]; then
# remove containers
rmC $imageName
# remove dangling images
danglingIds=$(docker images --filter "dangling=true" -q --no-trunc)
if [[ ! -z "$danglingIds" ]]; then
docker rmi $danglingIds &> /dev/null
fi
# remove images
docker images -q $imageName | xargs docker rmi -f &> /dev/null
fi
}
rmC() {
local imageName=$1
local containerIds=$(docker ps -a | grep "$imageName" | awk '{ print $1 }')
if [[ ! -z "$containerIds" ]]; then
echo "Parando e removendo contêineres..."
for id in $containerIds; do
docker stop $id &> /dev/null
docker rm $id &> /dev/null
echo "Contêiner $id parado e removido."
done
fi
}
navigation() {
local callback=$1
# Loop através dos diretórios no diretório atual
for dir in */; do
# Extrai o nome do diretório removendo a barra final
version=${dir%/}
# Verifica se o nome do diretório corresponde ao padrão de versão
if [[ $version =~ ^[0-9]+\.[0-9]+$ ]]; then
if [ -f "$version/Dockerfile" ]; then
$callback $version
fi
fi
done
}
callback_build() {
# Baixando imagem alpine
docker pull ${REPOSITORY}:$1 &> /dev/null
# BUILD VERSION
docker build \
-f $1/Dockerfile \
--build-arg TIMEZONE=$TIMEZONE \
-t ${build_registry}/${REPOSITORY}:$1 .
}
callback_smash() {
# Esmagando images
docker run -d --name smash_img ${build_registry}/${REPOSITORY}:$1
docker export smash_img > /tmp/docker-smash_img.tar
docker import /tmp/docker-smash_img.tar ${build_registry}/smash:latest
docker build \
-f Dockerfile.smash \
--build-arg SMASH_IMG=${build_registry}/smash:latest \
--build-arg VERSION=$1 \
-t ${REGISTRY}/${REPOSITORY}:$1 .
# Limpeza
rmC ${build_registry}/${REPOSITORY}
rmI ${build_registry}/smash
rm /tmp/docker-smash_img.tar
}
callback_push() {
# Realizando o push da imagem
docker push ${REGISTRY}/${REPOSITORY}:$1
}