Skip to content

Commit

Permalink
add 11.7 support and improve scripts
Browse files Browse the repository at this point in the history
  • Loading branch information
abbotto committed May 15, 2020
1 parent f85b937 commit ad39c90
Show file tree
Hide file tree
Showing 10 changed files with 81 additions and 36 deletions.
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -29,4 +29,4 @@ branches:
- master

script:
- ./lint.sh --sh
- ./dev/util/shellcheck.sh
4 changes: 2 additions & 2 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ ARG alpine_version
FROM alpine:${alpine_version}

ARG alpine_version
ARG pg_package_version
ARG pg_full_version

#--------------------------------------------------------------------------------
# Install dependencies
Expand All @@ -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

Expand Down
19 changes: 19 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,25 @@

Cron based download from s3 and database restore.

## Build

`./build_push.sh [-p <FILE>, --package <FILE>]`

`./build_push.sh -p 11.7-3.8`

### 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.8'
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.
Expand Down
51 changes: 38 additions & 13 deletions build_push.sh
Original file line number Diff line number Diff line change
@@ -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 <FILE>, --package <FILE>]'
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
8 changes: 8 additions & 0 deletions dev/shellcheck.sh
Original file line number Diff line number Diff line change
@@ -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}"
6 changes: 3 additions & 3 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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_BUCKET_NAME>
AWS_REGION: <AWS_REGION_NAME>
Expand Down
17 changes: 0 additions & 17 deletions lint.sh

This file was deleted.

3 changes: 3 additions & 0 deletions package/10.12-3.8.env
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
ALPINE_VERSION='3.8'
PG_BASE_VERSION='10'
PG_FULL_VERSION='10.12'
4 changes: 4 additions & 0 deletions package/11.7-3.9.env
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
ALPINE_VERSION='3.9'
PG_LATEST=false
PG_BASE_VERSION='11'
PG_FULL_VERSION='11.7'
3 changes: 3 additions & 0 deletions package/9.6.13-3.6.env
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
ALPINE_VERSION='3.6'
PG_BASE_VERSION='9'
PG_FULL_VERSION='9.6.13'

0 comments on commit ad39c90

Please sign in to comment.