Skip to content

Commit

Permalink
Build postgresql image with bitnami/postgres as a base image
Browse files Browse the repository at this point in the history
Install required tools for doing backup operation

Signed-off-by: Prasad Ghangal <prasad.ghangal@gmail.com>
  • Loading branch information
PrasadG193 committed Aug 28, 2019
1 parent da43bcd commit 95136fd
Show file tree
Hide file tree
Showing 3 changed files with 53 additions and 0 deletions.
5 changes: 5 additions & 0 deletions .goreleaser.yml
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,11 @@ dockers:
image_templates:
- 'kanisterio/postgres-kanister-tools:{{ .Tag }}'
dockerfile: 'docker/postgres-kanister-tools/Dockerfile'
- image_templates:
- 'kanisterio/postgresql:{{ .Tag }}'
dockerfile: 'docker/postgresql/Dockerfile'
extra_files:
- 'docker/postgresql/run.sh'
- binaries:
- kando
image_templates:
Expand Down
23 changes: 23 additions & 0 deletions docker/postgresql/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
FROM bitnami/postgresql:11.5.0-debian-9-r1

USER root

# Explicitly set user/group IDs
RUN useradd -r --gid=0 --uid=1001 postgres

# Install required components for backup
RUN set -x \
&& apt-get update \
&& apt-get install -y curl groff lzop pv postgresql-client python3-pip daemontools \
&& pip3 install --upgrade pip \
&& hash -r pip3 \
&& pip3 install wal-e[aws] \
&& pip3 install awscli \
&& (cd /usr/local/bin; curl -L https://github.com/wal-g/wal-g/releases/download/v0.1.7/wal-g.linux-amd64.tar.gz | tar -zxv)

# Override base image's CMD script
COPY docker/postgresql/run.sh /

RUN chown postgres:root /run.sh

USER postgres
25 changes: 25 additions & 0 deletions docker/postgresql/run.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
#!/bin/bash
# Forked from https://github.com/bitnami/bitnami-docker-postgresql/blob/master/11/debian-9/rootfs/run.sh
# to modify runtime args

set -o errexit
set -o nounset
set -o pipefail
# set -o xtrace # Uncomment this line for debugging purpose
# shellcheck disable=SC1091

# Load libraries
. /libpostgresql.sh
. /libos.sh

# Load PostgreSQL environment variables
eval "$(postgresql_env)"
readonly flags=("-D" "$POSTGRESQL_DATA_DIR" "--config-file=$POSTGRESQL_CONF_FILE" "--external_pid_file=$POSTGRESQL_PID_FILE" "--hba_file=$POSTGRESQL_PGHBA_FILE" "-c" "archive_command=envdir \"${PGDATA}/env\" wal-e wal-push %p" "-c" "archive_mode=true" "-c" "archive_timeout=60" "-c" "wal_level=archive")
readonly cmd=$(command -v postgres)

info "** Starting PostgreSQL **"
if am_i_root; then
exec gosu "$POSTGRESQL_DAEMON_USER" "${cmd}" "${flags[@]}"
else
exec "${cmd}" "${flags[@]}"
fi

0 comments on commit 95136fd

Please sign in to comment.