Skip to content

Commit fa42e1a

Browse files
author
Jared Abbott
committed
add 11.7 support and improve scripts
1 parent e2292da commit fa42e1a

10 files changed

+138
-15
lines changed

.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
docker-compose.override.yml

.travis.yml

+32
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
language: node_js
2+
3+
notifications:
4+
email: false
5+
6+
sudo: false
7+
8+
node_js:
9+
- "10"
10+
11+
dist: trusty
12+
13+
before_install:
14+
- sudo apt-add-repository "deb http://archive.ubuntu.com/ubuntu trusty-backports main restricted universe multiverse"
15+
- sudo apt-get -qq update
16+
- sudo apt-get install xz-utils
17+
- export scversion="stable"
18+
- wget "https://storage.googleapis.com/shellcheck/shellcheck-${scversion}.linux.x86_64.tar.xz"
19+
- tar --xz -xvf shellcheck-"${scversion}".linux.x86_64.tar.xz
20+
- sudo cp shellcheck-"${scversion}"/shellcheck /usr/bin/
21+
- shellcheck --version
22+
- export ALLOW_EXTERNAL_SOURCE='-x '
23+
24+
env:
25+
- CXX=g++-4.8
26+
27+
branches:
28+
only:
29+
- master
30+
31+
script:
32+
- ./dev/util/shellcheck.sh

Dockerfile

+2-2
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ ARG alpine_version
22
FROM alpine:${alpine_version}
33

44
ARG alpine_version
5-
ARG pg_package_version
5+
ARG pg_full_version
66

77
#--------------------------------------------------------------------------------
88
# Install dependencies
@@ -12,7 +12,7 @@ ARG pg_package_version
1212
#--------------------------------------------------------------------------------
1313
RUN echo "http://dl-cdn.alpinelinux.org/alpine/v${alpine_version}/main" >> /etc/apk/repositories
1414

15-
RUN apk --no-cache --update add dumb-init postgresql=${pg_package_version} curl python3 && \
15+
RUN apk --no-cache --update add dumb-init postgresql=${pg_full_version} curl python3 && \
1616
curl https://bootstrap.pypa.io/get-pip.py | python3 && \
1717
pip install awscli && \
1818
rm -f /usr/bin/pip && \

README.md

+19
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,25 @@
22

33
Cron based database dump and upload to S3.
44

5+
## Build
6+
7+
`./build_push.sh [-p <FILE>, --package <FILE>]`
8+
9+
`./build_push.sh -p 11.7-3.9`
10+
11+
### Package files
12+
13+
Each package file represents a release for a particular `postgres` branch.
14+
15+
The contents of the latest package file may look like this:
16+
17+
```
18+
ALPINE_VERSION='3.9'
19+
PG_BASE_VERSION='11'
20+
PG_FULL_VERSION='11.7'
21+
PG_LATEST=true
22+
```
23+
524
## Usage
625

726
Typically this image is instantiated as a container among many others and would have the responsibility of getting a database dump and uploading it to S3 at a particular time of day.

build_push.sh

+38-13
Original file line numberDiff line numberDiff line change
@@ -1,31 +1,56 @@
11
#!/usr/bin/env sh
22

3-
alpine_version='3.8'
4-
legacy_image=false
5-
pg_major_version='10'
6-
pg_package_version='10.10'
3+
#------------------------------------------------------------------------------------
4+
# Loop over arguments
5+
#------------------------------------------------------------------------------------
6+
for arg in "$@"; do
7+
# [ -p | --package ]
8+
if [ -n "${package_flag}" ]; then
9+
package_flag=''
10+
package="${arg}"
11+
fi
12+
13+
if [ "${arg}" = "-p" ] || [ "${arg}" = "--package" ]; then
14+
package_flag=true
15+
fi
16+
done
17+
18+
#------------------------------------------------------------------------------------
19+
# Exit on error
20+
#------------------------------------------------------------------------------------
21+
if [ -z "${package}" ]; then
22+
echo '> Package file not specified: [-p <FILE>, --package <FILE>]'
23+
exit 127
24+
fi
25+
26+
if [ -f "./package/${package}.env" ]; then
27+
. "./package/${package}.env"
28+
else
29+
echo "> Package file not found: './package/${package}.env'"
30+
exit 127
31+
fi
732

833
builds=\
9-
"${pg_package_version}_${pg_package_version}-r0_${alpine_version}",\
10-
"${pg_major_version}_${pg_package_version}-r0_${alpine_version}"
34+
"${PG_FULL_VERSION}_${PG_FULL_VERSION}-r0_${ALPINE_VERSION}",\
35+
"${PG_BASE_VERSION}_${PG_FULL_VERSION}-r0_${ALPINE_VERSION}"
1136

