Skip to content

Commit 7b01d6f

Browse files
committed
add 11.7 support and improve scripts
1 parent f85b937 commit 7b01d6f

10 files changed

Lines changed: 81 additions & 36 deletions

File tree

.travis.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,4 +29,4 @@ branches:
2929
- master
3030

3131
script:
32-
- ./lint.sh --sh
32+
- ./dev/util/shellcheck.sh

Dockerfile

Lines changed: 2 additions & 2 deletions
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} py-pip && \
15+
RUN apk --no-cache --update add dumb-init postgresql=${pg_full_version} py-pip && \
1616
pip install awscli && \
1717
apk --purge -v del py-pip
1818

README.md

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,25 @@
22

33
Cron based download from s3 and database restore.
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 downloading a dump file from s3 and restoring a database at a particular time of day.

build_push.sh

Lines changed: 38 additions & 13 deletions
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_restore_from_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-RESTORE-FROM-S3 TAG: ${pg_restore_from_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-restore-from-s3:$pg_restore_from_s3_tag --build-arg pg_package_version=$pg_package_version --build-arg alpine_version="${alpine_version}" .
28-
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
52+
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}" .
53+
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
2954
echo docker push bluedrop360/postgres-restore-from-s3:$pg_restore_from_s3_tag
3055
eval docker push bluedrop360/postgres-restore-from-s3:$pg_restore_from_s3_tag || exit 1
3156
done

dev/util/shellcheck.sh

Lines changed: 8 additions & 0 deletions
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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,14 +11,14 @@ version: '3'
1111

1212
services:
1313
postgres-restore-from-s3:
14-
image: postgres-restore-from-s3:10.10
14+
image: postgres-restore-from-s3:11.7
1515
network_mode: 'host'
1616
build:
1717
context: ./
1818
dockerfile: ./Dockerfile
1919
args:
20-
pg_alpine_branch: '3.8'
21-
pg_version: '10.10-r0'
20+
alpine_version: '3.9'
21+
pg_full_version: '11.7-r0'
2222
environment:
2323
AWS_BUCKET: <AWS_BUCKET_NAME>
2424
AWS_REGION: <AWS_REGION_NAME>

lint.sh

Lines changed: 0 additions & 17 deletions
This file was deleted.

package/10.12-3.8.env

Lines changed: 3 additions & 0 deletions
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

Lines changed: 4 additions & 0 deletions
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

Lines changed: 3 additions & 0 deletions
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)