feat: split postgres.Dockerfile in two stages to not include build pkgs into the final image. It also adds the postgres user at the end
This commit is contained in:
@@ -1,4 +1,3 @@
|
|||||||
version: "3.1"
|
|
||||||
services:
|
services:
|
||||||
db:
|
db:
|
||||||
build:
|
build:
|
||||||
@@ -7,13 +6,12 @@ services:
|
|||||||
restart: "always"
|
restart: "always"
|
||||||
environment:
|
environment:
|
||||||
POSTGRES_PASSWORD: mypassword
|
POSTGRES_PASSWORD: mypassword
|
||||||
POSTGRES_DATABASE: tycho_indexer_0
|
POSTGRES_USER: postgres
|
||||||
POSTGRES_USERNAME: postgres
|
POSTGRES_DB: tycho_indexer_0
|
||||||
POSTGRESQL_SHARED_PRELOAD_LIBRARIES: pg_cron
|
|
||||||
ports:
|
ports:
|
||||||
- "5431:5432"
|
- "5431:5432"
|
||||||
shm_size: "1gb"
|
shm_size: "1gb"
|
||||||
volumes:
|
volumes:
|
||||||
- postgres_data:/var/lib/postgresql/data
|
- postgres_data:/var/lib/postgresql/data
|
||||||
volumes:
|
volumes:
|
||||||
postgres_data:
|
postgres_data:
|
||||||
|
|||||||
@@ -1,13 +1,13 @@
|
|||||||
# This Dockerfile creates a custom postgres image used for CI and local deployment.
|
# This Dockerfile creates a custom postgres image used for CI and local deployment.
|
||||||
# This is required because we use some postgres extensions that aren't in the generic
|
# Includes the extensions: pg_partman, pg_cron.
|
||||||
# Postgres image such as pg_partman or pg_cron.
|
|
||||||
|
|
||||||
# As an image with pg_partman already exist, we start from this one and add pg_cron
|
# Stage 1: Build pg_cron extension
|
||||||
# and possibly other extensions on top of that.
|
FROM ghcr.io/dbsystel/postgresql-partman:15-5 AS builder
|
||||||
FROM ghcr.io/dbsystel/postgresql-partman:15-5
|
|
||||||
ARG PGCRON_VERSION="1.6.2"
|
ARG PGCRON_VERSION="1.6.2"
|
||||||
USER root
|
USER root
|
||||||
RUN apk update && apk add --no-cache wget build-base clang19 llvm19
|
|
||||||
|
RUN apk update && apk add --no-cache build-base clang19 llvm19 wget
|
||||||
|
|
||||||
RUN cd /tmp \
|
RUN cd /tmp \
|
||||||
&& wget "https://github.com/citusdata/pg_cron/archive/refs/tags/v${PGCRON_VERSION}.tar.gz" \
|
&& wget "https://github.com/citusdata/pg_cron/archive/refs/tags/v${PGCRON_VERSION}.tar.gz" \
|
||||||
&& tar zxf v${PGCRON_VERSION}.tar.gz \
|
&& tar zxf v${PGCRON_VERSION}.tar.gz \
|
||||||
@@ -16,10 +16,16 @@ RUN cd /tmp \
|
|||||||
&& make install \
|
&& make install \
|
||||||
&& cd .. && rm -r pg_cron-${PGCRON_VERSION} v${PGCRON_VERSION}.tar.gz
|
&& cd .. && rm -r pg_cron-${PGCRON_VERSION} v${PGCRON_VERSION}.tar.gz
|
||||||
|
|
||||||
|
# Stage 2: Final image, copy built extension
|
||||||
|
FROM ghcr.io/dbsystel/postgresql-partman:15-5
|
||||||
|
USER root
|
||||||
|
|
||||||
|
COPY --from=builder /usr/local/lib/postgresql/pg_cron.so /usr/local/lib/postgresql/
|
||||||
|
COPY --from=builder /usr/local/share/postgresql/extension/pg_cron* /usr/local/share/postgresql/extension/
|
||||||
|
|
||||||
# Add configuration to postgresql.conf template
|
# Add configuration to postgresql.conf template
|
||||||
# Start with postgres database, then switch to tycho_indexer_0 after it's created
|
# Start with postgres database, then switch to tycho_indexer_0 after it's created
|
||||||
RUN echo "shared_preload_libraries = 'pg_partman_bgw,pg_cron'" >> /usr/local/share/postgresql/postgresql.conf.sample \
|
RUN echo "shared_preload_libraries = 'pg_partman_bgw,pg_cron'" >> /usr/local/share/postgresql/postgresql.conf.sample \
|
||||||
&& echo "cron.database_name = 'tycho_indexer_0'" >> /usr/local/share/postgresql/postgresql.conf.sample
|
&& echo "cron.database_name = 'tycho_indexer_0'" >> /usr/local/share/postgresql/postgresql.conf.sample
|
||||||
|
|
||||||
# Stay as root user for PostgreSQL to work properly
|
USER postgres
|
||||||
# USER 1001
|
|
||||||
|
|||||||
Reference in New Issue
Block a user