12-
if [ "${legacy_image}" = 'false' ]; then
13-
builds="${builds}","latest_${pg_package_version}-r0_${alpine_version}"
37+
if [ "${PG_LATEST:-'false'}" = 'true' ]; then
38+
builds="${builds}","latest_${PG_FULL_VERSION}-r0_${ALPINE_VERSION}"
1439
fi
1540

1641
echo $builds | tr ',' '\n' | while read build; do
17-
alpine_version=$(echo "${build}" | cut -d '_' -f 3)
42+
ALPINE_VERSION=$(echo "${build}" | cut -d '_' -f 3)
1843
pg_dump_to_s3_tag=$(echo "${build}" | cut -d '_' -f 1 )
19-
pg_package_version=$(echo "${build}" | cut -d '_' -f 2)
44+
PG_FULL_VERSION=$(echo "${build}" | cut -d '_' -f 2)
2045

2146
echo ""
2247
echo "--------------------------------"
2348
echo "POSTGRES-DUMP-TO-S3 TAG: ${pg_dump_to_s3_tag}"
24-
echo "POSTGRES PACKAGE VERSION: ${pg_package_version}"
49+
echo "POSTGRES PACKAGE VERSION: ${PG_FULL_VERSION}"
2550
echo "--------------------------------"
2651

27-
echo docker build --tag bluedrop360/postgres-dump-to-s3:$pg_dump_to_s3_tag --build-arg pg_package_version=$pg_package_version --build-arg alpine_version="${alpine_version}" .
28-
eval docker build --tag bluedrop360/postgres-dump-to-s3:$pg_dump_to_s3_tag --build-arg pg_package_version=$pg_package_version --build-arg alpine_version="${alpine_version}" . || exit 1
52+
echo docker build --tag bluedrop360/postgres-dump-to-s3:$pg_dump_to_s3_tag --build-arg pg_full_version=$PG_FULL_VERSION --build-arg alpine_version="${ALPINE_VERSION}" .
53+
eval docker build --tag bluedrop360/postgres-dump-to-s3:$pg_dump_to_s3_tag --build-arg pg_full_version=$PG_FULL_VERSION --build-arg alpine_version="${ALPINE_VERSION}" . || exit 1
2954
echo docker push bluedrop360/postgres-dump-to-s3:$pg_dump_to_s3_tag
3055
eval docker push bluedrop360/postgres-dump-to-s3:$pg_dump_to_s3_tag || exit 1
3156
done

dev/util/shellcheck.sh

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
#!/usr/bin/env sh
2+
3+
printf '\n%s\n' "Checking shell scripts..."
4+
5+
SHELLCHECK_OPTS=""
6+
7+
RUN_SHELLCHECK="shellcheck ${ALLOW_EXTERNAL_SOURCE:-} ${SHELLCHECK_OPTS} {} +"
8+
eval "find ./*.sh -type f -exec ${RUN_SHELLCHECK}"

docker-compose.yml

+28
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
########################################################
2+
# Docker Compose: https://docs.docker.com/compose
3+
########################################################
4+
# This file is for local testing
5+
# - Copy contents to `docker-compose.override.yml`
6+
# - Update the volume and environment variable values
7+
# - BUILD: docker-compose build
8+
# - BUILD AND RUN: docker-compose up --build
9+
########################################################
10+
version: '3'
11+
12+
services:
13+
postgres-restore-from-s3:
14+
image: postgres-restore-from-s3:11.7
15+
network_mode: 'host'
16+
build:
17+
context: ./
18+
dockerfile: ./Dockerfile
19+
args:
20+
alpine_version: '3.9'
21+
pg_full_version: '11.7-r0'
22+
environment:
23+
AWS_BUCKET: <AWS_BUCKET_NAME>
24+
AWS_REGION: <AWS_REGION_NAME>
25+
DATABASE_URL: postgres://<DB_NAME>:<PASSPHRASE>@<HOST>:<PORT>/<DB_NAME>
26+
DUMP_OBJECT_PREFIX: <DB_NAME>/postgres/
27+
volumes:
28+
- <PROJECT_DIRECTORY>/build/postgres/dump:/cache:rw

package/10.12-3.8.env

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
ALPINE_VERSION='3.8'
2+
PG_BASE_VERSION='10'
3+
PG_FULL_VERSION='10.12'

package/11.7-3.9.env

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
ALPINE_VERSION='3.9'
2+
PG_LATEST=false
3+
PG_BASE_VERSION='11'
4+
PG_FULL_VERSION='11.7'

package/9.6.13-3.6.env

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
ALPINE_VERSION='3.6'
2+
PG_BASE_VERSION='9'
3+
PG_FULL_VERSION='9.6.13'

0 commit comments

Comments
 (0)