Docker compose setup (#513)

* fix password reset bug

* self hosted mode middleware changes on  pages

* fix lint

* wip: self hosted changes

* wip: self hosted frontend changes

* wip self hosted mode changes

* typo correction

* remove commented logic

* fix env variable names

* fix lint issues

* fix minor updates

* #445 Switched from single monolithic docker image to a docker-compose
 orchestrated network of services

* Automatically configures shared secret

* Working through some issues

* Use local file storage

* Moved the dockerfiles

* Fixed some issues when building from clean

* Corrected workflow

* Hopefully schedules everything correctly now

* Prep storage for worker process as well

* .env files are required

* Pinned dependency versions

* Disable self hosted in the client as well

* Removed double defaulting logic

* Using regexs is more succinct

* Added FRONT_URL environment variable

* Merge 236e4-self-hosted-mode-changes

* Improve inital user setup

* Finalized the new docker-compose setup

* Fix back-end formatting issues

---------

Co-authored-by: Frank <csskfaves@gmail.com>
Co-authored-by: Don Benjamin <don@webhammer.co.uk>
This commit is contained in:
Julien Nahum
2024-08-05 12:06:20 +02:00
committed by GitHub
parent 6b13f95322
commit 3280e38ee1
49 changed files with 6152 additions and 3431 deletions

115
docker/php-fpm-entrypoint Normal file
View File

@@ -0,0 +1,115 @@
#!/bin/bash
main() {
read_env
prep_file_permissions
prep_storage
if is_master "$@"; then
prep_laravel_secrets
wait_for_db
apply_db_migrations
run_init_project
mark_ready
else
wait_for_ready
wait_for_db
fi
read_env
run_server "$@"
}
is_master() {
echo "$@" | grep -q php-fpm
}
read_env() {
#set +x
[ -f .env ] || touch .env
. .env
#set -x
}
prep_file_permissions() {
chmod a+x ./artisan
}
prep_laravel_secrets() {
read_env
[ "x$APP_KEY" != "x" ] || {
echo "Generating Laravel key..."
grep -q "APP_KEY=" .env || {
echo "APP_KEY=" >> .env
}
./artisan key:generate
read_env
}
[ "x$JWT_SECRET" != "x" ] || {
echo "Generating Laravel Secret..."
./artisan jwt:secret -f
read_env
}
[ "x$FRONT_API_SECRET" != "x" ] || {
echo "Generating Shared Client Secret..."
/usr/local/bin/generate-api-secret.sh
read_env
}
echo "Done with secrets"
}
apply_db_migrations() {
echo "Running DB Migrations"
./artisan migrate
}
run_init_project() {
echo "Running app:init-project command"
./artisan app:init-project
}
wait_for_ready() {
echo "Checking keys have been generated"
until [ -f /secrets/configured ]; do
sleep 1;
echo "Waiting for keys to generate"
done
}
mark_ready() {
touch /secrets/configured
}
wait_for_db() {
until ./artisan migrate:status 2>&1 | grep -q -E "(Migration table not found|Migration name)"; do
echo "Waiting for DB to bootup"
sleep 1
done
}
run_server() {
echo "Booting $@"
read_env
/usr/local/bin/docker-php-entrypoint "$@"
}
prep_storage() {
[ -L storage ] || {
echo "Backing up initial storage directory"
rm -rf /etc/initial-storage
mv ./storage /etc/initial-storage
}
[ -d /persist/storage ] || {
echo "Initialising blank storage dir"
mkdir -p /persist
cp -a /etc/initial-storage /persist/storage
chmod 777 -R /persist/storage
}
touch /var/log/opnform.log
chown www-data /var/log/opnform.log
echo "Linking persistent storage into app"
ln -t . -sf /persist/storage
}
main "$@"