From 7b01d6f62f49ac283933ba899476c9a01f62286e Mon Sep 17 00:00:00 2001 From: Jared Abbott Date: Fri, 15 May 2020 12:13:11 -0230 Subject: [PATCH] add 11.7 support and improve scripts --- .travis.yml | 2 +- Dockerfile | 4 ++-- README.md | 19 ++++++++++++++++ build_push.sh | 51 +++++++++++++++++++++++++++++++----------- dev/util/shellcheck.sh | 8 +++++++ docker-compose.yml | 6 ++--- lint.sh | 17 -------------- package/10.12-3.8.env | 3 +++ package/11.7-3.9.env | 4 ++++ package/9.6.13-3.6.env | 3 +++ 10 files changed, 81 insertions(+), 36 deletions(-) create mode 100755 dev/util/shellcheck.sh delete mode 100644 lint.sh create mode 100644 package/10.12-3.8.env create mode 100644 package/11.7-3.9.env create mode 100644 package/9.6.13-3.6.env diff --git a/.travis.yml b/.travis.yml index a42996d..8c791e0 100644 --- a/.travis.yml +++ b/.travis.yml @@ -29,4 +29,4 @@ branches: - master script: - - ./lint.sh --sh + - ./dev/util/shellcheck.sh diff --git a/Dockerfile b/Dockerfile index a0da40b..f72cd42 100644 --- a/Dockerfile +++ b/Dockerfile @@ -2,7 +2,7 @@ ARG alpine_version FROM alpine:${alpine_version} ARG alpine_version -ARG pg_package_version +ARG pg_full_version #-------------------------------------------------------------------------------- # Install dependencies @@ -12,7 +12,7 @@ ARG pg_package_version #-------------------------------------------------------------------------------- RUN echo "http://dl-cdn.alpinelinux.org/alpine/v${alpine_version}/main" >> /etc/apk/repositories -RUN apk --no-cache --update add dumb-init postgresql=${pg_package_version} py-pip && \ +RUN apk --no-cache --update add dumb-init postgresql=${pg_full_version} py-pip && \ pip install awscli && \ apk --purge -v del py-pip diff --git a/README.md b/README.md index f1bc80f..78b401d 100644 --- a/README.md +++ b/README.md @@ -2,6 +2,25 @@ Cron based download from s3 and database restore. +## Build + +`./build_push.sh [-p , --package ]` + +`./build_push.sh -p 11.7-3.9` + +### Package files + +Each package file represents a release for a particular `postgres` branch. + +The contents of the latest package file may look like this: + +``` +ALPINE_VERSION='3.9' +PG_BASE_VERSION='11' +PG_FULL_VERSION='11.7' +PG_LATEST=true +``` + ## Usage Typically this image is instantiated as a container among many others and would have the responsibility of getting downloading a dump file from s3 and restoring a database at a particular time of day. diff --git a/build_push.sh b/build_push.sh index f126fa6..b7047f2 100755 --- a/build_push.sh +++ b/build_push.sh @@ -1,31 +1,56 @@ #!/usr/bin/env sh -alpine_version='3.8' -legacy_image=false -pg_major_version='10' -pg_package_version='10.10' +#------------------------------------------------------------------------------------ +# Loop over arguments +#------------------------------------------------------------------------------------ +for arg in "$@"; do + # [ -p | --package ] + if [ -n "${package_flag}" ]; then + package_flag='' + package="${arg}" + fi + + if [ "${arg}" = "-p" ] || [ "${arg}" = "--package" ]; then + package_flag=true + fi +done + +#------------------------------------------------------------------------------------ +# Exit on error +#------------------------------------------------------------------------------------ +if [ -z "${package}" ]; then + echo '> Package file not specified: [-p , --package ]' + exit 127 +fi + +if [ -f "./package/${package}.env" ]; then + . "./package/${package}.env" +else + echo "> Package file not found: './package/${package}.env'" + exit 127 +fi builds=\ -"${pg_package_version}_${pg_package_version}-r0_${alpine_version}",\ -"${pg_major_version}_${pg_package_version}-r0_${alpine_version}" +"${PG_FULL_VERSION}_${PG_FULL_VERSION}-r0_${ALPINE_VERSION}",\ +"${PG_BASE_VERSION}_${PG_FULL_VERSION}-r0_${ALPINE_VERSION}" -if [ "${legacy_image}" = 'false' ]; then - builds="${builds}","latest_${pg_package_version}-r0_${alpine_version}" +if [ "${PG_LATEST:-'false'}" = 'true' ]; then + builds="${builds}","latest_${PG_FULL_VERSION}-r0_${ALPINE_VERSION}" fi echo $builds | tr ',' '\n' | while read build; do - alpine_version=$(echo "${build}" | cut -d '_' -f 3) + ALPINE_VERSION=$(echo "${build}" | cut -d '_' -f 3) pg_restore_from_s3_tag=$(echo "${build}" | cut -d '_' -f 1 ) - pg_package_version=$(echo "${build}" | cut -d '_' -f 2) + PG_FULL_VERSION=$(echo "${build}" | cut -d '_' -f 2) echo "" echo "--------------------------------" echo "POSTGRES-RESTORE-FROM-S3 TAG: ${pg_restore_from_s3_tag}" - echo "POSTGRES PACKAGE VERSION: ${pg_package_version}" + echo "POSTGRES PACKAGE VERSION: ${PG_FULL_VERSION}" echo "--------------------------------" - echo docker build --tag bluedrop360/postgres-restore-from-s3:$pg_restore_from_s3_tag --build-arg pg_package_version=$pg_package_version --build-arg alpine_version="${alpine_version}" . - eval docker build --tag bluedrop360/postgres-restore-from-s3:$pg_restore_from_s3_tag --build-arg pg_package_version=$pg_package_version --build-arg alpine_version="${alpine_version}" . || exit 1 + echo docker build --tag bluedrop360/postgres-restore-from-s3:$pg_restore_from_s3_tag --build-arg pg_full_version=$PG_FULL_VERSION --build-arg alpine_version="${ALPINE_VERSION}" . + eval docker build --tag bluedrop360/postgres-restore-from-s3:$pg_restore_from_s3_tag --build-arg pg_full_version=$PG_FULL_VERSION --build-arg alpine_version="${ALPINE_VERSION}" . || exit 1 echo docker push bluedrop360/postgres-restore-from-s3:$pg_restore_from_s3_tag eval docker push bluedrop360/postgres-restore-from-s3:$pg_restore_from_s3_tag || exit 1 done diff --git a/dev/util/shellcheck.sh b/dev/util/shellcheck.sh new file mode 100755 index 0000000..af7e20d --- /dev/null +++ b/dev/util/shellcheck.sh @@ -0,0 +1,8 @@ +#!/usr/bin/env sh + +printf '\n%s\n' "Checking shell scripts..." + +SHELLCHECK_OPTS="" + +RUN_SHELLCHECK="shellcheck ${ALLOW_EXTERNAL_SOURCE:-} ${SHELLCHECK_OPTS} {} +" +eval "find ./*.sh -type f -exec ${RUN_SHELLCHECK}" diff --git a/docker-compose.yml b/docker-compose.yml index 33ab5e3..744e16f 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -11,14 +11,14 @@ version: '3' services: postgres-restore-from-s3: - image: postgres-restore-from-s3:10.10 + image: postgres-restore-from-s3:11.7 network_mode: 'host' build: context: ./ dockerfile: ./Dockerfile args: - pg_alpine_branch: '3.8' - pg_version: '10.10-r0' + alpine_version: '3.9' + pg_full_version: '11.7-r0' environment: AWS_BUCKET: AWS_REGION: diff --git a/lint.sh b/lint.sh deleted file mode 100644 index be6fb52..0000000 --- a/lint.sh +++ /dev/null @@ -1,17 +0,0 @@ -#!/usr/bin/env sh - -ALLOW_EXTERNAL_SOURCE="${ALLOW_EXTERNAL_SOURCE:-}" - -if [ "${1}" = "--yml" ]; then - printf '\n%s\n' "Checking '.travis.yml'..." - travis lint ./.travis.yml -fi - -if [ "${1}" = "--sh" ]; then - printf '\n%s\n' "Checking shell scripts..." - - SHELLCHECK_OPTS="" - - RUN_SHELLCHECK="shellcheck ${ALLOW_EXTERNAL_SOURCE} ${SHELLCHECK_OPTS} {} +" - eval "find ./*.sh -type f -exec ${RUN_SHELLCHECK}" -fi diff --git a/package/10.12-3.8.env b/package/10.12-3.8.env new file mode 100644 index 0000000..c1f48eb --- /dev/null +++ b/package/10.12-3.8.env @@ -0,0 +1,3 @@ +ALPINE_VERSION='3.8' +PG_BASE_VERSION='10' +PG_FULL_VERSION='10.12' diff --git a/package/11.7-3.9.env b/package/11.7-3.9.env new file mode 100644 index 0000000..970ec5b --- /dev/null +++ b/package/11.7-3.9.env @@ -0,0 +1,4 @@ +ALPINE_VERSION='3.9' +PG_LATEST=false +PG_BASE_VERSION='11' +PG_FULL_VERSION='11.7' diff --git a/package/9.6.13-3.6.env b/package/9.6.13-3.6.env new file mode 100644 index 0000000..9ee2ce9 --- /dev/null +++ b/package/9.6.13-3.6.env @@ -0,0 +1,3 @@ +ALPINE_VERSION='3.6' +PG_BASE_VERSION='9' +PG_FULL_VERSION='9.6.13'