Skip to content

Commit

Permalink
enh configpanel for s3
Browse files Browse the repository at this point in the history
  • Loading branch information
Tagadda authored and Salamandar committed May 27, 2024
1 parent 8003bae commit 6067cb5
Show file tree
Hide file tree
Showing 4 changed files with 90 additions and 5 deletions.
13 changes: 8 additions & 5 deletions conf/.env.production.sample
Original file line number Diff line number Diff line change
Expand Up @@ -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
# -----------------------
Expand Down
47 changes: 47 additions & 0 deletions config_panel.toml
Original file line number Diff line number Diff line change
@@ -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"
14 changes: 14 additions & 0 deletions scripts/install
Original file line number Diff line number Diff line change
Expand Up @@ -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)
#=================================================
Expand Down
21 changes: 21 additions & 0 deletions scripts/upgrade
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down

0 comments on commit 6067cb5

Please sign in to comment.