summaryrefslogtreecommitdiff
path: root/build
diff options
context:
space:
mode:
authorFreya Murphy <freya@freyacat.org>2024-12-23 11:13:27 -0500
committerFreya Murphy <freya@freyacat.org>2024-12-23 11:13:27 -0500
commit5a2ba9c2e7605bb788bc406184547d22c6436867 (patch)
treecbd988d534e8a8593a31d70571222443f80da0b3 /build
parentfix about modal (diff)
downloadxssbook2-5a2ba9c2e7605bb788bc406184547d22c6436867.tar.gz
xssbook2-5a2ba9c2e7605bb788bc406184547d22c6436867.tar.bz2
xssbook2-5a2ba9c2e7605bb788bc406184547d22c6436867.zip
v2.1.0, refactor w/ crimson
Diffstat (limited to 'build')
-rw-r--r--build/init/Dockerfile21
-rwxr-xr-xbuild/init/init148
-rw-r--r--build/nginx/Dockerfile21
-rw-r--r--build/php/Dockerfile17
-rw-r--r--build/postgres/Dockerfile21
-rw-r--r--build/postgrest/Dockerfile30
-rwxr-xr-xbuild/postgrest/entrypoint.sh21
-rw-r--r--build/postgrest/postgrest.tar.xzbin3648348 -> 0 bytes
-rw-r--r--build/shim/Dockerfile9
-rw-r--r--build/stamp.sh14
10 files changed, 0 insertions, 302 deletions
diff --git a/build/init/Dockerfile b/build/init/Dockerfile
deleted file mode 100644
index 98eb285..0000000
--- a/build/init/Dockerfile
+++ /dev/null
@@ -1,21 +0,0 @@
-FROM alpine:3.19
-
-# install packages
-RUN apk add --no-cache postgresql16-client tini shadow
-RUN rm -fr /var/cache/apk/*
-
-# setup main user
-RUN adduser -D init
-RUN groupmod --gid 1000 init
-RUN usermod --uid 1000 init
-
-# copy scripts
-COPY ./init /usr/local/bin/init
-
-# remove build packages
-RUN apk del shadow
-
-# do the
-USER init
-ENTRYPOINT ["/sbin/tini", "--"]
-CMD ["/usr/local/bin/init"]
diff --git a/build/init/init b/build/init/init
deleted file mode 100755
index c8dd3f0..0000000
--- a/build/init/init
+++ /dev/null
@@ -1,148 +0,0 @@
-#!/bin/sh
-
-errors=$(mktemp)
-
-step() {
- printf '\x1b[34;1m>> %s\x1b[0m\n' "$*"
-}
-
-error() {
- {
- printf '\x1b[31;1merror: \x1b[0m%s\n' "$*";
- grep -v 'current transaction is aborted' < "$errors";
- printf "\x1b[31m;1error: \x1b[0mAborting migrations, fix file(s) then restart process.";
- } 1>&2;
-}
-
-try() {
- "$@" 2> "$errors";
- count=$(grep -c 'ERROR' < "$errors")
- if [ "$count" -eq 0 ]; then
- return 0;
- else
- return 1;
- fi
-}
-
-export PGPASSWORD="$POSTGRES_PASSWORD"
-
-psql() {
- /usr/bin/psql \
- -h db \
- -p 5432 \
- -d "$POSTGRES_DB" \
- -U "$POSTGRES_USER" \
- "$@"
-}
-
-pg_isready() {
- /usr/bin/pg_isready \
- -h db \
- -p 5432 \
- -d "$POSTGRES_DB" \
- -U "$POSTGRES_USER"
-}
-
-curr_revision() {
- psql -qtAX -f /db/rev.sql;
-}
-
-wait_until_ready() {
- step 'Checking if the database is ready...';
- while true; do
- pg_isready;
- code=$?;
- if [ $code -eq 0 ]; then
- break;
- fi
- sleep 3;
- done
-}
-
-run_migrations() {
- i="$1"
- while true; do
- name=$(printf "%04d" "$i");
- file="/db/migrations/$name.sql"
- if [ -f "$file" ]; then
- if try psql -f "$file"; then
- i=$((i+1));
- continue;
- else
- error "An error occoured during a migration (rev $name)"
- return 1;
- fi
- else
- return 0;
- fi
- done
-}
-
-init_api() {
- if try psql -f /db/rest/rest.sql; then
- return 0;
- else
- error "An error occoured during api initialization"
- return 1;
- fi
-}
-
-update_jwt() {
- if try psql -c "UPDATE sys.database_info SET jwt_secret = '$JWT_SECRET' WHERE name = current_database();"; then
- return 0;
- else
- error "Could not update JWT"
- return 1;
- fi
-}
-
-load_ext() {
- psql -qtAX -f /db/ext.sql;
-}
-
-init () {
- # reomve ready status
- # so php ignores requests
- rm -f /status/ready
-
- step 'Waiting for database';
- # make sure the database is running
- # before we run any requests
- wait_until_ready;
- step 'Database ready';
-
- step 'Loading extensions';
- # Make sure extensions are loaded
- load_ext;
-
- step 'Peforming migrations';
- # get the current revision
- REV=$(curr_revision);
- step "Database at revision: $REV"
- # run each migration that is
- # higher than our current revision
- if ! run_migrations "$REV"; then
- return 1;
- fi
-
- step 'Initalizing the api';
- # reinit the api schema for
- # postgrest
- if ! init_api; then
- return 1;
- fi
-
- step 'Updating JWT secret';
- # make sure postgres has the corrent
- # jwt secret
- if ! update_jwt; then
- return 1;
- fi
-
- step 'Database is initialized'
- # database is ready
- touch /status/ready
-}
-
-init
-rm "$errors"
diff --git a/build/nginx/Dockerfile b/build/nginx/Dockerfile
deleted file mode 100644
index 6aa4e00..0000000
--- a/build/nginx/Dockerfile
+++ /dev/null
@@ -1,21 +0,0 @@
-FROM alpine:3.19
-
-# install packages
-RUN apk add --no-cache nginx shadow tini
-RUN rm -fr /var/cache/apk/*
-
-# update nginx user
-RUN groupmod --gid 1000 nginx
-RUN usermod --uid 1000 nginx
-
-# remove build packages
-RUN apk del shadow
-
-# make log syms
-RUN ln -sf /dev/stdout /var/log/nginx/access.log && \
- ln -sf /dev/stderr /var/log/nginx/error.log
-
-# do the
-USER nginx
-ENTRYPOINT ["/sbin/tini", "--"]
-CMD ["/usr/sbin/nginx", "-c", "/etc/nginx/nginx.conf"]
diff --git a/build/php/Dockerfile b/build/php/Dockerfile
deleted file mode 100644
index 5f4bdd5..0000000
--- a/build/php/Dockerfile
+++ /dev/null
@@ -1,17 +0,0 @@
-FROM php:fpm-alpine
-
-# install packages
-RUN apk add --no-cache postgresql-dev runuser shadow
-RUN rm -fr /var/cache/apk/*
-
-# update php user
-RUN groupmod --gid 1000 www-data
-RUN usermod --uid 1000 www-data
-
-# install php packages
-RUN docker-php-ext-configure pgsql -with-pgsql=/usr/local/pgsql
-RUN docker-php-ext-install pdo pdo_pgsql
-
-# remove build packages
-RUN apk del shadow
-USER www-data
diff --git a/build/postgres/Dockerfile b/build/postgres/Dockerfile
deleted file mode 100644
index 32bca6e..0000000
--- a/build/postgres/Dockerfile
+++ /dev/null
@@ -1,21 +0,0 @@
-FROM postgres:16-alpine
-
-# install packages
-RUN apk add --no-cache make git shadow
-RUN rm -fr /var/cache/apk/*
-
-# install pgjwt
-RUN git clone https://github.com/michelp/pgjwt.git /tmp/pgjwt
-WORKDIR /tmp/pgjwt
-RUN make install
-
-# update postgres user
-RUN groupmod --gid 1000 postgres
-RUN usermod --uid 1000 postgres
-
-# remove build packages
-RUN apk del make git shadow
-
-# fix workdir
-WORKDIR /
-USER postgres
diff --git a/build/postgrest/Dockerfile b/build/postgrest/Dockerfile
deleted file mode 100644
index bf1a573..0000000
--- a/build/postgrest/Dockerfile
+++ /dev/null
@@ -1,30 +0,0 @@
-FROM alpine:3.19
-
-# install packages
-RUN apk add --no-cache tini shadow
-RUN rm -fr /var/cache/apk/*
-
-# setup main user
-RUN adduser -D postgrest
-RUN groupmod --gid 1000 postgrest
-RUN usermod --uid 1000 postgrest
-
-# install postgrest
-COPY ./postgrest.tar.xz /tmp/postgrest.tar.xz
-RUN tar xJf /tmp/postgrest.tar.xz -C /usr/local/bin
-RUN rm /tmp/postgrest.tar.xz
-
-# copy scripts
-COPY ./entrypoint.sh /usr/local/bin/entrypoint.sh
-
-# remove build packages
-RUN apk del shadow
-
-# make the dirs
-RUN mkdir -p /etc/postgrest.d && \
- chown postgrest:postgrest /etc/postgrest.d
-
-# do the
-USER postgrest
-ENTRYPOINT ["/sbin/tini", "--"]
-CMD ["/usr/local/bin/entrypoint.sh"]
diff --git a/build/postgrest/entrypoint.sh b/build/postgrest/entrypoint.sh
deleted file mode 100755
index 71b433d..0000000
--- a/build/postgrest/entrypoint.sh
+++ /dev/null
@@ -1,21 +0,0 @@
-#!/bin/sh
-
-config=/etc/postgrest.d/postgrest.conf
-
-PGRST_DB_URI="postgres://authenticator:postgrest@db:5432/$POSTGRES_DB"
-PGRST_ROLE="rest_anon"
-PGRST_SCHEMA="api"
-
-rm -fr "$config"
-touch "$config"
-{
- printf 'db-uri = "%s"\n' "$PGRST_DB_URI";
- printf 'db-anon-role = "%s"\n' "$PGRST_ROLE";
- printf 'db-schemas = "%s"\n' "$PGRST_SCHEMA";
- printf 'jwt-secret = "%s"\n' "$JWT_SECRET";
- printf 'jwt-secret-is-base64 = false\n';
- printf 'server-host = "*"\n';
- printf 'server-port = 3000\n';
-} >> $config
-
-exec /usr/local/bin/postgrest "$config"
diff --git a/build/postgrest/postgrest.tar.xz b/build/postgrest/postgrest.tar.xz
deleted file mode 100644
index 33c2b2d..0000000
--- a/build/postgrest/postgrest.tar.xz
+++ /dev/null
Binary files differ
diff --git a/build/shim/Dockerfile b/build/shim/Dockerfile
deleted file mode 100644
index 82cc9a7..0000000
--- a/build/shim/Dockerfile
+++ /dev/null
@@ -1,9 +0,0 @@
-FROM alpine:3.19
-RUN apk add --no-cache \
- php83 \
- php83-pdo \
- php83-pdo_sqlite \
- php83-pdo_pgsql \
- tini
-ENTRYPOINT ["/sbin/tini", "--"]
-CMD ["/usr/bin/php83", "/opt/shim/shim.php"]
diff --git a/build/stamp.sh b/build/stamp.sh
deleted file mode 100644
index 3b19b04..0000000
--- a/build/stamp.sh
+++ /dev/null
@@ -1,14 +0,0 @@
-#!/bin/sh
-
-out="./src/web/stamp.php"
-public="./src/public"
-files=$(find "$public" -type f -printf %P\\n)
-
-printf "<?php\n\$__stamps = array();\n" > "$out"
-for file in $files; do
- stamp=$(date +%s -r "$public/$file")
- echo "\$__stamps['public/$file'] = $stamp;" >> "$out";
-done
-echo "define('FILE_TIMES', \$__stamps);" >> "$out"
-echo "unset(\$__stamps);" >> "$out"
-