diff --git a/.github/workflows/_docker.yml b/.github/workflows/_docker.yml index eb00b2f..37a0606 100644 --- a/.github/workflows/_docker.yml +++ b/.github/workflows/_docker.yml @@ -22,10 +22,13 @@ jobs: username: ${{ github.actor }} password: ${{ secrets.GITHUB_TOKEN }} + - name: 'Set up Docker Buildx' + uses: docker/setup-buildx-action@v3 + - name: 'Build Postgres Image' run: | - docker build \ + docker buildx build \ -f Dockerfile.postgres \ - --platform linux/amd64 \ - -t ghcr.io/trycompa/postgres:${{ inputs.tag }} . - docker push ghcr.io/trycompa/postgres:${{ inputs.tag }} \ No newline at end of file + --platform linux/amd64,linux/arm64 \ + -t ghcr.io/trycompa/postgres:${{ inputs.tag }} \ + --push . diff --git a/Dockerfile.postgres b/Dockerfile.postgres index 2c28b9a..d662ec0 100644 --- a/Dockerfile.postgres +++ b/Dockerfile.postgres @@ -18,5 +18,8 @@ RUN apt-get update && apt-get install -y \ && apt-get autoremove -y \ && rm -rf /var/lib/apt/lists/* +RUN mkdir -p /docker-entrypoint-initdb.d +COPY ./initdb-vector.sh /docker-entrypoint-initdb.d/vector.sh + # log all queries CMD ["postgres", "-c", "log_statement=all"] diff --git a/initdb-vector.sh b/initdb-vector.sh new file mode 100644 index 0000000..5564b88 --- /dev/null +++ b/initdb-vector.sh @@ -0,0 +1,19 @@ +#!/bin/sh + +set -e + +# Perform all actions as $POSTGRES_USER +export PGUSER="$POSTGRES_USER" + +# Create the 'template_vector' template db +"${psql[@]}" <<- 'EOSQL' +CREATE DATABASE template_vector IS_TEMPLATE true; +EOSQL + +# Load vector into both template_database and $POSTGRES_DB +for DB in template_postgis "$POSTGRES_DB"; do + echo "Loading PostGIS extensions into $DB" + "${psql[@]}" --dbname="$DB" <<-'EOSQL' + CREATE EXTENSION IF NOT EXISTS vector; +EOSQL +done \ No newline at end of file