From 6067cb5cd3959eff661e80ac55c5bebeeda9be52 Mon Sep 17 00:00:00 2001 From: Tagadda <36127788+Tagadda@users.noreply.github.com> Date: Sun, 23 Jul 2023 06:08:42 +0200 Subject: [PATCH] enh configpanel for s3 --- conf/.env.production.sample | 13 ++++++---- config_panel.toml | 47 +++++++++++++++++++++++++++++++++++++ scripts/install | 14 +++++++++++ scripts/upgrade | 21 +++++++++++++++++ 4 files changed, 90 insertions(+), 5 deletions(-) create mode 100644 config_panel.toml diff --git a/conf/.env.production.sample b/conf/.env.production.sample index 7005b5d6..2a00fa1e 100644 --- a/conf/.env.production.sample +++ b/conf/.env.production.sample @@ -78,11 +78,14 @@ DEFAULT_LOCALE=__LANGUAGE__ # File storage (optional) # ----------------------- -S3_ENABLED=false -# S3_BUCKET=files.example.com -# AWS_ACCESS_KEY_ID= -# AWS_SECRET_ACCESS_KEY= -# S3_ALIAS_HOST=files.example.com +S3_ENABLED=__S3_ENABLED__ +S3_ENDPOINT=__S3_ENDPOINT__ +S3_BUCKET=__S3_BUCKET__ +AWS_ACCESS_KEY_ID=__S3_ACCESS_KEY_ID__ +AWS_SECRET_ACCESS_KEY=__S3_ACCESS_KEY_SECRET__ +S3_ALIAS_HOST=__S3_ALIAS_HOST__ +#S3_PERMISSION= +S3_FORCE_SINGLE_REQUEST=true # IP and session retention # ----------------------- diff --git a/config_panel.toml b/config_panel.toml new file mode 100644 index 00000000..d3106929 --- /dev/null +++ b/config_panel.toml @@ -0,0 +1,47 @@ +version = "1.0" + +[main] + [main.s3] + services = ["__APP__-web", "__APP__-sidekiq"] + name = "S3 Configuration" + optional = true + + [main.s3.s3_enabled] + ask.en = "Enable S3-compatible media storage" + type = "boolean" + yes = "true" + no = "false" + bind = "S3_ENABLED:__INSTALL_DIR__/live/.env.production" + + [main.s3.s3_endpoint] + ask = "S3 Endpoint" + example = "https://minio.domain.tld" + type = "url" + bind = "S3_ENDPOINT:__INSTALL_DIR__/live/.env.production" + visible = "s3_enabled" + + [main.s3.s3_bucket] + ask = "S3 Bucket" + type = "string" + example = "mastodata" + bind = "S3_BUCKET:__INSTALL_DIR__/live/.env.production" + visible = "s3_enabled" + + [main.s3.s3_access_key_id] + ask = "S3 Access Key ID" + type = "string" + bind = "AWS_ACCESS_KEY_ID:__INSTALL_DIR__/live/.env.production" + visible = "s3_enabled" + + [main.s3.s3_access_key_secret] + ask = "S3 Access Key Secret" + type = "password" + bind = "AWS_SECRET_ACCESS_KEY:__INSTALL_DIR__/live/.env.production" + visible = "s3_enabled" + + [main.s3.s3_alias_host] + ask = "S3 Alias Host" + help = "https://docs.joinmastodon.org/admin/optional/object-storage-proxy/" + type = "string" + bind = "S3_ALIAS_HOST:/var/www/__APP__/live/.env.production" + visible = "s3_enabled" diff --git a/scripts/install b/scripts/install index 1385a306..ca6e9fb7 100644 --- a/scripts/install +++ b/scripts/install @@ -14,6 +14,20 @@ admin_mail=$(ynh_user_get_info --username=$admin --key=mail) # Set `service` settings to support `yunohost app shell` command ynh_app_setting_set --app="$app" --key=service --value="$app-web.service" +# Define config_panel settings keys... +s3_enabled=false +ynh_app_setting_set --app=$app --key=s3_enabled --value=false +s3_endpoint="" +ynh_app_setting_set --app=$app --key=s3_endpoint --value="" +s3_bucket="" +ynh_app_setting_set --app=$app --key=s3_bucket --value="" +s3_access_key_id="" +ynh_app_setting_set --app=$app --key=s3_access_key_id --value="" +s3_access_key_secret="" +ynh_app_setting_set --app=$app --key=s3_access_key_secret --value="" +s3_alias_host="" +ynh_app_setting_set --app=$app --key=s3_alias_host --value="" + #================================================= # APP "BUILD" (DEPLOYING SOURCES, VENV, COMPILING ETC) #================================================= diff --git a/scripts/upgrade b/scripts/upgrade index 2dd3d324..da38c79f 100644 --- a/scripts/upgrade +++ b/scripts/upgrade @@ -40,6 +40,27 @@ if [[ -z "${service:-}" ]]; then ynh_app_setting_set --app="$app" --key=service --value="$service" fi +# If s3_enabled doesn't exist, create it +if [[ -z "$s3_enabled" ]]; then + s3_enabled=$(ynh_read_var_in_file --file="$config" --key="S3_ENABLED") + ynh_app_setting_set --app=$app --key=s3_enabled --value=$s3_enabled + + s3_endpoint=$(ynh_read_var_in_file --file="$config" --key="S3_ENDPOINT") + ynh_app_setting_set --app=$app --key=s3_endpoint --value=$s3_endpoint + + s3_bucket=$(ynh_read_var_in_file --file="$config" --key="S3_BUCKET") + ynh_app_setting_set --app=$app --key=s3_bucket --value=$s3_bucket + + s3_access_key_id=$(ynh_read_var_in_file --file="$config" --key="AWS_ACCESS_KEY_ID") + ynh_app_setting_set --app=$app --key=s3_access_key_id --value=$s3_access_key_id + + s3_access_key_secret=$(ynh_read_var_in_file --file="$config" --key="AWS_SECRET_ACCESS_KEY") + ynh_app_setting_set --app=$app --key=s3_access_key_secret --value=$s3_access_key_secret + + s3_alias_host=$(ynh_read_var_in_file --file="$config" --key="S3_ALIAS_HOST") + ynh_app_setting_set --app=$app --key=s3_alias_host --value=$s3_alias_host +fi + # Remove previous added repository ynh_remove_extra_repo