Skip to content

Commit

Permalink
feat(monorepo): update docker-compose.yml to use custom pg image (#33)
Browse files Browse the repository at this point in the history
Create a custom Docker image for Postgres to add the
citext extension to the database upon initialization.
  • Loading branch information
mpellegrini authored Mar 26, 2024
1 parent 4d4b068 commit 995d350
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 5 deletions.
4 changes: 4 additions & 0 deletions .docker/PgDockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
FROM postgres:16.2-alpine

# Copy in the load-extensions script
COPY initdb-extensions.sh /docker-entrypoint-initdb.d/
11 changes: 11 additions & 0 deletions .docker/initdb-extensions.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
#!/bin/sh

set -e

echo "Loading extensions into $DB"

psql -v ON_ERROR_STOP=1 --username "$POSTGRES_USER" --dbname "$POSTGRES_DB" <<-EOSQL
# must quote extension names or else symbolic error will be thrown.
CREATE EXTENSION IF NOT EXISTS 'citext';
select * FROM pg_extension;
EOSQL
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -55,4 +55,4 @@ vite.config.ts.timestamp-*
.vercel/

# local docker volumes
/.docker/
/.docker/data
2 changes: 1 addition & 1 deletion .prettierignore
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ vite.config.ts.timestamp-*
.vercel/

# local docker volumes
/.docker/
/.docker/data

#-------------------------------------------------------------------------------------------------------------------
# Prettier-specific overrides
Expand Down
8 changes: 5 additions & 3 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
services:
postgres:
image: postgres:16.2-alpine
build:
context: ./.docker
dockerfile: PgDockerfile
restart: always
environment:
- POSTGRES_USER=postgres
Expand All @@ -13,7 +15,7 @@ services:
ports:
- '5432:5432'
volumes:
- ./.docker/pg-data:/var/lib/postgresql/data
- ./.docker/data/pg-data:/var/lib/postgresql/data

mailpit:
image: axllent/mailpit
Expand All @@ -27,4 +29,4 @@ services:
- 8025:8025
- 1025:1025
volumes:
- ./.docker/mailpit-data:/data
- ./.docker/data/mailpit-data:/data

0 comments on commit 995d350

Please sign in to comment.