forked from aerius/database-build
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbuild_images.sh
executable file
·32 lines (27 loc) · 1015 Bytes
/
build_images.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
#!/bin/bash
set -Eeuo pipefail
# Change current directory to directory of script so it can be called from everywhere
SCRIPT_PATH=$(readlink -f "${0}")
SCRIPT_DIR=$(dirname "${SCRIPT_PATH}")
cd "${SCRIPT_DIR}"
# If DOCKER_REGISTRY_URL is supplied we should prepend it to the image name
if [[ -z "${DOCKER_REGISTRY_URL:-}" ]]; then
IMAGE_NAME='aerius-database-build'
else
IMAGE_NAME="${DOCKER_REGISTRY_URL}/database-build"
fi
# Loop through all generated Docker directories
IMAGES_TO_PUSH=()
while read DIRECTORY; do
IMAGE_TAG=$(basename "${DIRECTORY}")
echo '# Building: '"${IMAGE_TAG}"
docker build --pull -t "${IMAGE_NAME}":"${IMAGE_TAG}" -f "${DIRECTORY}/Dockerfile" .
if [[ "${PUSH_IMAGES:-}" == 'true' ]]; then
IMAGES_TO_PUSH+=("${IMAGE_NAME}":"${IMAGE_TAG}")
fi
done < <(find docker/ -maxdepth 1 -type d -name '*-*-*')
# If there are images to push, do so
for IMAGE_TO_PUSH in "${IMAGES_TO_PUSH[@]}"; do
echo '# Pushing image: '"${IMAGE_TO_PUSH}"
docker push "${IMAGE_TO_PUSH}"
done