forked from mintcoding/licensing-template
-
Notifications
You must be signed in to change notification settings - Fork 0
/
make_docker_image.sh
executable file
·50 lines (48 loc) · 1.39 KB
/
make_docker_image.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
## first parameter is DBCA branch name
set -e
if [[ $# -lt 1 ]]; then
echo "ERROR: DBCA branch must be specified"
echo "$0 1"
exit 1
fi
CURRENT_BRANCH=$(git rev-parse --abbrev-ref HEAD)
#REPO=$(basename -s .git `git config --get remote.origin.url` | sed 's/-//g')
REPO=$(awk '{split($0, arr, "\/"); print arr[2]}' <<< $(git config -l|grep remote|grep url|head -n 1|sed 's/-//g'|sed 's/....$//'))
DBCA_BRANCH="dbca_"$1
BUILD_TAG=dbcawa/$REPO:$1_v$(date +%Y.%m.%d.%H.%M%S)
{
git checkout $DBCA_BRANCH
} ||
{
echo "ERROR: You must have your local code checked in and the DBCA branch set up on local with the 'dbca_' prefix. Example Instructions:"
echo "git remote add dbca git@github.com:dbca-wa/wildlifecompliance.git"
echo "git checkout -b dbca_compliance_mgt_dev dbca/compliance_mgt_dev"
echo "$0 1"
exit 1
}
{
git pull &&
cd $REPO/frontend/$REPO/ &&
npm run build &&
cd ../../../ &&
poetry run python manage.py collectstatic --no-input &&
git log --pretty=medium -30 > ./git_history_recent &&
docker image build --no-cache --tag $BUILD_TAG . &&
git checkout $CURRENT_BRANCH
echo $BUILD_TAG
} ||
{
git checkout $CURRENT_BRANCH
echo "ERROR: Docker build failed"
echo "$0 1"
exit 1
}
{
docker push $BUILD_TAG
} || {
git checkout $CURRENT_BRANCH
echo "ERROR: Docker push failed"
echo "$0 1"
exit 1
}