From 756708b37b4eb3e78d98988eb28a5859835ced84 Mon Sep 17 00:00:00 2001 From: Alek Ratzloff Date: Thu, 8 Feb 2024 21:29:15 -0800 Subject: [PATCH 01/21] Remove -x settings from siikr.conf siikr.conf should probably be treated as a configuration or env file, so it should not have execute permissions. It should only be invoked by using `source` in your shell. --- siikr.conf | 0 1 file changed, 0 insertions(+), 0 deletions(-) mode change 100755 => 100644 siikr.conf diff --git a/siikr.conf b/siikr.conf old mode 100755 new mode 100644 From 2ef6883413dfc65bf7378fe015a12f82b4a2c8b0 Mon Sep 17 00:00:00 2001 From: Alek Ratzloff Date: Fri, 23 Feb 2024 10:43:24 -0800 Subject: [PATCH 02/21] docker: add Dockerfile and supervisord.conf The Dockerfile tries to emulate the simple_setup.sh script as closely as possible. A couple of quirks: * php-zmq does not appear to have a Debian package, and the package on PECL is from 2016 and the repo has been abandoned. Instead, we need to compile it from source. Not a huge deal, but still annoying. * Since the msgrouter service can't really run in Docker (since it uses systemd services) I have opted to use supervisord. See here: https://docs.docker.com/config/containers/multi-service_container/ Signed-off-by: Alek Ratzloff --- Dockerfile | 45 +++++++++++++++++++++++++++++++++++++++++ docker/supervisord.conf | 22 ++++++++++++++++++++ 2 files changed, 67 insertions(+) create mode 100644 Dockerfile create mode 100644 docker/supervisord.conf diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..a4e30c5 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,45 @@ +FROM php:8.2-fpm + +# Install dependencies +RUN apt-get update && \ + apt-get install -y libpq-dev hunspell hunspell-en-us libzmq5-dev supervisor gcc git + +# Compile and install php-zmq +# +# PHP-ZMQ has some ... interesting issues with the Docker container. +# * There does not appear to be a package for it(?) and it doesn't come installed +# with PHP. +# * The package available on PECL is about 8 years old and the repo is abandoned. +# So we have to compile it from source. However, this is not that painful. Just +# annoying that we have to do it ourselves. + +# TODO: make this into a script and just copy it over rather than having this +# all embedded in the Dockerfile +# TODO: choose a specific tag or commit to clone from rather than using master, +# for reproducible builds + +RUN cd /tmp && \ + git clone "https://github.com/zeromq/php-zmq" && \ + cd php-zmq && \ + phpize && \ + ./configure && \ + make && make install && \ + cd .. && rm -rf php-zmq + +# Enable PHP extensions +RUN docker-php-ext-configure pgsql && \ + docker-php-ext-install pgsql && \ + docker-php-ext-enable zmq + +# Initialize supervisord +RUN mkdir -p /var/log/supervisor +COPY docker/supervisord.conf /etc/supervisor/conf.d/supervisord.conf + +WORKDIR /var/www/html + +# TODO: set up php-fpm config like the setup_simple.sh script does + +# Copy siikr +COPY siikr/. /var/www/html + +CMD ["/usr/bin/supervisord"] diff --git a/docker/supervisord.conf b/docker/supervisord.conf new file mode 100644 index 0000000..9215a35 --- /dev/null +++ b/docker/supervisord.conf @@ -0,0 +1,22 @@ +[supervisord] +nodaemon=true +logfile=/dev/null +logfile_maxbytes=0 + +[program:php-fpm] +command=php-fpm +autostart=true +autorestart=true +# Redirect stderr to stdout, and log to stdout +stdout_logfile=/dev/fd/1 +stdout_logfile_maxbytes=0 +redirect_stderr=true + +[program:msgrouter] +command=php /var/www/html/routing/msgRouter.php +autostart=true +autorestart=true +# Redirect stderr to stdout, and log to stdout +stdout_logfile=/dev/fd/1 +stdout_logfile_maxbytes=0 +redirect_stderr=true From 0065b7d3b6c5243685b935c3c39ca56d59dbcb2d Mon Sep 17 00:00:00 2001 From: Alek Ratzloff Date: Fri, 23 Feb 2024 10:51:06 -0800 Subject: [PATCH 03/21] docker: Rename siikr.conf -> siikr.example.env Since siikr.conf is more of an environment file, the extension should reflect that. I have also renamed it to siikr.example.env - this is so that if the configuation is changed, it will only go into the example env file, and not cause issues with pulling down into a modified siikr.env file. Additionally, it helps prevent in-dev configuration from accidentally getting committed in the case that someone uses `git commit -a` a bit carelessly. Signed-off-by: Alek Ratzloff --- README.md | 2 +- setup_simple.sh | 6 +++++- siikr.conf => siikr.example.env | 0 3 files changed, 6 insertions(+), 2 deletions(-) rename siikr.conf => siikr.example.env (100%) diff --git a/README.md b/README.md index f4b1879..4c22700 100644 --- a/README.md +++ b/README.md @@ -7,7 +7,7 @@ IYKYK. Best done on a clean Ubuntu or debian server. 0. clone this repo. -1. Fill out (at a minimum) the first three lines in `siikr.conf` +1. Copy `siikr.example.env` to `siikr.env` and fill out (at a minimum) the first three lines. 2. If not already in a terminal, switch to one and run `chmod +x setup_simple.sh` 3. Then run `sudo ./setup_simple.sh` and follow the prompts. 4. Pray. diff --git a/setup_simple.sh b/setup_simple.sh index 5743ab3..bd04a14 100755 --- a/setup_simple.sh +++ b/setup_simple.sh @@ -4,8 +4,12 @@ set -eo pipefail script_path="$(realpath "$0")" script_dir="$(dirname "$script_path")" -source "$script_dir/siikr.conf" +if [[ ! -f "$script_dir/siikr.env" ]]; then + echo "Could not find $script_dir/siikr.env. Make sure to copy siikr.example.env and fill it out with your deploy information." + exit 1 +fi +source "$script_dir/siikr.env" update_install_packages() { local confirm diff --git a/siikr.conf b/siikr.example.env similarity index 100% rename from siikr.conf rename to siikr.example.env From 8b955070557c493b9a47fa84c8580573b06e7bab Mon Sep 17 00:00:00 2001 From: Alek Ratzloff Date: Fri, 23 Feb 2024 14:53:55 -0800 Subject: [PATCH 04/21] Move Dockerfile -> docker/php-fpm.Dockerfile, and add DB configuration step to php-fpm.Dockerfile Signed-off-by: Alek Ratzloff --- Dockerfile => docker/php-fpm.Dockerfile | 10 ++++++++++ 1 file changed, 10 insertions(+) rename Dockerfile => docker/php-fpm.Dockerfile (84%) diff --git a/Dockerfile b/docker/php-fpm.Dockerfile similarity index 84% rename from Dockerfile rename to docker/php-fpm.Dockerfile index a4e30c5..75e660b 100644 --- a/Dockerfile +++ b/docker/php-fpm.Dockerfile @@ -42,4 +42,14 @@ WORKDIR /var/www/html # Copy siikr COPY siikr/. /var/www/html +# Create database configuration +RUN mkdir -p /var/www/html/auth +RUN cat > /var/www/html/auth/credentials.php < Date: Fri, 23 Feb 2024 14:55:37 -0800 Subject: [PATCH 05/21] Add docker-compose, postgres.Dockerfile, create_database.sh script, and update README + env example * docker-compose.yaml for docker-compose command * postgres.Dockerfile sets up Postgres appropriately * create_database.sh script will create the Postgres database from the SQL in the siikr directory in the Docker container * README includes base instructions for using docker-compose * Update siikr.example.env to include the POSTGRES_* environment variables necessary for Docker deployment Signed-off-by: Alek Ratzloff --- README.md | 12 ++++++++++++ docker-compose.yaml | 31 +++++++++++++++++++++++++++++++ docker/create_database.sh | 18 ++++++++++++++++++ docker/postgres.Dockerfile | 6 ++++++ siikr.example.env | 5 +++++ 5 files changed, 72 insertions(+) create mode 100644 docker-compose.yaml create mode 100755 docker/create_database.sh create mode 100644 docker/postgres.Dockerfile diff --git a/README.md b/README.md index 4c22700..cab98b5 100644 --- a/README.md +++ b/README.md @@ -13,3 +13,15 @@ Best done on a clean Ubuntu or debian server. 4. Pray. 5. Submit an issue if it fails. +# Docker installation + +Docker gives you a clean server, but the install may be a little more involved. + +0. clone this repo. +1. Make sure you have both Docker and `docker-compose` installed. +2. Copy `siikr.example.env` to `siikr.env` and fill out (at a minimum) the first three lines. +3. Run `docker-compose build` +4. Create the database using `docker/create_database.sh` +5. Bring the service up using `docker-compose up -d` +6. Optionally, check logs using `docker-compose logs -f` + diff --git a/docker-compose.yaml b/docker-compose.yaml new file mode 100644 index 0000000..c42d03d --- /dev/null +++ b/docker-compose.yaml @@ -0,0 +1,31 @@ +version: '3' + +services: + postgres: + build: + context: . + dockerfile: docker/postgres.Dockerfile + env_file: + - siikr.env + volumes: + - "./postgres_data:/var/lib/postgresql/data" + + #nginx: + # build: . + # ports: + # - "80:80" + # volumes: + # - "./nginx.conf:/etc/nginx/nginx.conf" + # depends_on: + # - php + + php: + build: + context: . + dockerfile: docker/php-fpm.Dockerfile + env_file: + - siikr.env + depends_on: + - postgres + volumes: + - "./postgres_data:/var/lib/postgresql/data" diff --git a/docker/create_database.sh b/docker/create_database.sh new file mode 100755 index 0000000..916b25a --- /dev/null +++ b/docker/create_database.sh @@ -0,0 +1,18 @@ +#!/bin/bash +set -eo pipefail + +script_path="$(realpath "$0")" +script_dir="$(realpath "$(dirname "$script_path")"/..)" + +if [[ ! -f "$script_dir/siikr.env" ]]; then + echo "Could not find $script_dir/siikr.env. Make sure to copy siikr.example.env and fill it out with your deploy information." + exit 1 +fi + +source "$script_dir/siikr.env" + +docker-compose up -d postgres --build +echo "Waiting for the database to be created and to come online..." +sleep 3 +docker-compose exec -T -u postgres postgres psql -U "$POSTGRES_USER" -d "$POSTGRES_DB" < "$script_dir/siikr/siikr_db_setup.sql" +#docker-compose down postgres diff --git a/docker/postgres.Dockerfile b/docker/postgres.Dockerfile new file mode 100644 index 0000000..d7886a3 --- /dev/null +++ b/docker/postgres.Dockerfile @@ -0,0 +1,6 @@ +FROM postgres:16-bookworm +RUN apt-get update && \ + apt-get -y install hunspell hunspell-en-us postgresql-16-pgvector + +CMD ["postgres"] + diff --git a/siikr.example.env b/siikr.example.env index ab94b88..25bc869 100644 --- a/siikr.example.env +++ b/siikr.example.env @@ -2,6 +2,7 @@ tumblr_API_consumer_key="PUT YOUR KEY HERE" pg_pass="PUT YOUR DB PASSWORD HERE" +# If using Docker, this should be set to /var/lib/postgresql/data pg_disk="PUT THE MOUNTPOINT OF WHEREVER THE DISK DRIVE STORING THE DB DATA IS HERE" document_root="/var/www/html/" #location you want to install siikr into php_dir="/usr/bin/php" #location of your active php install @@ -9,3 +10,7 @@ php_user="www-data" #the user your php server runs as pg_user="siikrweb" #postgres username that database access will be performed as. siikr_db="siikrdb" #name of siikr database to create +# These are Docker-specific environment variables, don't touch these. +POSTGRES_USER="$pg_user" +POSTGRES_PASSWORD="$pg_pass" +POSTGRES_DB="$siikr_db" From f422ea56ea5ffdcb200aaaaf2695ef59e3fcc80b Mon Sep 17 00:00:00 2001 From: Alek Ratzloff Date: Fri, 23 Feb 2024 14:58:30 -0800 Subject: [PATCH 06/21] Add siikr.env to root .gitignore Signed-off-by: Alek Ratzloff --- .gitignore | 1 + 1 file changed, 1 insertion(+) diff --git a/.gitignore b/.gitignore index 7a7fe6d..14cc6cb 100644 --- a/.gitignore +++ b/.gitignore @@ -3,3 +3,4 @@ siikr/dev/** siikr/auth/** siikr/internal/disks.php siikr/management/archive_blogs.php +siikr.env From 4c666e08f53ce0b12c71439ac7765b43bd9c1123 Mon Sep 17 00:00:00 2001 From: Alek Ratzloff Date: Fri, 23 Feb 2024 15:16:06 -0800 Subject: [PATCH 07/21] docker: Add DB host configuration and get_db() function * DB host was not previously available in the user configuration, this is now added in case your DB is hosted anywhere besides localhost (as is the case with Docker) * All of the `new PDO` calls were either using a hard-coded database user or getting the currently logged in UNIX user, rather than the configured user. The password was also being set to null. This is resolved with the `get_db()` function in the internal/globals.php file. All calls to `new PDO` are also updated so we don't have to update it in 6 different places, either. Signed-off-by: Alek Ratzloff --- docker/php-fpm.Dockerfile | 1 + setup_simple.sh | 1 + siikr/get_tags.php | 2 +- siikr/internal/archive.php | 3 +-- siikr/internal/embeddings.php | 5 ++--- siikr/internal/globals.php | 7 +++++++ siikr/management/dumpzip_blogs.php | 3 +-- siikr/resolve_image_url.php | 4 ++-- siikr/search.php | 2 +- 9 files changed, 17 insertions(+), 11 deletions(-) diff --git a/docker/php-fpm.Dockerfile b/docker/php-fpm.Dockerfile index 75e660b..63c5e29 100644 --- a/docker/php-fpm.Dockerfile +++ b/docker/php-fpm.Dockerfile @@ -50,6 +50,7 @@ RUN cat > /var/www/html/auth/credentials.php < "$script_dir/siikr/internal/disks.php" << EOF diff --git a/siikr/get_tags.php b/siikr/get_tags.php index 4464bb2..a8a2330 100644 --- a/siikr/get_tags.php +++ b/siikr/get_tags.php @@ -2,7 +2,7 @@ require_once 'internal/globals.php'; $blog_uuid = $_GET["blog_uuid"]; try { - $db = new PDO("pgsql:dbname=$db_name", "www-data", null); + $db = get_db(); $blog_info = (object)[ "valid" => false, "blog_uuid" => $blog_uuid, diff --git a/siikr/internal/archive.php b/siikr/internal/archive.php index a1455cf..ea1f940 100644 --- a/siikr/internal/archive.php +++ b/siikr/internal/archive.php @@ -2,8 +2,7 @@ require_once 'globals.php'; $archiver_uuid = uuid_create(UUID_TYPE_RANDOM); -$userInfo = posix_getpwuid(posix_geteuid()); -$db = new PDO("pgsql:dbname=$db_name", $userInfo["name"], null); +$db = get_db(); require_once 'lease.php'; diff --git a/siikr/internal/embeddings.php b/siikr/internal/embeddings.php index 781e04e..69cb16b 100644 --- a/siikr/internal/embeddings.php +++ b/siikr/internal/embeddings.php @@ -2,7 +2,6 @@ #Experimental, don't worry about it. require_once 'globals.php'; $batch_size = 10; -$userInfo = posix_getpwuid(posix_geteuid()); $credentials = base64_encode("$clip_host_username:$clip_host_password"); $options = [ 'http' => [ @@ -13,7 +12,7 @@ 'ignore_errors' => true, ] ]; -$db = new PDO("pgsql:dbname=$db_name", $userInfo["name"], null); +$db = get_db(); $unembedded = $db->prepare("SELECT * FROM images WHERE clip_attempted IS NULL LIMIT 10000"); $set_clip_attempted = $db->prepare("UPDATE images SET clip_attempted = now() WHERE image_id = :image_id"); @@ -63,4 +62,4 @@ function send_batch() { $to_send = ["image_urls" => [], "embedding_uuids" => []]; $images_pending = []; -} \ No newline at end of file +} diff --git a/siikr/internal/globals.php b/siikr/internal/globals.php index 429e00d..542da2e 100644 --- a/siikr/internal/globals.php +++ b/siikr/internal/globals.php @@ -368,3 +368,10 @@ function check_delete($tag_text, $prior_count, $blog_uuid, $db) { } return false; } + +/** + * Get a handle to the database. + */ +function get_db() { + return new PDO("pgsql:host=$db_host;dbname=$db_name", $db_user, $db_pass); +} diff --git a/siikr/management/dumpzip_blogs.php b/siikr/management/dumpzip_blogs.php index 51313ea..be7c647 100644 --- a/siikr/management/dumpzip_blogs.php +++ b/siikr/management/dumpzip_blogs.php @@ -1,8 +1,7 @@ prepare("SELECT img_url FROM images where image_id = :image_id"); $get_image_stmt->execute(["image_id" => $image_id]); @@ -12,4 +12,4 @@ $blog_info->display_error = $e->getMessage(); } $db = null; -echo $url; \ No newline at end of file +echo $url; diff --git a/siikr/search.php b/siikr/search.php index 15719f3..36318ca 100644 --- a/siikr/search.php +++ b/siikr/search.php @@ -15,7 +15,7 @@ $query = "websearch_to_tsquery('simple', '$raw_query')";//$parser->parse($raw_query); $blog_info = (object)[]; try { - $db = new PDO("pgsql:dbname=$db_name", "www-data", null); + $db = get_db(); $response = call_tumblr($username, "info", [], true); if($response->meta->status != 200) { $error_string = ""; From b5a830971481f13c5e91cc24103b0ee1a1822780 Mon Sep 17 00:00:00 2001 From: Alek Ratzloff Date: Fri, 23 Feb 2024 16:52:32 -0800 Subject: [PATCH 08/21] Add postgres_data/ directory to .gitignore Signed-off-by: Alek Ratzloff --- .gitignore | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.gitignore b/.gitignore index 14cc6cb..b4342bf 100644 --- a/.gitignore +++ b/.gitignore @@ -4,3 +4,5 @@ siikr/auth/** siikr/internal/disks.php siikr/management/archive_blogs.php siikr.env + +postgres_data/ From 0e2d88e8d4b4c21747c5427d0ed43003c19c6950 Mon Sep 17 00:00:00 2001 From: Alek Ratzloff Date: Fri, 23 Feb 2024 16:53:16 -0800 Subject: [PATCH 09/21] docker: Add nginx to the PHP FPM container * Forward port 80 -> 8080 * Install nginx in php container * Add a php-fpm-siikr.conf file for Docker * Add an nginx-siikr.conf file Docker Signed-off-by: Alek Ratzloff --- docker-compose.yaml | 11 ++--------- docker/nginx-siikr.conf | 23 +++++++++++++++++++++++ docker/php-fpm-siikr.conf | 1 + docker/php-fpm.Dockerfile | 11 +++++++++-- docker/postgres.Dockerfile | 3 --- docker/supervisord.conf | 13 +++++++++++++ 6 files changed, 48 insertions(+), 14 deletions(-) create mode 100644 docker/nginx-siikr.conf create mode 100644 docker/php-fpm-siikr.conf diff --git a/docker-compose.yaml b/docker-compose.yaml index c42d03d..93847e7 100644 --- a/docker-compose.yaml +++ b/docker-compose.yaml @@ -10,19 +10,12 @@ services: volumes: - "./postgres_data:/var/lib/postgresql/data" - #nginx: - # build: . - # ports: - # - "80:80" - # volumes: - # - "./nginx.conf:/etc/nginx/nginx.conf" - # depends_on: - # - php - php: build: context: . dockerfile: docker/php-fpm.Dockerfile + ports: + - "8080:80" env_file: - siikr.env depends_on: diff --git a/docker/nginx-siikr.conf b/docker/nginx-siikr.conf new file mode 100644 index 0000000..be6b08a --- /dev/null +++ b/docker/nginx-siikr.conf @@ -0,0 +1,23 @@ +server { + listen 80 default_server; + server_name _; + + root /var/www/html; + + index index.html index.php; + + + location / { + # First attempt to serve request as file, then + # as directory, then fall back to displaying a 404. + try_files $uri $uri/ =404; + } + + location ~ \.php$ { + include snippets/fastcgi-php.conf; + fastcgi_pass 127.0.0.1:9000; + } + + error_log /dev/stdout; + access_log /dev/stdout; +} diff --git a/docker/php-fpm-siikr.conf b/docker/php-fpm-siikr.conf new file mode 100644 index 0000000..b5cc7fd --- /dev/null +++ b/docker/php-fpm-siikr.conf @@ -0,0 +1 @@ +[www] diff --git a/docker/php-fpm.Dockerfile b/docker/php-fpm.Dockerfile index 63c5e29..1f431c8 100644 --- a/docker/php-fpm.Dockerfile +++ b/docker/php-fpm.Dockerfile @@ -2,7 +2,7 @@ FROM php:8.2-fpm # Install dependencies RUN apt-get update && \ - apt-get install -y libpq-dev hunspell hunspell-en-us libzmq5-dev supervisor gcc git + apt-get install -y libpq-dev hunspell hunspell-en-us libzmq5-dev supervisor nginx gcc git # Compile and install php-zmq # @@ -31,6 +31,12 @@ RUN docker-php-ext-configure pgsql && \ docker-php-ext-install pgsql && \ docker-php-ext-enable zmq +# Add php-fpm config +COPY docker/php-fpm-siikr.conf /usr/local/etc/php-fpm.d + +# Add nginx config +COPY docker/nginx-siikr.conf /etc/nginx/sites-available/default + # Initialize supervisord RUN mkdir -p /var/log/supervisor COPY docker/supervisord.conf /etc/supervisor/conf.d/supervisord.conf @@ -39,7 +45,8 @@ WORKDIR /var/www/html # TODO: set up php-fpm config like the setup_simple.sh script does -# Copy siikr +# Clean out /var/www/html and then copy siikr +RUN rm /var/www/html/* -rf COPY siikr/. /var/www/html # Create database configuration diff --git a/docker/postgres.Dockerfile b/docker/postgres.Dockerfile index d7886a3..41a5fe2 100644 --- a/docker/postgres.Dockerfile +++ b/docker/postgres.Dockerfile @@ -1,6 +1,3 @@ FROM postgres:16-bookworm RUN apt-get update && \ apt-get -y install hunspell hunspell-en-us postgresql-16-pgvector - -CMD ["postgres"] - diff --git a/docker/supervisord.conf b/docker/supervisord.conf index 9215a35..5ddda33 100644 --- a/docker/supervisord.conf +++ b/docker/supervisord.conf @@ -1,10 +1,12 @@ [supervisord] +user=root nodaemon=true logfile=/dev/null logfile_maxbytes=0 [program:php-fpm] command=php-fpm +user=root autostart=true autorestart=true # Redirect stderr to stdout, and log to stdout @@ -14,6 +16,17 @@ redirect_stderr=true [program:msgrouter] command=php /var/www/html/routing/msgRouter.php +user=root +autostart=true +autorestart=true +# Redirect stderr to stdout, and log to stdout +stdout_logfile=/dev/fd/1 +stdout_logfile_maxbytes=0 +redirect_stderr=true + +[program:nginx] +command=nginx -g 'daemon off;' +user=root autostart=true autorestart=true # Redirect stderr to stdout, and log to stdout From 3636659220f5fef132310a7ddf28c8a7b1655bb9 Mon Sep 17 00:00:00 2001 From: Alek Ratzloff Date: Fri, 23 Feb 2024 16:57:32 -0800 Subject: [PATCH 10/21] Add siikr/internal/disks.php file creation to php-fpm.Dockerfile Signed-off-by: Alek Ratzloff --- docker/php-fpm.Dockerfile | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/docker/php-fpm.Dockerfile b/docker/php-fpm.Dockerfile index 1f431c8..f4a575b 100644 --- a/docker/php-fpm.Dockerfile +++ b/docker/php-fpm.Dockerfile @@ -60,4 +60,9 @@ RUN cat > /var/www/html/auth/credentials.php < /var/www/html/internal/disks.php < Date: Fri, 23 Feb 2024 17:10:22 -0800 Subject: [PATCH 11/21] Fix a couple of small bugs in index.php and show_page.php * Use `isset` on the $_GET key, instead of checking for implicit membership * Add a catch for `DivisionByZeroError` in the show_page.php - not sure why the `catch (Exception $e)` wasn't catching it. (We can fix it later) Signed-off-by: Alek Ratzloff --- siikr/index.php | 2 +- siikr/show_page.php | 2 ++ 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/siikr/index.php b/siikr/index.php index 51be769..a3684fa 100644 --- a/siikr/index.php +++ b/siikr/index.php @@ -1,6 +1,6 @@ From c0d575bc18cba20208c6687887e0a083f3ec62f4 Mon Sep 17 00:00:00 2001 From: Kevin Meyer Date: Mon, 19 Aug 2024 23:39:17 -0400 Subject: [PATCH 12/21] fix(docker): Docker works now --- Makefile | 46 +++++++++++++++++++++++++++++++++++++++ README.md | 1 + docker-compose.yaml | 21 ++++++++++++++---- docker/create_database.sh | 2 +- siikr.example.env | 11 ++++++++++ siikr/siikr_db_setup.sql | 4 ++++ 6 files changed, 80 insertions(+), 5 deletions(-) create mode 100644 Makefile diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..78c6a26 --- /dev/null +++ b/Makefile @@ -0,0 +1,46 @@ +DOCKER_REPO?=meyerkev248/siikr + +reset: + $(MAKE) build + $(MAKE) down + $(MAKE) up + +reset-clean: + $(MAKE) build + $(MAKE) clean + $(MAKE) up + +.PHONY: build +build: + docker-compose build + +.PHONY: up +up: + + docker-compose up -d + +.PHONY: down +down: + docker-compose down + +.PHONY: clean +clean: + docker-compose down -v + +.PHONY: logs +logs: + docker-compose logs -f + +.PHONY: docker-push +docker-push: + @IMAGES="my-postgres:latest my-php-fpm:latest"; \ + TAG=$$(git rev-parse --short HEAD); \ + if [ -n "$$(git status --porcelain)" ]; then \ + TAG="$$TAG-dirty"; \ + fi; \ + for IMAGE in $$IMAGES; do \ + docker tag $$IMAGE ${DOCKER_REPO}:$$TAG; \ + docker push ${DOCKER_REPO}:$$TAG; \ + done + + diff --git a/README.md b/README.md index cab98b5..2754b10 100644 --- a/README.md +++ b/README.md @@ -22,6 +22,7 @@ Docker gives you a clean server, but the install may be a little more involved. 2. Copy `siikr.example.env` to `siikr.env` and fill out (at a minimum) the first three lines. 3. Run `docker-compose build` 4. Create the database using `docker/create_database.sh` + 1. TODO: Make this an entrypoint script or cron job in the helm chart 5. Bring the service up using `docker-compose up -d` 6. Optionally, check logs using `docker-compose logs -f` diff --git a/docker-compose.yaml b/docker-compose.yaml index 93847e7..00776d7 100644 --- a/docker-compose.yaml +++ b/docker-compose.yaml @@ -1,3 +1,4 @@ + version: '3' services: @@ -5,20 +6,32 @@ services: build: context: . dockerfile: docker/postgres.Dockerfile + image: my-postgres:latest env_file: - siikr.env volumes: - - "./postgres_data:/var/lib/postgresql/data" + - postgres_data:/var/lib/postgresql/data + - ./siikr/siikr_db_setup.sql:/docker-entrypoint-initdb.d/01_siikr_db_setup.sql + healthcheck: + test: ["CMD", "pg_isready", "-U", "postgres"] + interval: 10s + retries: 5 + start_period: 30s + timeout: 5s php: build: context: . dockerfile: docker/php-fpm.Dockerfile + image: my-php-fpm:latest ports: - "8080:80" env_file: - siikr.env depends_on: - - postgres - volumes: - - "./postgres_data:/var/lib/postgresql/data" + postgres: + condition: service_healthy + +volumes: + postgres_data: + diff --git a/docker/create_database.sh b/docker/create_database.sh index 916b25a..56e912a 100755 --- a/docker/create_database.sh +++ b/docker/create_database.sh @@ -11,7 +11,7 @@ fi source "$script_dir/siikr.env" -docker-compose up -d postgres --build +docker-compose up -d postgres echo "Waiting for the database to be created and to come online..." sleep 3 docker-compose exec -T -u postgres postgres psql -U "$POSTGRES_USER" -d "$POSTGRES_DB" < "$script_dir/siikr/siikr_db_setup.sql" diff --git a/siikr.example.env b/siikr.example.env index 25bc869..a397e1c 100644 --- a/siikr.example.env +++ b/siikr.example.env @@ -14,3 +14,14 @@ siikr_db="siikrdb" #name of siikr database to create POSTGRES_USER="$pg_user" POSTGRES_PASSWORD="$pg_pass" POSTGRES_DB="$siikr_db" + +# If you're using Docker, follow these +# These are Docker-specific environment variables, don't touch these. +# https://github.com/containers/podman-compose/issues/718 +# POSTGRES_USER="$pg_user" +# POSTGRES_PASSWORD="$pg_pass" +# POSTGRES_DB="$siikr_db" + +POSTGRES_USER=postgres +POSTGRES_PASSWORD="testtesttest" +POSTGRES_DB=siikrdb diff --git a/siikr/siikr_db_setup.sql b/siikr/siikr_db_setup.sql index 2a0bfcf..d314442 100644 --- a/siikr/siikr_db_setup.sql +++ b/siikr/siikr_db_setup.sql @@ -5,6 +5,10 @@ -- Dumped from database version 14.10 (Ubuntu 14.10-0ubuntu0.22.04.1) -- Dumped by pg_dump version 14.10 (Ubuntu 14.10-0ubuntu0.22.04.1) + +-- TODO: BURN ME +CREATE ROLE postgres WITH LOGIN SUPERUSER password 'postgres'; + SET statement_timeout = 0; SET lock_timeout = 0; SET idle_in_transaction_session_timeout = 0; From 734c0edc63c9455b1a1887f9bfc505584b992db4 Mon Sep 17 00:00:00 2001 From: Kevin Meyer Date: Mon, 19 Aug 2024 23:52:34 -0400 Subject: [PATCH 13/21] siikrweb must exist as a functional entity --- siikr.example.env | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/siikr.example.env b/siikr.example.env index a397e1c..39d41d7 100644 --- a/siikr.example.env +++ b/siikr.example.env @@ -22,6 +22,6 @@ POSTGRES_DB="$siikr_db" # POSTGRES_PASSWORD="$pg_pass" # POSTGRES_DB="$siikr_db" -POSTGRES_USER=postgres +POSTGRES_USER=siikrweb POSTGRES_PASSWORD="testtesttest" POSTGRES_DB=siikrdb From 548cab51beddf6861b84c5fafdc2d2949d930dc8 Mon Sep 17 00:00:00 2001 From: Kevin Meyer Date: Mon, 19 Aug 2024 23:54:15 -0400 Subject: [PATCH 14/21] One quick doc line --- Makefile | 1 + 1 file changed, 1 insertion(+) diff --git a/Makefile b/Makefile index 78c6a26..fe132ab 100644 --- a/Makefile +++ b/Makefile @@ -40,6 +40,7 @@ docker-push: fi; \ for IMAGE in $$IMAGES; do \ docker tag $$IMAGE ${DOCKER_REPO}:$$TAG; \ + echo "Pushing $$IMAGE to ${DOCKER_REPO}:$$TAG"; \ docker push ${DOCKER_REPO}:$$TAG; \ done From 79506083341be5eaa386c12f8dc64049dd2422ec Mon Sep 17 00:00:00 2001 From: Kevin Meyer Date: Mon, 19 Aug 2024 23:59:57 -0400 Subject: [PATCH 15/21] fix(postgres): Removing the postgres superuser password --- siikr/siikr_db_setup.sql | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/siikr/siikr_db_setup.sql b/siikr/siikr_db_setup.sql index d314442..5866181 100644 --- a/siikr/siikr_db_setup.sql +++ b/siikr/siikr_db_setup.sql @@ -5,9 +5,9 @@ -- Dumped from database version 14.10 (Ubuntu 14.10-0ubuntu0.22.04.1) -- Dumped by pg_dump version 14.10 (Ubuntu 14.10-0ubuntu0.22.04.1) - --- TODO: BURN ME -CREATE ROLE postgres WITH LOGIN SUPERUSER password 'postgres'; +-- Manually added, needed for healthchecks +-- Should never ever have a password +CREATE ROLE postgres WITH LOGIN SUPERUSER; SET statement_timeout = 0; SET lock_timeout = 0; From 0ecd316a9fdbaeafa07fd6437a97339efd2ac0a5 Mon Sep 17 00:00:00 2001 From: Kevin Meyer Date: Tue, 20 Aug 2024 01:00:51 -0400 Subject: [PATCH 16/21] Made auth an entrypoint script --- Makefile | 4 +++- README.md | 10 ++++------ docker-compose.yaml | 6 ++++++ docker/entrypoint.sh | 16 ++++++++++++++++ docker/php-fpm.Dockerfile | 13 +++++-------- 5 files changed, 34 insertions(+), 15 deletions(-) create mode 100755 docker/entrypoint.sh diff --git a/Makefile b/Makefile index fe132ab..d8120fd 100644 --- a/Makefile +++ b/Makefile @@ -44,4 +44,6 @@ docker-push: docker push ${DOCKER_REPO}:$$TAG; \ done - +.PHONY: debug +debug: + docker-compose exec php bash \ No newline at end of file diff --git a/README.md b/README.md index 2754b10..36f05af 100644 --- a/README.md +++ b/README.md @@ -19,10 +19,8 @@ Docker gives you a clean server, but the install may be a little more involved. 0. clone this repo. 1. Make sure you have both Docker and `docker-compose` installed. -2. Copy `siikr.example.env` to `siikr.env` and fill out (at a minimum) the first three lines. -3. Run `docker-compose build` -4. Create the database using `docker/create_database.sh` - 1. TODO: Make this an entrypoint script or cron job in the helm chart -5. Bring the service up using `docker-compose up -d` -6. Optionally, check logs using `docker-compose logs -f` + 1. TODO: Document how to setup the API key sanely +2. Copy `siikr.example.env` to `siikr.env` and fill out (at a minimum) the first three lines while noticing the hardcoded postgres user siikrweb. +3. `make build up && open localhost:8080 && make logs` - This will follow logs in the terminal and open the browser window +4. You'll need to do some magic with DDNS for callback reasons in your router or via some other mechanism. This is _not_ documented. diff --git a/docker-compose.yaml b/docker-compose.yaml index 00776d7..466b98b 100644 --- a/docker-compose.yaml +++ b/docker-compose.yaml @@ -31,6 +31,12 @@ services: depends_on: postgres: condition: service_healthy + healthcheck: + test: ["CMD", "curl", "-f", "http://localhost:80"] + interval: 1m30s + timeout: 30s + retries: 5 + start_period: 30s volumes: postgres_data: diff --git a/docker/entrypoint.sh b/docker/entrypoint.sh new file mode 100755 index 0000000..b3991d8 --- /dev/null +++ b/docker/entrypoint.sh @@ -0,0 +1,16 @@ +#!/bin/bash + +if [ -f siikr.env ]; then + export $(cat siikr.env | xargs) +fi + +cat > /var/www/html/auth/credentials.php < /var/www/html/auth/credentials.php < /var/www/html/internal/disks.php < Date: Tue, 20 Aug 2024 01:10:35 -0400 Subject: [PATCH 17/21] fixes: Using postgres 14 and proper db connections --- docker/postgres.Dockerfile | 5 +++-- siikr/internal/globals.php | 1 + 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/docker/postgres.Dockerfile b/docker/postgres.Dockerfile index 41a5fe2..b8a48cd 100644 --- a/docker/postgres.Dockerfile +++ b/docker/postgres.Dockerfile @@ -1,3 +1,4 @@ -FROM postgres:16-bookworm +ARG POSTGRES_VERSION=14 +FROM postgres:$(POSTGRES_VERSION)-bookworm RUN apt-get update && \ - apt-get -y install hunspell hunspell-en-us postgresql-16-pgvector + apt-get -y install hunspell hunspell-en-us postgresql-$(POSTGRES_VERSION)-pgvector diff --git a/siikr/internal/globals.php b/siikr/internal/globals.php index 542da2e..440c71c 100644 --- a/siikr/internal/globals.php +++ b/siikr/internal/globals.php @@ -373,5 +373,6 @@ function check_delete($tag_text, $prior_count, $blog_uuid, $db) { * Get a handle to the database. */ function get_db() { + global $db_host, $db_name, $db_user, $db_pass; return new PDO("pgsql:host=$db_host;dbname=$db_name", $db_user, $db_pass); } From bb1281237acdc3ee9244c8442e40cf5f017c39e3 Mon Sep 17 00:00:00 2001 From: Kevin Meyer Date: Tue, 20 Aug 2024 01:43:27 -0400 Subject: [PATCH 18/21] fix(php): Database connections now work --- docker-compose.yaml | 2 ++ docker/php-fpm.Dockerfile | 3 ++- docker/postgres.Dockerfile | 5 +++-- 3 files changed, 7 insertions(+), 3 deletions(-) diff --git a/docker-compose.yaml b/docker-compose.yaml index 466b98b..1232410 100644 --- a/docker-compose.yaml +++ b/docker-compose.yaml @@ -6,6 +6,8 @@ services: build: context: . dockerfile: docker/postgres.Dockerfile + args: + POSTGRES_VERSION: 14 image: my-postgres:latest env_file: - siikr.env diff --git a/docker/php-fpm.Dockerfile b/docker/php-fpm.Dockerfile index 447cc88..54bfe6b 100644 --- a/docker/php-fpm.Dockerfile +++ b/docker/php-fpm.Dockerfile @@ -28,7 +28,8 @@ RUN cd /tmp && \ # Enable PHP extensions RUN docker-php-ext-configure pgsql && \ - docker-php-ext-install pgsql && \ + docker-php-ext-install pdo_pgsql pgsql && \ + docker-php-ext-enable pdo_pgsql pgsql && \ docker-php-ext-enable zmq # Add php-fpm config diff --git a/docker/postgres.Dockerfile b/docker/postgres.Dockerfile index b8a48cd..f4b25ba 100644 --- a/docker/postgres.Dockerfile +++ b/docker/postgres.Dockerfile @@ -1,4 +1,5 @@ ARG POSTGRES_VERSION=14 -FROM postgres:$(POSTGRES_VERSION)-bookworm +FROM postgres:${POSTGRES_VERSION}-bookworm +ARG POSTGRES_VERSION=14 RUN apt-get update && \ - apt-get -y install hunspell hunspell-en-us postgresql-$(POSTGRES_VERSION)-pgvector + apt-get -y install hunspell hunspell-en-us postgresql-${POSTGRES_VERSION}-pgvector From 4919abfc3310027935d2381140e3326afc61d46a Mon Sep 17 00:00:00 2001 From: Kevin Meyer Date: Tue, 20 Aug 2024 02:17:39 -0400 Subject: [PATCH 19/21] Fixed extension installs --- docker/php-fpm.Dockerfile | 10 ++-------- siikr/internal/globals.php | 4 ++-- siikr/search.php | 4 ++-- 3 files changed, 6 insertions(+), 12 deletions(-) diff --git a/docker/php-fpm.Dockerfile b/docker/php-fpm.Dockerfile index 54bfe6b..9dd013e 100644 --- a/docker/php-fpm.Dockerfile +++ b/docker/php-fpm.Dockerfile @@ -1,4 +1,5 @@ FROM php:8.2-fpm +ADD --chmod=0755 https://github.com/mlocati/docker-php-extension-installer/releases/latest/download/install-php-extensions /usr/local/bin/ # Install dependencies RUN apt-get update && \ @@ -18,18 +19,11 @@ RUN apt-get update && \ # TODO: choose a specific tag or commit to clone from rather than using master, # for reproducible builds -RUN cd /tmp && \ - git clone "https://github.com/zeromq/php-zmq" && \ - cd php-zmq && \ - phpize && \ - ./configure && \ - make && make install && \ - cd .. && rm -rf php-zmq - # Enable PHP extensions RUN docker-php-ext-configure pgsql && \ docker-php-ext-install pdo_pgsql pgsql && \ docker-php-ext-enable pdo_pgsql pgsql && \ + install-php-extensions zmq && \ docker-php-ext-enable zmq # Add php-fpm config diff --git a/siikr/internal/globals.php b/siikr/internal/globals.php index 440c71c..0806f78 100644 --- a/siikr/internal/globals.php +++ b/siikr/internal/globals.php @@ -74,7 +74,7 @@ function getTextSearchString($query, $search_params, $match_condition="p.blog_uu $query_english = str_replace("_tsquery('simple',", "_tsquery('en_us_hunspell',", $query); list($weight_string, $filter_string, $image_only) = parseParams($search_params); if(!$image_only) - return getPostSearchString($query_simple, $query_english, $match_condition, $weight_string, $filter_string); + return getPostSearchString($query_simple, $query_english, $weight_string, $filter_string, $match_condition); else return getImageSearchString($query, $match_condition); } @@ -101,7 +101,7 @@ function getImageSearchString($query_simple, $query_english, $post_match_conditi )"; } -function getPostSearchString($query_simple, $query_english, $match_condition="p.blog_uuid = :q_uuid ", $weight_string, $filter_string) { +function getPostSearchString($query_simple, $query_english, $weight_string, $filter_string, $match_condition="p.blog_uuid = :q_uuid ") { return "SELECT c.post_id::text, c.post_url, diff --git a/siikr/search.php b/siikr/search.php index 36318ca..7b063ee 100644 --- a/siikr/search.php +++ b/siikr/search.php @@ -2,7 +2,6 @@ require_once 'internal/globals.php'; $username = $_GET["username"]; -$raw_query = pg_escape_string($_GET["query"].""); $search_params_assoc = sanitizeParams($_GET); $search_params_arr = []; foreach($search_params_assoc as $k => $v) { @@ -12,10 +11,11 @@ //$parsed = parseParams($search_params); $parser = new Parser('simple'); //fancy new abstract syntax tree parse -$query = "websearch_to_tsquery('simple', '$raw_query')";//$parser->parse($raw_query); $blog_info = (object)[]; try { $db = get_db(); + $raw_query = $db->quote( $_GET["query"].""); + $query = "websearch_to_tsquery('simple', $raw_query)";//$parser->parse($raw_query); $response = call_tumblr($username, "info", [], true); if($response->meta->status != 200) { $error_string = ""; From 6c7fb2f810854eec9d381c54856869b57c927243 Mon Sep 17 00:00:00 2001 From: Kevin Meyer Date: Tue, 20 Aug 2024 02:38:15 -0400 Subject: [PATCH 20/21] Fixing get_db() --- docker-compose.yaml | 3 +++ docker/entrypoint.sh | 2 ++ setup_simple.sh | 2 ++ siikr.example.env | 2 +- siikr/get_tags.php | 2 +- siikr/internal/archive.php | 2 +- siikr/internal/embeddings.php | 2 +- siikr/internal/globals.php | 9 +++++---- siikr/management/dumpzip_blogs.php | 2 +- siikr/resolve_image_url.php | 2 +- siikr/search.php | 2 +- 11 files changed, 19 insertions(+), 11 deletions(-) diff --git a/docker-compose.yaml b/docker-compose.yaml index 1232410..61adee6 100644 --- a/docker-compose.yaml +++ b/docker-compose.yaml @@ -33,6 +33,9 @@ services: depends_on: postgres: condition: service_healthy + volumes: + # We run a diskspace check + - postgres_data:/var/lib/postgresql/data healthcheck: test: ["CMD", "curl", "-f", "http://localhost:80"] interval: 1m30s diff --git a/docker/entrypoint.sh b/docker/entrypoint.sh index b3991d8..1922ec8 100755 --- a/docker/entrypoint.sh +++ b/docker/entrypoint.sh @@ -11,6 +11,8 @@ cat > /var/www/html/auth/credentials.php < "$script_dir/siikr/internal/disks.php" << EOF diff --git a/siikr.example.env b/siikr.example.env index 39d41d7..32802d5 100644 --- a/siikr.example.env +++ b/siikr.example.env @@ -3,7 +3,7 @@ tumblr_API_consumer_key="PUT YOUR KEY HERE" pg_pass="PUT YOUR DB PASSWORD HERE" # If using Docker, this should be set to /var/lib/postgresql/data -pg_disk="PUT THE MOUNTPOINT OF WHEREVER THE DISK DRIVE STORING THE DB DATA IS HERE" +pg_disk="/var/lib/postgresql/data" document_root="/var/www/html/" #location you want to install siikr into php_dir="/usr/bin/php" #location of your active php install php_user="www-data" #the user your php server runs as diff --git a/siikr/get_tags.php b/siikr/get_tags.php index a8a2330..0a5de5f 100644 --- a/siikr/get_tags.php +++ b/siikr/get_tags.php @@ -2,7 +2,7 @@ require_once 'internal/globals.php'; $blog_uuid = $_GET["blog_uuid"]; try { - $db = get_db(); + $db = get_db($db_name, $db_app_user, $db_app_pass); $blog_info = (object)[ "valid" => false, "blog_uuid" => $blog_uuid, diff --git a/siikr/internal/archive.php b/siikr/internal/archive.php index ea1f940..3c92c63 100644 --- a/siikr/internal/archive.php +++ b/siikr/internal/archive.php @@ -2,7 +2,7 @@ require_once 'globals.php'; $archiver_uuid = uuid_create(UUID_TYPE_RANDOM); -$db = get_db(); +$db = get_db($db_name, $db_user, $db_pass); require_once 'lease.php'; diff --git a/siikr/internal/embeddings.php b/siikr/internal/embeddings.php index 69cb16b..06420da 100644 --- a/siikr/internal/embeddings.php +++ b/siikr/internal/embeddings.php @@ -12,7 +12,7 @@ 'ignore_errors' => true, ] ]; -$db = get_db(); +$db = get_db($db_name, $db_user, $db_pass); $unembedded = $db->prepare("SELECT * FROM images WHERE clip_attempted IS NULL LIMIT 10000"); $set_clip_attempted = $db->prepare("UPDATE images SET clip_attempted = now() WHERE image_id = :image_id"); diff --git a/siikr/internal/globals.php b/siikr/internal/globals.php index 0806f78..cf98dda 100644 --- a/siikr/internal/globals.php +++ b/siikr/internal/globals.php @@ -4,7 +4,6 @@ require_once $predir.'auth/credentials.php'; require_once 'disks.php'; - $clean_sp = ["sp_self_text", "sp_trail_text", "sp_image_text", "sp_tag_text"]; $clean_fp= ["fp_images", "fp_video", "fp_audio", "fp_ask", "fp_chat", "fp_link"]; $DENUM = [ @@ -339,7 +338,9 @@ function sanitizeParams($paramArr) { } function get_disk_stats() { - $diskpath = "/mnt/volume_sfo3_01"; + # Env var for the disk path + # default to /var/lib/postgresql/data + $diskpath = getenv('pg_disk') ?: '/var/lib/postgresql/data'; $total_diskspace = disk_total_space($diskpath); $free_space = disk_free_space($diskpath); $used_percent = (1 - $free_space/$total_diskspace)*100; @@ -372,7 +373,7 @@ function check_delete($tag_text, $prior_count, $blog_uuid, $db) { /** * Get a handle to the database. */ -function get_db() { - global $db_host, $db_name, $db_user, $db_pass; +function get_db($db_name, $db_user, $db_pass) { + global $db_host; return new PDO("pgsql:host=$db_host;dbname=$db_name", $db_user, $db_pass); } diff --git a/siikr/management/dumpzip_blogs.php b/siikr/management/dumpzip_blogs.php index be7c647..8b3a301 100644 --- a/siikr/management/dumpzip_blogs.php +++ b/siikr/management/dumpzip_blogs.php @@ -1,7 +1,7 @@ prepare("SELECT img_url FROM images where image_id = :image_id"); $get_image_stmt->execute(["image_id" => $image_id]); diff --git a/siikr/search.php b/siikr/search.php index 7b063ee..d3283f6 100644 --- a/siikr/search.php +++ b/siikr/search.php @@ -13,7 +13,7 @@ $parser = new Parser('simple'); //fancy new abstract syntax tree parse $blog_info = (object)[]; try { - $db = get_db(); + $db = get_db($db_name, $db_app_user, $db_app_pass); $raw_query = $db->quote( $_GET["query"].""); $query = "websearch_to_tsquery('simple', $raw_query)";//$parser->parse($raw_query); $response = call_tumblr($username, "info", [], true); From 598d13cc5ff77f2563b43fc52d2a25d69d579b58 Mon Sep 17 00:00:00 2001 From: Kevin Meyer Date: Tue, 20 Aug 2024 02:40:18 -0400 Subject: [PATCH 21/21] Adding two helper functions for databases --- siikr/internal/globals.php | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/siikr/internal/globals.php b/siikr/internal/globals.php index cf98dda..3227a2d 100644 --- a/siikr/internal/globals.php +++ b/siikr/internal/globals.php @@ -377,3 +377,13 @@ function get_db($db_name, $db_user, $db_pass) { global $db_host; return new PDO("pgsql:host=$db_host;dbname=$db_name", $db_user, $db_pass); } + +function get_admin_db() { + global $db_name, $db_user, $db_pass; + return get_db($db_name, $db_user, $db_pass); +} + +function get_app_db() { + global $db_name, $db_app_user, $db_app_pass; + return get_db($db_name, $db_app_user, $db_app_pass); +}