Skip to content

Commit cd5a499

Browse files
Merge pull request #2 from trycompa/init-script
setup init script
2 parents 8fa2f10 + b229b11 commit cd5a499

File tree

3 files changed

+29
-4
lines changed

3 files changed

+29
-4
lines changed

.github/workflows/_docker.yml

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,10 +22,13 @@ jobs:
2222
username: ${{ github.actor }}
2323
password: ${{ secrets.GITHUB_TOKEN }}
2424

25+
- name: 'Set up Docker Buildx'
26+
uses: docker/setup-buildx-action@v3
27+
2528
- name: 'Build Postgres Image'
2629
run: |
27-
docker build \
30+
docker buildx build \
2831
-f Dockerfile.postgres \
29-
--platform linux/amd64 \
30-
-t ghcr.io/trycompa/postgres:${{ inputs.tag }} .
31-
docker push ghcr.io/trycompa/postgres:${{ inputs.tag }}
32+
--platform linux/amd64,linux/arm64 \
33+
-t ghcr.io/trycompa/postgres:${{ inputs.tag }} \
34+
--push .

Dockerfile.postgres

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,5 +18,8 @@ RUN apt-get update && apt-get install -y \
1818
&& apt-get autoremove -y \
1919
&& rm -rf /var/lib/apt/lists/*
2020

21+
RUN mkdir -p /docker-entrypoint-initdb.d
22+
COPY ./initdb-vector.sh /docker-entrypoint-initdb.d/vector.sh
23+
2124
# log all queries
2225
CMD ["postgres", "-c", "log_statement=all"]

initdb-vector.sh

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
#!/bin/sh
2+
3+
set -e
4+
5+
# Perform all actions as $POSTGRES_USER
6+
export PGUSER="$POSTGRES_USER"
7+
8+
# Create the 'template_vector' template db
9+
"${psql[@]}" <<- 'EOSQL'
10+
CREATE DATABASE template_vector IS_TEMPLATE true;
11+
EOSQL
12+
13+
# Load vector into both template_database and $POSTGRES_DB
14+
for DB in template_postgis "$POSTGRES_DB"; do
15+
echo "Loading PostGIS extensions into $DB"
16+
"${psql[@]}" --dbname="$DB" <<-'EOSQL'
17+
CREATE EXTENSION IF NOT EXISTS vector;
18+
EOSQL
19+
done

0 commit comments

Comments
 (0)