-
Notifications
You must be signed in to change notification settings - Fork 5
/
docker-build.sh
executable file
·39 lines (33 loc) · 1.23 KB
/
docker-build.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
#!/usr/bin/env bash
readonly COMMIT=$(git rev-parse --short HEAD)
declare -l BRANCH # Make contents of the variable lowercase
readonly BRANCH=$(git rev-parse --abbrev-ref HEAD)
readonly TAG="whisker:${BRANCH}-${COMMIT}"
# Try to detect available docker commands.
function set_docker_cmd() {
if [[ -z "${DOCKER_CMD}" ]]; then
if command -v dockerd-rootless-infosun &>/dev/null; then
DOCKER_CMD="dockerd-rootless-infosun --data-root /local/hdd/${USER}/docker -- docker"
else
DOCKER_CMD="docker"
fi
readonly DOCKER_CMD
fi
}
# Helper function to run docker.
function my_docker() {
set_docker_cmd
eval "${DOCKER_CMD}" "$@"
}
function main() {
echo "Building docker image of Whisker with tag ${TAG}"
my_docker image build . -t "${TAG}" -f Dockerfile
readonly tar_file="${TAG}.tar"
echo "Saving image to ${tar_file}.gz"
# Note: according to the docker documentation this command should be used:
# docker save tag | gzip > tarfile.tar.gz
# But this leads to invalid TAR header errors when attempting to load the
# tar file with docker again. In contrast, this command does work:
my_docker save "${TAG}" -o "${tar_file}" && gzip -f "${tar_file}"
}
main