Skip to content

Instantly share code, notes, and snippets.

@Hadryan
Forked from jgould22/Dockerfile
Created November 22, 2022 08:02
Show Gist options
  • Save Hadryan/a62416f952b4c5f466c8f49f56719683 to your computer and use it in GitHub Desktop.
Save Hadryan/a62416f952b4c5f466c8f49f56719683 to your computer and use it in GitHub Desktop.

Revisions

  1. @jgould22 jgould22 revised this gist Oct 24, 2022. 1 changed file with 22 additions and 3 deletions.
    25 changes: 22 additions & 3 deletions Dockerfile
    Original file line number Diff line number Diff line change
    @@ -1,27 +1,33 @@
    FROM postgres:14-alpine
    FROM postgres:15-alpine
    LABEL maintainer="Jordan Gould <[email protected]>"
    # Based on https://github.com/andreaswachowski/docker-postgres/blob/master/initdb.sh

    ENV PG_JOBMON_VERSION v1.4.1
    ENV PG_PARTMAN_VERSION v4.6.0
    ENV PG_PARTMAN_VERSION v4.7.1

    # Install pg_jobmon
    RUN set -ex \
    \
    # Get some basic deps required to download the extensions and name them fetch-deps so we can delete them later
    && apk add --no-cache --virtual .fetch-deps \
    ca-certificates \
    openssl \
    tar \
    \
    # Download pg_jobmon
    && wget -O pg_jobmon.tar.gz "https://github.com/omniti-labs/pg_jobmon/archive/$PG_JOBMON_VERSION.tar.gz" \
    # Make a dir to store the src files
    && mkdir -p /usr/src/pg_jobmon \
    # Extract the src files
    && tar \
    --extract \
    --file pg_jobmon.tar.gz \
    --directory /usr/src/pg_jobmon \
    --strip-components 1 \
    # Delete the src tar
    && rm pg_jobmon.tar.gz \
    \
    # Get the depends required to build pg_jobmon and name this set of depends build-deps so we can delete them later
    && apk add --no-cache --virtual .build-deps \
    autoconf \
    automake \
    @@ -32,27 +38,40 @@ RUN set -ex \
    libxml2-dev \
    make \
    perl \
    # Change to the src
    && cd /usr/src/pg_jobmon \
    # Build the extenison
    && make \
    # Install the extension
    && make install \
    # Return to home so we are ready for the next step
    && cd / \
    # Delete the src files from this step
    && rm -rf /usr/src/pg_jobmon

    # Install pg_partman
    RUN set -ex \
    # Download pg_partman
    && wget -O pg_partman.tar.gz "https://github.com/pgpartman/pg_partman/archive/$PG_PARTMAN_VERSION.tar.gz" \
    # Create a folder to put the src files in
    && mkdir -p /usr/src/pg_partman \
    # Extract the src files
    && tar \
    --extract \
    --file pg_partman.tar.gz \
    --directory /usr/src/pg_partman \
    --strip-components 1 \
    # Delete src file tar
    && rm pg_partman.tar.gz \
    # Move to src file folder
    && cd /usr/src/pg_partman \
    # Build the extension
    && make \
    # Install the extension
    && make install \
    && cd / \
    # Delete the src files for pg_partman
    && rm -rf /usr/src/pg_partman \
    # Delete the dependancies for downloading and building the extensions, we no longer need them
    && apk del .fetch-deps .build-deps

    # Copy the init script
  2. @jgould22 jgould22 renamed this gist Jan 17, 2022. 1 changed file with 3 additions and 3 deletions.
    6 changes: 3 additions & 3 deletions Dockerfile.yml → Dockerfile
    Original file line number Diff line number Diff line change
    @@ -1,9 +1,9 @@
    FROM postgres:13-alpine
    FROM postgres:14-alpine
    LABEL maintainer="Jordan Gould <[email protected]>"
    # Based on https://github.com/andreaswachowski/docker-postgres/blob/master/initdb.sh

    ENV PG_JOBMON_VERSION v1.3.3
    ENV PG_PARTMAN_VERSION v4.4.0
    ENV PG_JOBMON_VERSION v1.4.1
    ENV PG_PARTMAN_VERSION v4.6.0

    # Install pg_jobmon
    RUN set -ex \
  3. @jgould22 jgould22 revised this gist Oct 17, 2020. No changes.
  4. @jgould22 jgould22 revised this gist Oct 17, 2020. 1 changed file with 3 additions and 3 deletions.
    6 changes: 3 additions & 3 deletions Dockerfile.yml
    Original file line number Diff line number Diff line change
    @@ -1,9 +1,9 @@
    FROM postgres:12-alpine
    MAINTAINER Jordan Gould <[email protected]>
    FROM postgres:13-alpine
    LABEL maintainer="Jordan Gould <[email protected]>"
    # Based on https://github.com/andreaswachowski/docker-postgres/blob/master/initdb.sh

    ENV PG_JOBMON_VERSION v1.3.3
    ENV PG_PARTMAN_VERSION v4.4.0
    ENV PG_PARTMAN_VERSION v4.4.0

    # Install pg_jobmon
    RUN set -ex \
  5. @jgould22 jgould22 revised this gist Jun 22, 2020. 1 changed file with 4 additions and 2 deletions.
    6 changes: 4 additions & 2 deletions Dockerfile.yml
    Original file line number Diff line number Diff line change
    @@ -3,7 +3,7 @@ MAINTAINER Jordan Gould <[email protected]>
    # Based on https://github.com/andreaswachowski/docker-postgres/blob/master/initdb.sh

    ENV PG_JOBMON_VERSION v1.3.3
    ENV PG_PARTMAN_VERSION v4.2.2
    ENV PG_PARTMAN_VERSION v4.4.0

    # Install pg_jobmon
    RUN set -ex \
    @@ -26,6 +26,8 @@ RUN set -ex \
    autoconf \
    automake \
    g++ \
    clang \
    llvm \
    libtool \
    libxml2-dev \
    make \
    @@ -56,4 +58,4 @@ RUN set -ex \
    # Copy the init script
    # The Docker Postgres initd script will run anything
    # in the directory /docker-entrypoint-initdb.d
    COPY initdb.sh /docker-entrypoint-initdb.d/initdb.sh
    COPY initdb.sh /docker-entrypoint-initdb.d/initdb.sh
  6. @jgould22 jgould22 created this gist Nov 12, 2019.
    59 changes: 59 additions & 0 deletions Dockerfile.yml
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,59 @@
    FROM postgres:12-alpine
    MAINTAINER Jordan Gould <[email protected]>
    # Based on https://github.com/andreaswachowski/docker-postgres/blob/master/initdb.sh

    ENV PG_JOBMON_VERSION v1.3.3
    ENV PG_PARTMAN_VERSION v4.2.2

    # Install pg_jobmon
    RUN set -ex \
    \
    && apk add --no-cache --virtual .fetch-deps \
    ca-certificates \
    openssl \
    tar \
    \
    && wget -O pg_jobmon.tar.gz "https://github.com/omniti-labs/pg_jobmon/archive/$PG_JOBMON_VERSION.tar.gz" \
    && mkdir -p /usr/src/pg_jobmon \
    && tar \
    --extract \
    --file pg_jobmon.tar.gz \
    --directory /usr/src/pg_jobmon \
    --strip-components 1 \
    && rm pg_jobmon.tar.gz \
    \
    && apk add --no-cache --virtual .build-deps \
    autoconf \
    automake \
    g++ \
    libtool \
    libxml2-dev \
    make \
    perl \
    && cd /usr/src/pg_jobmon \
    && make \
    && make install \
    && cd / \
    && rm -rf /usr/src/pg_jobmon

    # Install pg_partman
    RUN set -ex \
    && wget -O pg_partman.tar.gz "https://github.com/pgpartman/pg_partman/archive/$PG_PARTMAN_VERSION.tar.gz" \
    && mkdir -p /usr/src/pg_partman \
    && tar \
    --extract \
    --file pg_partman.tar.gz \
    --directory /usr/src/pg_partman \
    --strip-components 1 \
    && rm pg_partman.tar.gz \
    && cd /usr/src/pg_partman \
    && make \
    && make install \
    && cd / \
    && rm -rf /usr/src/pg_partman \
    && apk del .fetch-deps .build-deps

    # Copy the init script
    # The Docker Postgres initd script will run anything
    # in the directory /docker-entrypoint-initdb.d
    COPY initdb.sh /docker-entrypoint-initdb.d/initdb.sh
    35 changes: 35 additions & 0 deletions initdb.sh
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,35 @@
    #!/bin/bash -e

    echo "Creating dblink extension"
    psql -v ON_ERROR_STOP=1 --username "$POSTGRES_USER" --dbname "$POSTGRES_DB" <<-EOSQL
    CREATE SCHEMA dblink;
    CREATE EXTENSION dblink SCHEMA dblink;
    EOSQL

    echo "Creating jobmon extension"
    psql -v ON_ERROR_STOP=1 --username "$POSTGRES_USER" --dbname "$POSTGRES_DB" <<-EOSQL
    CREATE SCHEMA jobmon;
    CREATE EXTENSION pg_jobmon SCHEMA jobmon;
    INSERT INTO jobmon.dblink_mapping_jobmon (username, pwd) VALUES ('$POSTGRES_USER', '$POSTGRES_PASSWORD');
    EOSQL

    echo "Creating partman extension"
    psql -v ON_ERROR_STOP=1 --username "$POSTGRES_USER" --dbname "$POSTGRES_DB" <<-EOSQL
    CREATE SCHEMA partman;
    CREATE EXTENSION pg_partman SCHEMA partman;
    EOSQL

    echo "Adding jobmon permissions"
    psql -v ON_ERROR_STOP=1 --username "$POSTGRES_USER" --dbname "$POSTGRES_DB" <<-EOSQL
    GRANT USAGE ON SCHEMA jobmon TO $POSTGRES_USER;
    GRANT USAGE ON SCHEMA dblink TO $POSTGRES_USER;
    GRANT SELECT, INSERT, UPDATE, DELETE ON ALL TABLES IN SCHEMA jobmon TO $POSTGRES_USER;
    GRANT EXECUTE ON ALL FUNCTIONS IN SCHEMA jobmon TO $POSTGRES_USER;
    GRANT ALL ON ALL SEQUENCES IN SCHEMA jobmon TO $POSTGRES_USER;
    EOSQL

    echo "ADDING pg_partman_bgw TO postgresql.conf"
    echo "shared_preload_libraries = 'pg_partman_bgw'" >> $PGDATA/postgresql.conf
    echo "pg_partman_bgw.interval = 3600" >> $PGDATA/postgresql.conf
    echo "pg_partman_bgw.role = '$POSTGRES_USER'" >> $PGDATA/postgresql.conf
    echo "pg_partman_bgw.dbname = '$POSTGRES_DB'" >> $PGDATA/postgresql.conf