Skip to content

Upgrade to Postgres 12.4 #2

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 13 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
16 changes: 6 additions & 10 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,20 +1,16 @@
ARG pg_alpine_branch
FROM alpine:${pg_alpine_branch}
ARG alpine_version
FROM alpine:${alpine_version}

ARG pg_alpine_branch
ARG pg_version
ARG alpine_version
ARG pg_full_version

#--------------------------------------------------------------------------------
# Install dependencies
#--------------------------------------------------------------------------------
# "postgresql" is required for "pg_restore"
# "python" is required for "aws-cli"
#--------------------------------------------------------------------------------
RUN echo "http://dl-cdn.alpinelinux.org/alpine/v${pg_alpine_branch}/main" >> /etc/apk/repositories

RUN apk --no-cache add dumb-init postgresql=${pg_version} python py-pip && \
pip install awscli && \
apk --purge -v del py-pip
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_full_version} aws-cli

#--------------------------------------------------------------------------------
# Set script permissions and create required directories
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 12.4-3.12`

### 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.12'
PG_BASE_VERSION='12'
PG_FULL_VERSION='12.4'
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
4 changes: 2 additions & 2 deletions action.sh
Original file line number Diff line number Diff line change
Expand Up @@ -100,10 +100,10 @@ if [ -n "$PRE_RESTORE_PSQL" ]; then
fi

if [ -n "$SCHEMA" ]; then
printf '%s' " pg_restore --jobs $(grep -c ^processor /proc/cpuinfo) --schema $SCHEMA --no-owner -d <DATABASE_URL> /cache/${dump_file}"
printf '\n%s' " pg_restore --jobs $(grep -c ^processor /proc/cpuinfo) --schema $SCHEMA --no-owner -d <DATABASE_URL> /cache/${dump_file}"
pg_restore --jobs "$(grep -c ^processor /proc/cpuinfo)" --schema "$SCHEMA" --no-owner -d "${DATABASE_URL}" "/cache/${dump_file}"
else
printf '%s' " pg_restore --jobs $(grep -c ^processor /proc/cpuinfo) --no-owner -d <DATABASE_URL> /cache/${dump_file}"
printf '\n%s' " pg_restore --jobs $(grep -c ^processor /proc/cpuinfo) --no-owner -d <DATABASE_URL> /cache/${dump_file}"
pg_restore --jobs "$(grep -c ^processor /proc/cpuinfo)" --no-owner -d "${DATABASE_URL}" "/cache/${dump_file}"
fi

Expand Down
71 changes: 53 additions & 18 deletions build_push.sh
Original file line number Diff line number Diff line change
@@ -1,21 +1,56 @@
#!/usr/bin/env sh

builds=$(echo '
9.6.10 9.6.10-r0 3.6
9.6 9.6.10-r0 3.6
9 9.6.10-r0 3.6
latest 9.6.10-r0 3.6
' | grep -v '^#' | tr -s ' ')

# shellcheck disable=SC2039
IFS=$'\n'
for build in $builds; do
tag=$(echo "${build}" | cut -d ' ' -f 1 )
pg_version=$(echo "${build}" | cut -d ' ' -f 2)
pg_alpine_version=$(echo "${build}" | cut -d ' ' -f 3)

echo docker build --tag bluedrop360/postgres-restore-from-s3:"${tag}" --build-arg pg_version="${pg_version}" --build-arg pg_alpine_branch="${pg_alpine_version}" .
eval docker build --tag bluedrop360/postgres-restore-from-s3:"${tag}" --build-arg pg_version="${pg_version}" --build-arg pg_alpine_branch="${pg_alpine_version}" .
echo docker push bluedrop360/postgres-restore-from-s3:"${tag}"
eval docker push bluedrop360/postgres-restore-from-s3:"${tag}"
#------------------------------------------------------------------------------------
# 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_FULL_VERSION}_${PG_FULL_VERSION}-r0_${ALPINE_VERSION}",\
"${PG_BASE_VERSION}_${PG_FULL_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)
pg_restore_from_s3_tag=$(echo "${build}" | cut -d '_' -f 1 )
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_FULL_VERSION}"
echo "--------------------------------"

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/util/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:9.6.10
image: postgres-restore-from-s3:11.7
network_mode: 'host'
build:
context: ./
dockerfile: ./Dockerfile
args:
pg_alpine_branch: '3.6'
pg_version: '9.6.10-r0'
alpine_version: '3.12'
pg_full_version: '12.4-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'
4 changes: 4 additions & 0 deletions package/12.4-3.12.env
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
ALPINE_VERSION='3.12'
PG_LATEST=false
PG_BASE_VERSION='12'
PG_FULL_VERSION='12.4'
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'