From 066bea4cdffab3212e16ac181955e43beae2b855 Mon Sep 17 00:00:00 2001 From: dragondaddy Date: Tue, 8 Aug 2023 21:45:35 +0200 Subject: [PATCH] We mess with api/.env --- conf/sample.env | 86 +++++++++++++++++++++++++++++++++++++++++++++++++ scripts/install | 75 +++++------------------------------------- 2 files changed, 94 insertions(+), 67 deletions(-) create mode 100644 conf/sample.env diff --git a/conf/sample.env b/conf/sample.env new file mode 100644 index 0000000..205c21a --- /dev/null +++ b/conf/sample.env @@ -0,0 +1,86 @@ +# Version of the API +VERSION="0.5.3" + +# Do we allow bots ? +ALLOW_BOTS="false" + +# What type of file are we allowed to upload ? +ALLOW_VIDEO_UPLOAD="true" +ALLOW_IMAGE_UPLOAD="true" +ALLOW_PDF_UPLOAD="true" +ALLOW_AUDIO_UPLOAD="false" # not allowed since backend is not ready + +# Task execution intervals in seconds +CRON_CONVERT_IMAGES="60" # 1 minute +CRON_CONVERT_VIDEO="3600" # 1 hour +CRON_NOTIFICATION_EMAILS="3600" # 1 hour +CRON_COMPRESS_GIFS="3600" # 1 hour +CRON_BOT_ACTIVATE="3600" # 1 hour +CRON_CLEAN_CACHE="86400" # 1 day +CRON_CLEAN_NOTIFICATIONS="604800" # 7 days +CRON_CLEAN_FILES="604800" # 7 days +CRON_CLEAN_MESSAGES="604800" # 7 days +CRON_CLEAN_GROUPS="2592000" # 30 days + +# Can be set to "prod" or "dev" +APP_ENV="prod" + +# APP_SECRET is used as seed for all random things. +APP_SECRET="__RANDOM_STRING__" + +# DOMAIN is used to generate urls +DOMAIN="__DOMAIN__" + +# LANG is the default language of the API +LANG="__LANGUAGE__" + +# IDLE_HOURS indicate hours during which heavy operations can occur +IDLE_HOURS="01-07" + +# Number of threads to use for video conversion +# "0" means that ffmpeg uses all the processing power that it wants +VIDEO_CONVERSION_THREADS="1" + +# Control wether a video should be converted or not +# We define here types and size conditions that should be accepted as-is, without conversion +# Since video/mp4 is maximally compatible, it's probably better to keep it as the only accepted type +# You can check comptibility with browsers here: https://caniuse.com/?search=video%20format +# VIDEO_FORMAT_NOT_CONVERTED is a comma (',') separated list +# VIDEO_SIZE_NOT_CONVERTED is in Mo +VIDEO_FORMAT_NOT_CONVERTED="video/mp4" +VIDEO_SIZE_NOT_CONVERTED="10" + +# Maximum number of seconds a task can lock the cron command +# The zusam:cron command will wait that a previous task is finished before launching a new one +# This is the time in seconds before it considers the task as stalled and clears the lock +MAX_TASK_LOCK_DURATION="14400" + +# DATABASE_URL is used to locate and eventually connect to the db +DATABASE_URL="sqlite:///%kernel.project_dir%/../data/data.db" + +# ffmpeg binary (You can usually find it with `command -v ffmpeg`) +FFMPEG_PATH="/usr/bin/ffmpeg" + +# ghostscript binary (You can usually find it with `command -v gs`) +GHOSTSCRIPT_PATH="/usr/bin/gs" + +# files directory +dir_files="%kernel.project_dir%/../data/files" +dir_cache="%kernel.project_dir%/../data/cache" +dir_bots="%kernel.project_dir%/../data/bots" + +# Should we allow mails to be sent ? +ALLOW_EMAIL="false" + +# For Gmail as a transport, use: "gmail://username:password@localhost" +# For a generic SMTP server, use: "smtp://localhost:25?encryption=&auth_mode=" +# Delivery is disabled via "null://localhost" +MAILER_DSN=null://localhost +mailer_username="" +mailer_password="" +mailer_auth_mode="cram-md5" +mailer_port=587 +mailer_host="" +mailer_transport="smtp" +mailer_encryption="tls" + diff --git a/scripts/install b/scripts/install index 7313d69..736a05e 100755 --- a/scripts/install +++ b/scripts/install @@ -32,27 +32,6 @@ ynh_app_setting_set --app=$app --key=fpm_footprint --value=$fpm_footprint ynh_app_setting_set --app=$app --key=fpm_free_footprint --value=$fpm_free_footprint ynh_app_setting_set --app=$app --key=fpm_usage --value=$fpm_usage -# Install parameters are automatically saved as settings -# -# Settings are automatically loaded as bash variables -# in every app script context, therefore typically these will exist: -# - $domain -# - $path -# - $language -# ... etc -# -# Resources defined in the manifest are provisioned prior to this script -# and corresponding settings are also available, such as: -# - $install_dir -# - $port -# - $db_name -# ... - -# -# $app is the app id (i.e. 'example' for first install, -# or 'example__2', '__3', ... for multi-instance installs) -# - #================================================= # APP "BUILD" (DEPLOYING SOURCES, VENV, COMPILING ETC) #================================================= @@ -81,36 +60,15 @@ chown -R $app:www-data "$install_dir" #================================================= ynh_script_progression --message="Adding system configurations related to $app..." --weight=1 -### `ynh_add_fpm_config` is used to set up a PHP config. -### You can remove it if your app doesn't use PHP. -### `ynh_add_fpm_config` will use the files conf/php-fpm.conf -### If you're not using these lines: -### - You can remove these files in conf/. -### - Remove the section "BACKUP THE PHP-FPM CONFIGURATION" in the backup script -### - Remove also the section "REMOVE PHP-FPM CONFIGURATION" in the remove script -### - As well as the section "RESTORE THE PHP-FPM CONFIGURATION" in the restore script -### with the reload at the end of the script. -### - And the section "PHP-FPM CONFIGURATION" in the upgrade script - -# Create a dedicated PHP-FPM config using the conf/php-fpm.conf or conf/extra_php-fpm.conf +# Create a dedicated PHP-FPM config using conf/extra_php-fpm.conf ynh_add_fpm_config # Create a dedicated NGINX config using the conf/nginx.conf template ynh_add_nginx_config -### `ynh_use_logrotate` is used to configure a logrotate configuration for the logs of this app. -### Use this helper only if there is effectively a log file for this app. -### If you're not using this helper: -### - Remove the section "BACKUP LOGROTATE" in the backup script -### - Remove also the section "REMOVE LOGROTATE CONFIGURATION" in the remove script -### - As well as the section "RESTORE THE LOGROTATE CONFIGURATION" in the restore script -### - And the section "SETUP LOGROTATE" in the upgrade script - -# Use logrotate to manage application logfile(s) -# ynh_use_logrotate - # Create a dedicated Fail2Ban config -#ynh_add_fail2ban_config --logpath="/var/log/nginx/${domain}-error.log" --failregex="Regex to match into the log for a failed login" +# We'll see that in later versions +# ynh_add_fail2ban_config --logpath="/var/log/nginx/${domain}-error.log" --failregex="Regex to match into the log for a failed login" #================================================= # APP INITIAL CONFIGURATION @@ -119,34 +77,17 @@ ynh_add_nginx_config #================================================= # ynh_script_progression --message="Adding a configuration file..." --weight=1 -### You can add specific configuration files. -### -### Typically, put your template conf file in ../conf/your_config_file -### The template may contain strings such as __FOO__ or __FOO_BAR__, -### which will automatically be replaced by the values of $foo and $foo_bar -### -### ynh_add_config will also keep track of the config file's checksum, -### which later during upgrade may allow to automatically backup the config file -### if it's found that the file was manually modified -### -### Check the documentation of `ynh_add_config` for more info. - -# ynh_add_config --template="some_config_file" --destination="$install_dir/some_config_file" +ynh_add_config --template="../conf/sample.env" --destination="$install_dir/api/.env" # FIXME: this should be handled by the core in the future # You may need to use chmod 600 instead of 400, # for example if the app is expected to be able to modify its own config -# chmod 400 "$install_dir/some_config_file" -# chown $app:$app "$install_dir/some_config_file" - -### For more complex cases where you want to replace stuff using regexes, -### you shoud rely on ynh_replace_string (which is basically a wrapper for sed) -### When doing so, you also need to manually call ynh_store_file_checksum -### -### ynh_replace_string --match_string="match_string" --replace_string="replace_string" --target_file="$install_dir/some_config_file" -### ynh_store_file_checksum --file="$install_dir/some_config_file" +chmod 600 "$install_dir/api/.env" +chown $app:www-data "$install_dir/api/.env" +#================================================= # DATABASE +#================================================= ynh_script_progression --message="Initialiazing the database..." --weight=1 /usr/bin/php$phpversion $install_dir/api/bin/console zusam:init $email $first_group $first_user_pass