File tree 3 files changed +115
-0
lines changed
3 files changed +115
-0
lines changed Original file line number Diff line number Diff line change
1
+ name : build container
2
+ on :
3
+ # triggered by user action only
4
+ workflow_dispatch :
5
+ inputs :
6
+ PG_VERSION :
7
+ description : ' Postgres version'
8
+ required : true
9
+ default : ' 15.3'
10
+ EXTENSIONS :
11
+ description : ' Postgres extensions to install'
12
+ required : true
13
+ default : ' cron timescaledb'
14
+ TIMESCALEDB_VERSION :
15
+ description : ' TimescaleDB version'
16
+ required : true
17
+ default : ' 2.11.0'
18
+ jobs :
19
+ build :
20
+ runs-on : ubuntu-latest
21
+ steps :
22
+ - uses : actions/checkout@v3
23
+ - uses : docker/setup-buildx-action@v2
24
+ - uses : docker/login-action@v2
25
+ # authenticate ghcr.io
26
+ with :
27
+ registry : ghcr.io
28
+ username : ${{ github.actor }}
29
+ password : ${{ secrets.GITHUB_TOKEN }}
30
+ - name : calculate image tag
31
+ id : vars
32
+ run : |
33
+ # step 1: if exists, replace extension timescaledb with its versioned equivalent
34
+ export EXTENSIONS=$(echo "${{ github.event.inputs.EXTENSIONS }}" | sed 's/timescaledb/timescaledb-${{ github.event.inputs.TIMESCALEDB_VERSION }}/g s/ /-/g')
35
+ echo ::set-output name=IMAGE_TAG::$(echo "${{ github.event.inputs.PG_VERSION }}-${EXTENSIONS}-${{ github.event.inputs.TIMESCALEDB_VERSION }}" | tr ' ' '-')
36
+ - uses : docker/build-push-action@v3
37
+ with :
38
+ context : .
39
+ file : ./Dockerfile
40
+ push : true
41
+ tags : ghcr.io/${{ github.repository }}:${{ steps.vars.outputs.IMAGE_TAG }}
42
+ build-args : |
43
+ PG_VERSION=${{ github.event.inputs.PG_VERSION }}
44
+ EXTENSIONS=${{ github.event.inputs.EXTENSIONS }}
45
+ TIMESCALEDB_VERSION=${{ github.event.inputs.TIMESCALEDB_VERSION }}
Original file line number Diff line number Diff line change
1
+ # add extensions to cnpg postgresql image: timescaledb, pg_cron
2
+ ARG POSTGRESQL_VERSION=15.3
3
+ ARG EXTENSIONS="timescaledb cron"
4
+ ARG TIMESCALEDB_VERSION=2.11.0
5
+
6
+
7
+ FROM ghcr.io/cloudnative-pg/postgresql:${POSTGRESQL_VERSION}
8
+ ARG EXTENSIONS
9
+ ENV EXTENSIONS=${EXTENSIONS}
10
+ ARG TIMESCALEDB_VERSION
11
+ ENV TIMESCALEDB_VERSION=${TIMESCALEDB_VERSION}
12
+
13
+ COPY ./install_pg_extensions.sh /
14
+ # switch to root user to install extensions
15
+ USER root
16
+ RUN \
17
+ apt-get update && \
18
+ /install_pg_extensions.sh ${EXTENSIONS} && \
19
+ # cleanup
20
+ apt-get clean && \
21
+ rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/* /install_pg_extensions.sh
22
+ # switch back to the postgres user
23
+ USER postgres
Original file line number Diff line number Diff line change
1
+ #! /bin/bash
2
+ set -euxo pipefail
3
+
4
+ # calling syntax: install_pg_extensions.sh [extension1] [extension2] ...
5
+
6
+ # install extensions
7
+ EXTENSIONS=" $@ "
8
+ # cycle through extensions list
9
+ for EXTENSION in ${EXTENSIONS} ; do
10
+ # is it an extension found in apt?
11
+ if apt-cache show " postgresql-${PG_MAJOR} -${EXTENSION} " & > /dev/null; then
12
+ # install the extension
13
+ apt-get install -y " postgresql-${PG_MAJOR} -${EXTENSION} "
14
+ continue
15
+ fi
16
+
17
+ # special case: timescaledb
18
+ if [ " $EXTENSION " == " timescaledb" ]; then
19
+ # dependencies
20
+ apt-get install apt-transport-https lsb-release wget -y
21
+
22
+ # repository
23
+ echo " deb https://packagecloud.io/timescale/timescaledb/debian/" \
24
+ " $( lsb_release -c -s) main" \
25
+ > /etc/apt/sources.list.d/timescaledb.list
26
+
27
+ # key
28
+ wget --quiet -O - https://packagecloud.io/timescale/timescaledb/gpgkey \
29
+ | gpg --dearmor > /etc/apt/trusted.gpg.d/timescaledb.gpg
30
+
31
+ apt-get update
32
+ apt-get install --yes \
33
+ timescaledb-tools \
34
+ timescaledb-toolkit-postgresql-${PG_MAJOR} \
35
+ timescaledb-2-loader-postgresql-${PG_MAJOR} \
36
+ timescaledb-2-${TIMESCALEDB_VERSION} -postgresql-${PG_MAJOR}
37
+
38
+ # cleanup
39
+ apt-get remove apt-transport-https lsb-release wget --auto-remove -y
40
+
41
+ continue
42
+ fi
43
+
44
+ # extension not found/supported
45
+ echo " Extension '${EXTENSION} ' not found/supported"
46
+ exit 1
47
+ done
You can’t perform that action at this time.
0 commit comments