-
Notifications
You must be signed in to change notification settings - Fork 0
/
qual.sh
executable file
·82 lines (79 loc) · 3.29 KB
/
qual.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
80
81
82
#!/bin/sh
# Pass version as first argument - REQUIRED.
#VER="${1:-`git symbolic-ref -q --short HEAD || git describe --tags --exact-match`}"
VER=$1
getNPMVer () {
sed -e 's/^"//' -e 's/"$//' <<<`npm pkg get version`
}
integrityExit () {
echo "$1"
echo "Aborting build to preserve build tag integrity with commits." && exit 1
}
GITBRANCH=`git symbolic-ref -q --short HEAD`
GITTAG=`git describe --tags --exact-match 2>/dev/null`
COMMIT=$(git rev-parse HEAD)
cd `git rev-parse --show-toplevel` # cd to repo root.
IMAGENAME=`basename $(pwd)`
if [ -f ./package.json ]; then
NPMVER=`getNPMVer`
fi
echo "Build Tag: $VER"
echo "NPM-Ver: $NPMVER"
echo "Branch: $GITBRANCH"
echo "Git Tag: $GITTAG"
echo Commit: $COMMIT
echo Image Name: $IMAGENAME
echo
# Ensure they've already updated their npm version to match what they want to tag the build with.
if [[ "$NPMVER" != "" && "$VER" != "$NPMVER" ]]; then
integrityExit "The version in your npm package.json file does not match the build tag passed.
Please run the following command to update your package version and commit those changes before attempting to build:
npm version -no-git-tag-version $VER
"
fi
# Ensure we're building from committed changes.
if `git diff-index --quiet HEAD --`; then
echo "Active branch $GITBRANCH is clean. Continuing with checks..."
else
integrityExit "Active branch $GITBRANCH is dirty. Please commit changes to associate with build."
fi
# Ensure we're tagging with a version and not a branch name.
if [ "$VER" = "$GITBRANCH" ]; then
integrityExit "Not tagging commit $COMMIT on branch $GITBRANCH with tag $GITBRANCH. Please provide a versioning argument."
fi
# Ensure our version paramenter is not in conflict with an existing commit tag.
if [[ "$GITTAG" != "" && "$GITTAG" != "v$VER" ]]; then
integrityExit "Not overwriting existing tag $GITTAG on commit $COMMIT with new tag $VER."
fi
# Ensure we're able to tag the commit with the version.
if [[ "$VER" = "$GITTAG" || "v$VER" = "$GITTAG" ]]; then
echo "Commit $COMMIT is already tagged as $GITTAG."
else
if `git tag $VER $COMMIT`; then
echo "Tagged commit $COMMIT on branch $GITBRANCH with tag $VER."
else
integrityExit "Failed to tag commit $COMMIT on branch $GITBRANCH with tag $VER."
fi
fi
echo "Proceeding with versioned builds..."
docker build -t registry.its.txstate.edu/$IMAGENAME .
docker tag registry.its.txstate.edu/$IMAGENAME registry.its.txstate.edu/$IMAGENAME:$VER
PUSH_STATUS=$(docker push registry.its.txstate.edu/$IMAGENAME --quiet)
if [[ $PUSH_STATUS = "registry.its.txstate.edu/$IMAGENAME" ]]; then
echo "Pushed latest build to registry.its.txstate.edu/$IMAGENAME."
else
echo "Failed to push latest build to registry.its.txstate.edu/$IMAGENAME.
Please resolve the issues preventing the push and try again with the following command:
docker push registry.its.txstate.edu/$IMAGENAME
"
fi
PUSH_STATUS=$(docker push registry.its.txstate.edu/$IMAGENAME:$VER --quiet)
if [[ $PUSH_STATUS = "registry.its.txstate.edu/$IMAGENAME:$VER" ]]; then
echo "Pushed tagged build to registry.its.txstate.edu/$IMAGENAME:$VER."
else
echo "Failed to push tagged build to registry.its.txstate.edu/$IMAGENAME:$VER.
Please resolve the issues preventing the push and try again with the following command:
docker push registry.its.txstate.edu/$IMAGENAME:$VER
"
fi
git push origin --tags