forked from dbca-wa/wildlifecompliance
-
Notifications
You must be signed in to change notification settings - Fork 0
/
make_docker_image.sh
executable file
·79 lines (74 loc) · 2.04 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
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
#!/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/....$//'))
BUILD_TAG=dbcawa/$REPO:$1_v$(date +%Y.%m.%d.%H.%M%S)
DBCA_ORIGIN_HASH=$(echo "$REPO" | md5sum -t | cut -c1-32)
DBCA_BRANCH=$DBCA_ORIGIN_HASH"_"$1
EXISTING_REMOTES=$(git remote)
{
if (( ! $(grep -c "$EXISTING_REMOTES" <<< "$DBCA_ORIGIN_HASH") )); then
echo "Attempt to create branch"
echo $REPO
echo "git remote add $DBCA_ORIGIN_HASH [email protected]:dbca-wa/$REPO.git"
git remote add $DBCA_ORIGIN_HASH [email protected]:dbca-wa/$REPO.git &&
git fetch $DBCA_ORIGIN_HASH &&
git remote set-url --push $DBCA_ORIGIN_HASH no_push &&
git checkout -b $DBCA_ORIGIN_HASH"_"$1 $DBCA_ORIGIN_HASH"/"$1
fi
echo "DBCA branch already exists"
} ||
{
echo "ERROR: Failed to create dbca branch"
echo "$0 1"
exit 1
}
{
git checkout $DBCA_BRANCH
echo $(git status)
} ||
{
echo "ERROR: Failed to checkout dbca branch"
echo "$0 1"
exit 1
}
{
git pull &&
cd $REPO/frontend/$REPO/ &&
# Apply front end venv if it exists
{
source venv/bin/activate && npm run build
} ||
{
npm run build
echo "INFO: Front end built without venv"
}
cd ../../../ &&
source venv/bin/activate &&
python manage_wc.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
}