Skip to content

Commit

Permalink
feat: add postgres
Browse files Browse the repository at this point in the history
  • Loading branch information
bhunter234 committed Aug 31, 2024
1 parent 78cb773 commit 48cc174
Show file tree
Hide file tree
Showing 6 changed files with 178 additions and 1 deletion.
6 changes: 6 additions & 0 deletions .github/dependabot.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
version: 2
updates:
- package-ecosystem: "github-actions"
directory: "/"
schedule:
interval: "daily"
49 changes: 49 additions & 0 deletions .github/workflows/postgres.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
name: Build Postgres

on:
schedule:
- cron: '0 0 1 * *'
workflow_dispatch:

jobs:
build-postgres:
runs-on: ubuntu-latest
permissions:
packages: write
steps:
- name: Checkout
uses: actions/checkout@v4
with:
fetch-depth: 0

- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3

- name: Set up QEMU
uses: docker/setup-qemu-action@v3

- name: Login to GitHub Container Registry
uses: docker/login-action@v3
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}

- name: Docker meta
id: meta
uses: docker/metadata-action@v5
with:
images: ghcr.io/tgdrive/postgres
tags: |
latest
16-alpine
- name: Build Image
uses: docker/build-push-action@v6
with:
context: ./postgres
push: true
platforms: linux/amd64,linux/arm64
tags: ${{ steps.meta.outputs.tags }}
cache-from: type=gha
cache-to: type=gha,mode=max
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
# docker-images
# docker-images
This repository contains docker images needed for teldrive
45 changes: 45 additions & 0 deletions postgres/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
FROM postgres:16-alpine


ARG PGROONGA_VERSION=3.2.1
ARG GROONGA_VERSION=14.0.5

ENV PGROONGA_VERSION=${PGROONGA_VERSION} \
GROONGA_VERSION=${GROONGA_VERSION}

COPY build.sh /
RUN chmod +x /build.sh
RUN \
apk add --no-cache --virtual=.build-dependencies \
apache-arrow-dev \
build-base \
clang15-dev \
cmake \
git \
gettext-dev \
linux-headers \
llvm15 \
lz4-dev \
msgpack-c-dev \
rapidjson-dev \
ruby \
samurai \
xsimd-dev \
xxhash-dev \
zlib-dev \
zstd-dev && \
/build.sh && \
rm -f build.sh && \
apk del .build-dependencies && \
apk add --no-cache \
libarrow \
libxxhash \
msgpack-c \
zlib \
zstd

COPY start.sh /usr/local/bin/

RUN chmod +x /usr/local/bin/start.sh

ENTRYPOINT ["start.sh"]
47 changes: 47 additions & 0 deletions postgres/build.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
#!/bin/bash

set -eux

MECAB_VERSION=0.996

mkdir build
pushd build

wget https://packages.groonga.org/source/groonga/groonga-${GROONGA_VERSION}.tar.gz
tar xf groonga-${GROONGA_VERSION}.tar.gz
pushd groonga-${GROONGA_VERSION}

pushd vendor
ruby download_mecab.rb
popd

cmake \
-S . \
-B ../groonga.build \
--preset=release-maximum \
-DCMAKE_INSTALL_PREFIX=/usr/local
cmake --build ../groonga.build
cmake --install ../groonga.build
popd

wget https://packages.groonga.org/source/pgroonga/pgroonga-${PGROONGA_VERSION}.tar.gz
tar xf pgroonga-${PGROONGA_VERSION}.tar.gz
pushd pgroonga-${PGROONGA_VERSION}
make PGRN_DEBUG=yes HAVE_MSGPACK=1 MSGPACK_PACKAGE_NAME=msgpack-c -j$(nproc)
make install
popd

git clone https://github.com/pgvector/pgvector.git
pushd pgvector
make -j$(nproc)
make install
popd

git clone https://github.com/citusdata/pg_cron.git
pushd pg_cron
make -j$(nproc)
make install
popd

popd
rm -rf build
29 changes: 29 additions & 0 deletions postgres/start.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
#!/bin/sh

set -e

echo "Starting custom entrypoint..."

# Initialize the database but don't start postgres
docker-entrypoint.sh postgres -h '' &
PID=$!

# Wait for the initialization to complete
echo "Waiting for PostgreSQL to initialize..."
until pg_isready; do
sleep 1
done

# Stop the temporary PostgreSQL process
echo "Stopping temporary PostgreSQL process..."
kill -s TERM $PID
wait $PID

# Modify the PostgreSQL configuration
echo "Modifying PostgreSQL configuration..."
echo "shared_preload_libraries = 'pg_cron'" >> /var/lib/postgresql/data/postgresql.conf
echo "cron.database_name = '${POSTGRES_DB:-postgres}'" >> /var/lib/postgresql/data/postgresql.conf

echo "Starting PostgreSQL..."
# Has to run as the postgres user
exec su - postgres -c "postgres -D /var/lib/postgresql/data"

0 comments on commit 48cc174

Please sign in to comment.