-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbuild_docker_tag.sh
executable file
·60 lines (47 loc) · 1.43 KB
/
build_docker_tag.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
#!/bin/bash
# Get git information and build docker image
if [[ $# -gt 0 ]] ; then
echo "usage: $0 [-h]"
echo "Builds a docker image from tagged source, and embeds git info. Run from source directory."
echo
echo "For a tagged commit vX.Y.Z, the docker image will be tagged as X.Y.Z."
echo
exit 1
fi
# Get git information
status=$( git status -s )
# status should be empty if the repository is clean
if [[ ! -z "$status" ]] ; then
echo "Repository is not clean - see git status"
exit 1
fi
gitRemote=$( git remote get-url origin )
# Get the git hash or tag
hash=$( git rev-parse HEAD )
# See if there's a tag
gitTag=$( git describe --tags --abbrev=0 --exact-match $hash 2>/dev/null || echo "" )
if [[ -z "$gitTag" ]]; then
echo "No tag found for commit $hash"
exit 1
fi
# Check that the git tag satisfies the format vX.Y.Z
if [[ ! $gitTag =~ ^v[0-9]+\.[0-9]+\.[0-9]+$ ]]; then
echo "Tag $gitTag does not match vX.Y.Z format"
exit 1
fi
dockerVersion=${gitTag:1}
dockerTag="cookpa/ftdc-t1w-preproc:${dockerVersion}"
# Build the docker image
docker build -t "$dockerTag" . \
--build-arg GIT_REMOTE="$gitRemote" \
--build-arg GIT_COMMIT="$gitTag" \
--build-arg DOCKER_IMAGE_TAG="$dockerTag" \
--build-arg DOCKER_IMAGE_VERSION="$dockerVersion"
if [[ $? -ne 0 ]] ; then
echo "Docker build failed - see output above"
exit 1
else
echo
echo "Build successful: $dockerTag"
echo
fi