mirror of
https://github.com/YunoHost-Apps/django_example_ynh.git
synced 2024-09-03 18:26:21 +02:00
Revert path change: Keep '__FINALPATH__' and '__PUBLIC_PATH__'
Install the app project into: '__FINALPATH__' -> `/opt/yunohost/$app` Store files to serve via nginx in: '__PUBLIC_PATH__' -> `/var/www/$app`
This commit is contained in:
parent
52b0a6e58b
commit
9f169cd1a4
11 changed files with 55 additions and 32 deletions
|
@ -2,7 +2,7 @@
|
|||
location __PATH__/static/ {
|
||||
# Service static files by nginx
|
||||
# e.g.: /var/www/$app/static
|
||||
alias __FINALPATH__/static/;
|
||||
alias __PUBLIC_PATH__/static/;
|
||||
expires 30d;
|
||||
}
|
||||
|
||||
|
|
|
@ -19,9 +19,12 @@ DEBUG = False # Don't turn DEBUG on in production!
|
|||
|
||||
# -----------------------------------------------------------------------------
|
||||
|
||||
FINALPATH = __Path('__FINALPATH__') # /var/www/$app
|
||||
FINALPATH = __Path('__FINALPATH__') # /opt/yunohost/$app
|
||||
assert FINALPATH.is_dir(), f'Directory not exists: {FINALPATH}'
|
||||
|
||||
PUBLIC_PATH = __Path('__PUBLIC_PATH__') # /var/www/$app
|
||||
assert PUBLIC_PATH.is_dir(), f'Directory not exists: {PUBLIC_PATH}'
|
||||
|
||||
LOG_FILE = __Path('__LOG_FILE__') # /var/log/$app/django_example_ynh.log
|
||||
assert LOG_FILE.is_file(), f'File not exists: {LOG_FILE}'
|
||||
|
||||
|
@ -37,6 +40,26 @@ SECRET_KEY = __get_or_create_secret(FINALPATH / 'secret.txt') # /opt/yunohost/$
|
|||
|
||||
# INSTALLED_APPS.append('<insert-your-app-here>')
|
||||
|
||||
MIDDLEWARE.insert(
|
||||
MIDDLEWARE.index('django.contrib.auth.middleware.AuthenticationMiddleware') + 1,
|
||||
# login a user via HTTP_REMOTE_USER header from SSOwat:
|
||||
'django_yunohost_integration.sso_auth.auth_middleware.SSOwatRemoteUserMiddleware',
|
||||
)
|
||||
|
||||
# Keep ModelBackend around for per-user permissions and superuser
|
||||
AUTHENTICATION_BACKENDS = (
|
||||
# Authenticate via SSO and nginx 'HTTP_REMOTE_USER' header:
|
||||
'django_yunohost_integration.sso_auth.auth_backend.SSOwatUserBackend',
|
||||
#
|
||||
# Fallback to normal Django model backend:
|
||||
'django.contrib.auth.backends.ModelBackend',
|
||||
)
|
||||
|
||||
LOGIN_REDIRECT_URL = None
|
||||
LOGIN_URL = '/yunohost/sso/'
|
||||
LOGOUT_REDIRECT_URL = '/yunohost/sso/'
|
||||
# /yunohost/sso/?action=logout
|
||||
|
||||
# -----------------------------------------------------------------------------
|
||||
|
||||
|
||||
|
@ -103,9 +126,8 @@ else:
|
|||
STATIC_URL = '/static/'
|
||||
MEDIA_URL = '/media/'
|
||||
|
||||
STATIC_ROOT = str(FINALPATH / 'static')
|
||||
MEDIA_ROOT = str(FINALPATH / 'media')
|
||||
|
||||
STATIC_ROOT = str(PUBLIC_PATH / 'static')
|
||||
MEDIA_ROOT = str(PUBLIC_PATH / 'media')
|
||||
|
||||
# -----------------------------------------------------------------------------
|
||||
|
||||
|
|
|
@ -75,6 +75,9 @@ These projects used `django_example_ynh`:
|
|||
|
||||
# Developer info
|
||||
|
||||
The App project will be stored under `__FINALPATH__` (e.g.: `/opt/yunohost/$app`) that's Django's `settings.FINALPATH`
|
||||
"static" / "media" files to serve via nginx are under `__PUBLIC_PATH__` (e.g.: `/var/www/$app`) that's `settings.PUBLIC_PATH`
|
||||
|
||||
## package installation / debugging
|
||||
|
||||
This app is not in YunoHost app catalog. Test install, e.g.:
|
||||
|
|
|
@ -15,7 +15,8 @@ app=$YNH_APP_INSTANCE_NAME
|
|||
# SET CONSTANTS
|
||||
#=================================================
|
||||
|
||||
final_path=/var/www/$app
|
||||
public_path=/var/www/$app
|
||||
final_path=/opt/yunohost/$app
|
||||
log_path=/var/log/$app
|
||||
log_file="${log_path}/django_example_ynh.log"
|
||||
|
||||
|
|
|
@ -18,7 +18,7 @@ ynh_print_info --message="Loading installation settings..."
|
|||
|
||||
app=$YNH_APP_INSTANCE_NAME
|
||||
|
||||
final_path=$(ynh_app_setting_get --app="$app" --key=final_path)
|
||||
public_path=$(ynh_app_setting_get --app="$app" --key=public_path)
|
||||
final_path=$(ynh_app_setting_get --app="$app" --key=final_path)
|
||||
db_name=$(ynh_app_setting_get --app="$app" --key=db_name)
|
||||
|
||||
|
@ -34,7 +34,7 @@ ynh_print_info --message="Declaring files to be backed up..."
|
|||
#=================================================
|
||||
|
||||
ynh_backup --src_path="$final_path"
|
||||
ynh_backup --src_path="$final_path"
|
||||
ynh_backup --src_path="$public_path"
|
||||
|
||||
#=================================================
|
||||
# BACKUP THE NGINX CONFIGURATION
|
||||
|
|
|
@ -25,7 +25,7 @@ new_path=$YNH_APP_NEW_PATH
|
|||
ynh_script_progression --message="Loading installation settings..."
|
||||
|
||||
admin=$(ynh_app_setting_get --app="$app" --key=admin)
|
||||
final_path=$(ynh_app_setting_get --app="$app" --key=final_path)
|
||||
public_path=$(ynh_app_setting_get --app="$app" --key=public_path)
|
||||
final_path=$(ynh_app_setting_get --app="$app" --key=final_path)
|
||||
log_path=$(ynh_app_setting_get --app="$app" --key=log_path)
|
||||
|
||||
|
@ -94,7 +94,7 @@ then
|
|||
domain="$old_domain"
|
||||
path_url="$new_path"
|
||||
# Create a dedicated nginx config
|
||||
ynh_add_nginx_config "final_path" "port"
|
||||
ynh_add_nginx_config "public_path" "port"
|
||||
fi
|
||||
|
||||
# Change the domain for nginx
|
||||
|
@ -112,7 +112,7 @@ fi
|
|||
#=================================================
|
||||
# MODIFY SETTINGS
|
||||
#=================================================
|
||||
ynh_script_progression --message="Modify django_example_ynh's config file..."
|
||||
ynh_script_progression --message="Modify django-fmd's config file..."
|
||||
|
||||
ynh_add_config --template="settings.py" --destination="$final_path/settings.py"
|
||||
|
||||
|
|
|
@ -20,7 +20,7 @@ ynh_abort_if_errors
|
|||
ynh_script_progression --message="Validating installation parameters..."
|
||||
|
||||
# Path for e.g. "static" files, served by nginx:
|
||||
test ! -e "$final_path" || ynh_die --message="This path already contains a folder"
|
||||
test ! -e "$public_path" || ynh_die --message="This path already contains a folder"
|
||||
|
||||
# Path for own config files, e.g.: Django's settings.py:
|
||||
test ! -e "$final_path" || ynh_die --message="This path already contains a folder"
|
||||
|
@ -28,7 +28,7 @@ test ! -e "$final_path" || ynh_die --message="This path already contains a folde
|
|||
# Register (book) web path
|
||||
ynh_webpath_register --app="$app" --domain="$domain" --path_url="$path_url"
|
||||
|
||||
mkdir -p "$final_path/media" "$final_path/static"
|
||||
mkdir -p "$public_path/media" "$public_path/static"
|
||||
mkdir -p "$final_path"
|
||||
|
||||
mkdir -p "$log_path"
|
||||
|
@ -40,7 +40,7 @@ touch "${log_file}"
|
|||
ynh_script_progression --message="Storing installation settings..."
|
||||
|
||||
ynh_app_setting_set --app="$app" --key=admin --value="$admin"
|
||||
ynh_app_setting_set --app="$app" --key=final_path --value="$final_path"
|
||||
ynh_app_setting_set --app="$app" --key=public_path --value="$public_path"
|
||||
ynh_app_setting_set --app="$app" --key=final_path --value="$final_path"
|
||||
ynh_app_setting_set --app="$app" --key=log_path --value="$log_file"
|
||||
|
||||
|
@ -92,7 +92,7 @@ ynh_script_progression --message="Configuring nginx web server..."
|
|||
|
||||
# Create a dedicated nginx config
|
||||
# https://github.com/YunoHost/yunohost/blob/dev/data/helpers.d/nginx
|
||||
ynh_add_nginx_config "final_path" "port"
|
||||
ynh_add_nginx_config "public_path" "port"
|
||||
|
||||
#=================================================
|
||||
# CREATE DEDICATED USER
|
||||
|
@ -186,11 +186,11 @@ yunohost service add $app --description="Web based management to catalog things"
|
|||
|
||||
# Set permissions to app files
|
||||
chown -R "$app:" "$log_path"
|
||||
chown -R "$app:www-data" "$final_path"
|
||||
chown -R "$app:www-data" "$public_path"
|
||||
chown -R "$app:" "$final_path"
|
||||
|
||||
chmod o-rwx "$log_path"
|
||||
chmod o-rwx "$final_path"
|
||||
chmod o-rwx "$public_path"
|
||||
chmod o-rwx "$final_path"
|
||||
|
||||
#=================================================
|
||||
|
|
|
@ -17,7 +17,7 @@ ynh_script_progression --message="Loading installation settings..."
|
|||
domain=$(ynh_app_setting_get --app="$app" --key=domain)
|
||||
db_name=$(ynh_app_setting_get --app="$app" --key=db_name)
|
||||
db_user=$db_name
|
||||
final_path=$(ynh_app_setting_get --app="$app" --key=final_path)
|
||||
public_path=$(ynh_app_setting_get --app="$app" --key=public_path)
|
||||
final_path=$(ynh_app_setting_get --app="$app" --key=final_path)
|
||||
|
||||
#=================================================
|
||||
|
@ -68,7 +68,7 @@ ynh_exec_warn_less ynh_remove_app_dependencies
|
|||
ynh_script_progression --message="Removing app main directory..."
|
||||
|
||||
# Remove the app directory securely
|
||||
ynh_secure_remove --file="$final_path"
|
||||
ynh_secure_remove --file="$public_path"
|
||||
ynh_secure_remove --file="$final_path"
|
||||
|
||||
#=================================================
|
||||
|
|
|
@ -21,7 +21,7 @@ ynh_abort_if_errors
|
|||
ynh_script_progression --message="Loading settings..."
|
||||
|
||||
final_path=$(ynh_app_setting_get --app="$app" --key=final_path)
|
||||
final_path=$(ynh_app_setting_get --app="$app" --key=final_path)
|
||||
public_path=$(ynh_app_setting_get --app="$app" --key=public_path)
|
||||
db_name=$(ynh_app_setting_get --app="$app" --key=db_name)
|
||||
db_user=$db_name
|
||||
db_pwd=$(ynh_app_setting_get --app="$app" --key=psqlpwd)
|
||||
|
@ -51,9 +51,7 @@ ynh_restore_file --origin_path="/etc/nginx/conf.d/$domain.d/$app.conf"
|
|||
ynh_script_progression --message="Restoring the app main directory..."
|
||||
|
||||
ynh_restore_file --origin_path="$final_path"
|
||||
ynh_restore_file --origin_path="$final_path"
|
||||
|
||||
touch "$final_path/local_settings.py"
|
||||
ynh_restore_file --origin_path="$public_path"
|
||||
|
||||
#=================================================
|
||||
# RECREATE THE DEDICATED USER
|
||||
|
@ -68,7 +66,7 @@ ynh_system_user_create --username=$app --home_dir="$final_path" --use_shell
|
|||
#=================================================
|
||||
|
||||
# Restore permissions on app files
|
||||
chown -R "$app:www-data" "$final_path"
|
||||
chown -R "$app:www-data" "$public_path"
|
||||
chown -R "$app:" "$final_path"
|
||||
|
||||
#=================================================
|
||||
|
@ -144,11 +142,11 @@ ynh_restore_file --origin_path="/etc/logrotate.d/$app"
|
|||
|
||||
# Set permissions to app files
|
||||
chown -R "$app:" "$log_path"
|
||||
chown -R "$app:www-data" "$final_path"
|
||||
chown -R "$app:www-data" "$public_path"
|
||||
chown -R "$app:" "$final_path"
|
||||
|
||||
chmod o-rwx "$log_path"
|
||||
chmod o-rwx "$final_path"
|
||||
chmod o-rwx "$public_path"
|
||||
chmod o-rwx "$final_path"
|
||||
|
||||
#=================================================
|
||||
|
|
|
@ -13,7 +13,7 @@ source /usr/share/yunohost/helpers
|
|||
ynh_script_progression --message="Loading installation settings..."
|
||||
|
||||
admin=$(ynh_app_setting_get --app="$app" --key=admin)
|
||||
final_path=$(ynh_app_setting_get --app="$app" --key=final_path)
|
||||
public_path=$(ynh_app_setting_get --app="$app" --key=public_path)
|
||||
final_path=$(ynh_app_setting_get --app="$app" --key=final_path)
|
||||
log_path=$(ynh_app_setting_get --app="$app" --key=log_path)
|
||||
|
||||
|
@ -68,7 +68,7 @@ ynh_script_progression --message="Upgrading nginx web server configuration..."
|
|||
|
||||
# Create a dedicated nginx config
|
||||
# https://github.com/YunoHost/yunohost/blob/dev/data/helpers.d/nginx
|
||||
ynh_add_nginx_config "final_path" "port"
|
||||
ynh_add_nginx_config "public_path" "port"
|
||||
|
||||
#=================================================
|
||||
# SPECIFIC UPGRADE
|
||||
|
@ -178,11 +178,11 @@ yunohost service add $app --description="Web based management to catalog things"
|
|||
|
||||
# Set permissions to app files
|
||||
chown -R "$app:" "$log_path"
|
||||
chown -R "$app:www-data" "$final_path"
|
||||
chown -R "$app:www-data" "$public_path"
|
||||
chown -R "$app:" "$final_path"
|
||||
|
||||
chmod o-rwx "$log_path"
|
||||
chmod o-rwx "$final_path"
|
||||
chmod o-rwx "$public_path"
|
||||
chmod o-rwx "$final_path"
|
||||
|
||||
#=================================================
|
||||
|
|
|
@ -21,9 +21,8 @@ class DjangoYnhTestCase(HtmlAssertionMixin, TestCase):
|
|||
def test_settings(self):
|
||||
assert settings.PATH_URL == 'app_path'
|
||||
|
||||
# TODO: Switch to: assert str(settings.FINALPATH).endswith('/local_test/var_www')
|
||||
assert str(settings.FINALPATH).endswith('/local_test/opt_yunohost')
|
||||
|
||||
assert str(settings.PUBLIC_PATH).endswith('/local_test/var_www')
|
||||
assert str(settings.LOG_FILE).endswith('/local_test/var_log_django_example_ynh.log')
|
||||
|
||||
assert settings.ROOT_URLCONF == 'urls'
|
||||
|
|
Loading…
Add table
Reference in a new issue