-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbuild_image.sh
More file actions
executable file
·24 lines (19 loc) · 900 Bytes
/
build_image.sh
File metadata and controls
executable file
·24 lines (19 loc) · 900 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
#!/bin/bash
image_name=$1
dist_version=$2
docker image inspect "${image_name}:${dist_version}" >/dev/null 2>&1 || docker pull "${image_name}:${dist_version}" >/dev/null 2>&1
remote_vcs_ref=$(docker image inspect "${image_name}:${dist_version}" 2>/dev/null | jq -M -r '.[0].Config.Labels["org.label-schema.vcs-ref"]')
git fetch
if [ "$FORCE" ] || \
[ "$remote_vcs_ref" = "null" ] || \
[ "$(git rev-parse --short $remote_vcs_ref 2>/dev/null)" = "" ] || \
[ "$(git diff --exit-code $remote_vcs_ref...HEAD Dockerfile)" != "" ]; then
echo "Dockerfile is changed between $remote_vcs_ref...HEAD"
docker build -t "${image_name}:${dist_version}" \
--build-arg DIST_VERSION=${dist_version} \
--build-arg BUILD_DATE=`date -u +"%Y-%m-%dT%H:%M:%SZ"` \
--build-arg VCS_REF=`git rev-parse --short HEAD` \
.
else
echo "Dockerfile is not changed since the last build. Skipped."
fi