-
Notifications
You must be signed in to change notification settings - Fork 33
/
Copy pathdocker-build.sh
executable file
·52 lines (43 loc) · 1.17 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
#!/bin/bash
# build the bootstrap docker container
TAG=""
while [[ $# -gt 0 ]]; do
case $1 in
-t|--tag)
TAG="$2"
shift # past argument
shift # past value
;;
*)
echo "Unknown option $1"
exit 1
;;
esac
done
PRODUCT="$(npm pkg get name | tr -d '"')"
VER="$(npm pkg get version | tr -d '"')"
BASE_TAG="${PRODUCT}_${VER}"
echo "BASE_TAG: $BASE_TAG, PRODUCT: $PRODUCT"
build_id=$(git log $BASE_TAG..HEAD --oneline | wc -l)
build_id=$(echo $build_id +1 | bc)
if [ "$build_id" -lt "1" ]
then
echo "Base tag not found in git: $BASE_TAG"
exit 1
fi
VERTAG="$VER-$build_id"
echo "Building image $PRODUCT:$VERTAG"
docker build . -t $PRODUCT:$VERTAG --build-arg BUILD_VER=$VERTAG --no-cache --pull
echo "Publish to docker hub"
docker tag $PRODUCT:$VERTAG nubosoftware/$PRODUCT:$VERTAG
docker push nubosoftware/$PRODUCT:$VERTAG
docker tag $PRODUCT:$VERTAG nubosoftware/$PRODUCT:$VER
docker push nubosoftware/$PRODUCT:$VER
if [ -z "$TAG" ]
then
echo "No need to update speific tag"
else
echo "Publish nubosoftware/$PRODUCT:$TAG"
docker tag $PRODUCT:$VERTAG nubosoftware/$PRODUCT:$TAG
docker push nubosoftware/$PRODUCT:$TAG
fi