-
Notifications
You must be signed in to change notification settings - Fork 0
/
build-push.sh
executable file
·77 lines (60 loc) · 1.28 KB
/
build-push.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
#!/bin/sh
#set -x
set -e
bin_docker=$(which docker)
# Docker hub
user="pikelang"
repo="pike"
# DRYRUN cheat code
if [ -z "${DRYRUN}" ]; then
output_opt="--push"
else
output_opt=""
fi
# Build Dockerfile and push to Docker hub
build_push()
{
dir=$1
if [ ! -d "${dir}" ]; then
echo "${dir} is not a directory" >&2
return
fi
# Prevent build and push if a SKIP file is present
if [ -f "${dir}/SKIP" ]; then
echo "${dir} is skipped" >&2
return
fi
# Populate arch and tags from vars file
arch=""
tags=""
# Skip if missing vars file
if [ ! -f "${dir}/vars" ]; then
echo "${dir} miss proper vars file, skipping" >&2
return
else
. "${dir}/vars"
fi
version=$(basename "${dir}")
# Get additional tags from vars file
more_tags=""
for t in ${tags}; do
more_tags="${more_tags} --tag=${user}/${repo}:${t}"
done
${bin_docker} buildx build \
--tag="${user}/${repo}:${version}" ${more_tags}\
--platform="${arch}" \
${output_opt} \
"${dir}"
}
# Either give directory/ies as argument(s), either loop over docker/ directory
if [ $# -eq 0 ]; then
for elem in "docker"/*; do
echo "building ${elem}"
build_push "${elem}"
done
else
for elem in "$@"; do
echo "building ${elem}"
build_push "${elem}"
done
fi