518 setup env command (#519)
* Created command and cleaned * Simplified docker setup, created script to generate .env * add git ignore file back
This commit is contained in:
@@ -1,61 +1,22 @@
|
||||
#!/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
|
||||
wait_for_db
|
||||
apply_db_migrations
|
||||
run_init_project
|
||||
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
|
||||
@@ -66,28 +27,15 @@ run_init_project() {
|
||||
./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() {
|
||||
echo "Waiting for DB to be ready"
|
||||
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
|
||||
echo "Starting server $@"
|
||||
/usr/local/bin/docker-php-entrypoint "$@"
|
||||
}
|
||||
|
||||
@@ -112,4 +60,4 @@ prep_storage() {
|
||||
ln -t . -sf /persist/storage
|
||||
}
|
||||
|
||||
main "$@"
|
||||
main "$@"
|
||||
Reference in New Issue
Block a user