-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdocker_build.sh
executable file
·60 lines (54 loc) · 1.58 KB
/
docker_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
#!/bin/bash
[[ ! -f "$HOME/allvars" ]] && { echo -e "[ERROR]: No se encontro allvars deployado"; exit -1; }
source $HOME/allvars
APP_VERSION=$(cat package.json | jq -r .version)
APP_REVISION=$(git rev-list --count HEAD)
REPO=${DOCKER_REPO}/${API3_APP_NAME}:${APP_VERSION}.${APP_REVISION}
#I think this is useless
APP_PORT=${API3_PORT}:${API3_CONTAINER_PORT}
MONGODB="MONGODB_URI=localhost:27017/dbname"
build() {
echo -e " ==> Building ${REPO} image."
docker build -t ${REPO} .
echo -e "Listing ${REPO} image."
docker images
}
test() {
echo -e " ==> Run ${REPO} image."
docker run --name ${API3_APP_NAME} -p ${APP_PORT} --env ${MONGODB} -d ${REPO} &
sleep 5
docker logs ${API3_APP_NAME}
}
release(){
echo -e " ==> Release ${REPO} image to docker registry."
if [[ ! -z "$DOCKER_PWD" ]]; then
cat ${DOCKER_PWD} | docker login --username ${DOCKER_USER} --password-stdin
fi
docker tag ${REPO} ${REPO}
docker push ${REPO}
}
clean(){
echo -e "Cleaning local build environment."
docker stop ${API3_APP_NAME} 2>/dev/null; true
docker rm ${API3_APP_NAME} 2>/dev/null; true
docker rmi ${REPO} 2>/dev/null; true
}
help(){
echo -e ""
echo -e "Please use \`make <target>' where <target> is one of"
echo -e ""
echo -e " build Builds the docker image."
echo -e " test Tests image."
echo -e " release Releases image."
echo -e " clean Cleans local images."
echo -e ""
}
if [[ "$1" == "build" ]]; then build;
elif [[ "$1" == "test" ]]; then test;
elif [[ "$1" == "release" ]];then release;
elif [[ "$1" == "clean" ]]; then clean;
elif [[ "$1" == "help" ]];then help;
else
help
exit -1
fi