Initial commit

This commit is contained in:
teutat3s 2023-03-06 22:56:27 +01:00
commit 529b194a54
Signed by: teutat3s
GPG key ID: 18DAE600A6BBE705
6 changed files with 168 additions and 0 deletions

1
.dockerignore Normal file
View file

@ -0,0 +1 @@
local.yaml

1
.gitignore vendored Normal file
View file

@ -0,0 +1 @@
local.yaml

6
Dockerfile Normal file
View file

@ -0,0 +1,6 @@
FROM kimai/kimai2:apache-1.30.6-prod
# Upstream: https://github.com/tobybatch/kimai2/blob/main/Dockerfile
# Override default entrypoint script and apache conf
COPY assets/startup.sh /startup.sh
COPY assets/000-default.conf /etc/apache2/sites-available/000-default.conf

27
assets/000-default.conf Normal file
View file

@ -0,0 +1,27 @@
<VirtualHost *:8001>
ServerAdmin webmaster@localhost
DocumentRoot /opt/kimai/public
PassEnv DATABASE_PREFIX
PassEnv MAILER_FROM
PassEnv APP_ENV
PassEnv APP_SECRET
PassEnv DATABASE_URL
PassEnv MAILER_URL
PassEnv TRUSTED_PROXIES
PassEnv TRUSTED_HOSTS
<Directory "/opt/kimai/public">
Require all granted
DirectoryIndex index.php
AllowOverride All
</Directory>
<Directory /opt/kimai/public/assets>
Order Deny,Allow
Deny from all
</Directory>
</VirtualHost>
ServerName localhost

86
assets/startup.sh Executable file
View file

@ -0,0 +1,86 @@
#!/bin/bash
echo $KIMAI
function waitForDB() {
# Parse sql connection data
if [ ! -z "$DATABASE_URL" ]; then
DB_TYPE=$(awk -F '[/:@]' '{print $1}' <<< $DATABASE_URL)
DB_USER=$(awk -F '[/:@]' '{print $4}' <<< $DATABASE_URL)
DB_PASS=$(awk -F '[/:@]' '{print $5}' <<< $DATABASE_URL)
DB_HOST=$(awk -F '[/:@]' '{print $6}' <<< $DATABASE_URL)
DB_PORT=$(awk -F '[/:@]' '{print $7}' <<< $DATABASE_URL)
DB_BASE=$(awk -F '[/?]' '{print $4}' <<< $DATABASE_URL)
else
DB_TYPE=${DB_TYPE:mysql}
if [ "$DB_TYPE" == "mysql" ]; then
export DATABASE_URL="${DB_TYPE}://${DB_USER:=kimai}:${DB_PASS:=kimai}@${DB_HOST:=sqldb}:${DB_PORT:=3306}/${DB_BASE:=kimai}"
else
echo "Unknown database type, cannot proceed. Only 'mysql' is supported, received: [$DB_TYPE]"
exit 1
fi
fi
re='^[0-9]+$'
if ! [[ $DB_PORT =~ $re ]] ; then
DB_PORT=3306
fi
echo "Wait for MySQL DB connection ..."
until php /dbtest.php $DB_HOST $DB_BASE $DB_PORT $DB_USER $DB_PASS; do
echo Checking DB: $?
sleep 3
done
echo "Connection established"
}
function handleStartup() {
# set mem limits and copy in custom logger config
if [ "${APP_ENV}" == "prod" ]; then
sed "s/128M/${memory_limit}M/g" /usr/local/etc/php/php.ini-production > /usr/local/etc/php/php.ini
if [ "${KIMAI:0:1}" -lt "2" ]; then
cp /assets/monolog-prod.yaml /opt/kimai/config/packages/monolog.yaml
else
assets/monolog.yaml /opt/kimai/config/packages/monolog.yaml
fi
else
sed "s/128M/${memory_limit}M/g" /usr/local/etc/php/php.ini-development > /usr/local/etc/php/php.ini
if [ "${KIMAI:0:1}" -lt "2" ]; then
cp /assets/monolog-dev.yaml /opt/kimai/config/packages/monolog.yaml
else
assets/monolog.yaml /opt/kimai/config/packages/monolog.yaml
fi
fi
# Handle custom config
if [ -f /opt/kimai/public/assets/local.yaml ]; then
cp /opt/kimai/public/assets/local.yaml /opt/kimai/config/packages/local.yaml
fi
# These are idempotent, run them anyway
tar -zx -C /opt/kimai -f /var/tmp/public.tgz
/opt/kimai/bin/console -n kimai:install
/opt/kimai/bin/console -n kimai:update
if [ ! -z "$ADMINPASS" ] && [ ! -a "$ADMINMAIL" ]; then
/opt/kimai/bin/console kimai:create-user superadmin $ADMINMAIL ROLE_SUPER_ADMIN $ADMINPASS
fi
export KIMAI=$(/opt/kimai/bin/console kimai:version --short)
echo $KIMAI > /opt/kimai/var/installed
echo "Kimai2 ready"
}
function runServer() {
/opt/kimai/bin/console kimai:reload --env=$APP_ENV
if [ -e /use_apache ]; then
/usr/sbin/apache2ctl -D FOREGROUND
elif [ -e /use_fpm ]; then
exec php-fpm
else
echo "Error, unknown server type"
fi
}
waitForDB
handleStartup
runServer
exit

47
fly.toml Normal file
View file

@ -0,0 +1,47 @@
# fly.toml file generated for kimai-app on 2023-03-05T17:15:42+01:00
app = "kimai-app"
kill_signal = "SIGINT"
kill_timeout = 5
processes = []
[mounts]
source="kimaidata"
destination="/opt/kimai/public"
[env]
ADMINMAIL = "jfw@miom.space"
MAILER_FROM = "jfw@miom.space"
DB_TYPE = "mysql"
DB_USER = "kimai_user"
DB_HOST = "inv-db.internal"
TRUSTED_HOSTS = "track.faenix.eu,kimai-app.fly.dev,localhost,127.0.0.1"
[experimental]
auto_rollback = true
[[services]]
http_checks = []
internal_port = 8001
processes = ["app"]
protocol = "tcp"
script_checks = []
[services.concurrency]
hard_limit = 25
soft_limit = 20
type = "connections"
[[services.ports]]
force_https = true
handlers = ["http"]
port = 80
[[services.ports]]
handlers = ["tls", "http"]
port = 443
[[services.tcp_checks]]
grace_period = "1s"
interval = "15s"
restart_limit = 0
timeout = "2s"