diff --git a/README.md b/README.md index fa238ce..2fbc81b 100644 --- a/README.md +++ b/README.md @@ -44,3 +44,9 @@ All the functionality for generating and storing the receptors and hexagons. ### Build_grid_receptors_to All the functionality for generating and storing the receptors_to lookup tables. + + +## Image build +There are two scripts for building the Docker images. +* [`update.sh`](update.sh) - Creates the Dockerfile files for the specified Database-build versions. +* [`build_images.sh`](build_images.sh) - Builds all generated Dockerfile files. diff --git a/VERSION b/VERSION new file mode 100644 index 0000000..b000224 --- /dev/null +++ b/VERSION @@ -0,0 +1 @@ +0.1-SNAPSHOT diff --git a/build_images.sh b/build_images.sh new file mode 100755 index 0000000..b740e59 --- /dev/null +++ b/build_images.sh @@ -0,0 +1,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-modules' +else + IMAGE_NAME="${DOCKER_REGISTRY_URL}/database-modules" +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 '*-database-build_*') + +# 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 diff --git a/docker/.gitignore b/docker/.gitignore new file mode 100644 index 0000000..2e288dc --- /dev/null +++ b/docker/.gitignore @@ -0,0 +1,2 @@ +# Ignore generated directories +*-database-build_* diff --git a/docker/Dockerfile.template b/docker/Dockerfile.template new file mode 100644 index 0000000..4ad71df --- /dev/null +++ b/docker/Dockerfile.template @@ -0,0 +1,5 @@ +# syntax = docker/dockerfile:1 +FROM nexus-docker.aerius.nl/database-build:%%DATABASE_BUILD_VERSION%% + +# Copy the database-modules source into the image +COPY source/modules/ /source/database-modules diff --git a/update.sh b/update.sh new file mode 100755 index 0000000..47377d3 --- /dev/null +++ b/update.sh @@ -0,0 +1,30 @@ +#!/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}" + +# Database-Build versions +IMAGE_VERSIONS=( + "1.4.0-psql_15-pgis_3.4" + "1.4.0-psql_17-pgis_3.5" +) + +# Read in current version of the script +BUILD_VERSION=$( "docker/${IMAGE_TAG}/Dockerfile" +done