-
Notifications
You must be signed in to change notification settings - Fork 0
/
image
executable file
·73 lines (55 loc) · 1.45 KB
/
image
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
#!/bin/bash
DIR="$(cd $(dirname $0) && pwd)"
BIN_DIR="$(cd $DIR/.. && pwd)"
# Import functions
. $BIN_DIR/helper/fn
usage() {
cat <<-EOF
Usage: $0 [options...]
Options:
-e <production|staging> Environment
-h Show usage
EOF
exit 0
}
# Go to current directory
CURR_FOLDER="$(pwd)"
cd $CURR_FOLDER
OPT="staging"
while getopts "e:h" o
do
case ${o} in
e) [ $OPTARG = "staging" -o $OPTARG = "production" ] && OPT=$OPTARG || usage ;;
h) usage ;;
\?) usage ;;
esac
done
# ENV File
load_env $OPT
# Generate ENVs for frontend application
if test "${REQUIRE_GEN:-0}" = "1"; then
gen_env "${CURR_FOLDER}/resource/env.js"
fi
# Variables
REGISTRY_USER="$(cat ${CURR_FOLDER}/.registry-user)"
REGISTRY_PASSWD="$(cat ${CURR_FOLDER}/.registry-passwd)"
TAG_IMAGE="${REGISTRY}/${IMAGE}:${VERSION}"
TAG_IMAGE_LATEST="${REGISTRY}/${IMAGE}:latest"
# Build
docker build \
--build-arg NODE_ENV=${NODE_ENV} \
--target main \
--compress \
--force-rm \
--no-cache . \
--tag $TAG_IMAGE \
--tag $TAG_IMAGE_LATEST
test $? -ne 0 && abort "Falha no build da image --> ${TAG_IMAGE}" || ok "Build image ok --> ${TAG_IMAGE}"
# Push (Send image to Registry)
cat ${CURR_FOLDER}/.registry-passwd | docker login $REGISTRY --username $REGISTRY_USER --password-stdin
docker push $TAG_IMAGE
docker push $TAG_IMAGE_LATEST
# # Cleanup
# docker rmi $(docker images -q -f "dangling=true" -f "label=autodelete=true")
ok "Build finalizado... Yeahh!!!"
exit 0