added support for postgres

This commit is contained in:
samuel-p 2021-10-29 21:00:54 +02:00
parent df2f775244
commit 2112fa1f5b
2 changed files with 21 additions and 16 deletions

View File

@ -24,7 +24,7 @@ COPY --from=builder /var/www /var/www
COPY entrypoint.sh /entrypoint.sh
COPY worker-entrypoint.sh /worker-entrypoint.sh
COPY wait-for-db.php /wait-for-db.php
RUN apt-install php${PHPVER}-curl php${PHPVER}-zip php${PHPVER}-bcmath php${PHPVER}-intl php${PHPVER}-mbstring php${PHPVER}-xml optipng pngquant jpegoptim gifsicle ffmpeg php${PHPVER}-imagick php${PHPVER}-gd php${PHPVER}-redis php${PHPVER}-mysql &&\
RUN apt-install php${PHPVER}-curl php${PHPVER}-zip php${PHPVER}-bcmath php${PHPVER}-intl php${PHPVER}-mbstring php${PHPVER}-xml optipng pngquant jpegoptim gifsicle ffmpeg php${PHPVER}-imagick php${PHPVER}-gd php${PHPVER}-redis php${PHPVER}-mysql php${PHPVER}-pgsql &&\
a2enmod rewrite &&\
sed -i 's/AllowOverride None/AllowOverride All/g' /etc/apache2/apache2.conf &&\
sed -i 's/^post_max_size.*/post_max_size = 100M/g' /etc/php/${PHPVER}/apache2/php.ini &&\

View File

@ -1,27 +1,32 @@
<?php
$conn = mysqli_connect(
getenv('DB_HOST'),
getenv('DB_USERNAME'),
getenv('DB_PASSWORD'),
getenv('DB_DATABASE'),
getenv('DB_PORT')
);
function connect()
{
$connection = getenv('DB_CONNECTION');
$host = getenv('DB_HOST');
$username = getenv('DB_USERNAME');
$password = getenv('DB_PASSWORD');
$database = getenv('DB_DATABASE');
$port = getenv('DB_PORT');
if ($connection === 'mysql') {
return mysqli_connect($host, $username, $password, $database, $port);
}
if ($connection === 'pgsql') {
return pg_connect('host=' . $host . ' port=' . $port . ' dbname=' . $database . ' user=' . $username . ' password=' . $password);
}
throw new Exception('unsupported connection type ' . $connection);
}
$conn = connect();
$counter = 10;
$count = 1;
while (!$conn) {
echo("Waiting for Database... $count / $counter\n");
sleep(2);
$conn = mysqli_connect(
getenv('DB_HOST'),
getenv('DB_USERNAME'),
getenv('DB_PASSWORD'),
getenv('DB_DATABASE'),
getenv('DB_PORT')
);
$conn = connect();
$count++;
if($count == $counter) {
if ($count == $counter) {
echo("Database did not respond after $counter tries, giving up\n");
die(1);
}