mirror of
https://github.com/YunoHost-Apps/django_example_ynh.git
synced 2024-09-03 18:26:21 +02:00
__FINAL_HOME_PATH__ and __FINAL_WWW_PATH__ -> __FINALPATH__
This commit is contained in:
parent
796b822b6c
commit
3b4984871a
13 changed files with 64 additions and 43 deletions
|
@ -17,4 +17,4 @@ accesslog = '__LOG_FILE__'
|
||||||
errorlog = '__LOG_FILE__'
|
errorlog = '__LOG_FILE__'
|
||||||
|
|
||||||
# https://docs.gunicorn.org/en/latest/settings.html#pidfile
|
# https://docs.gunicorn.org/en/latest/settings.html#pidfile
|
||||||
pidfile = '__FINAL_HOME_PATH__/gunicorn.pid'
|
pidfile = '__FINALPATH__/gunicorn.pid'
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
#!__FINAL_HOME_PATH__/venv/bin/python
|
#!__FINALPATH__/venv/bin/python
|
||||||
|
|
||||||
import os
|
import os
|
||||||
import sys
|
import sys
|
||||||
|
|
|
@ -2,7 +2,7 @@
|
||||||
################################################################################
|
################################################################################
|
||||||
|
|
||||||
# Please do not modify this file, it will be reset at the next update.
|
# Please do not modify this file, it will be reset at the next update.
|
||||||
# You can edit the file __FINAL_HOME_PATH__/local_settings.py and add/modify the settings you need.
|
# You can edit the file __FINALPATH__/local_settings.py and add/modify the settings you need.
|
||||||
# The parameters you add in local_settings.py will overwrite these,
|
# The parameters you add in local_settings.py will overwrite these,
|
||||||
# but you can use the options and documentation in this file to find out what can be done.
|
# but you can use the options and documentation in this file to find out what can be done.
|
||||||
|
|
||||||
|
@ -19,11 +19,8 @@ DEBUG = False # Don't turn DEBUG on in production!
|
||||||
|
|
||||||
# -----------------------------------------------------------------------------
|
# -----------------------------------------------------------------------------
|
||||||
|
|
||||||
FINAL_HOME_PATH = __Path('__FINAL_HOME_PATH__') # /opt/yunohost/$app
|
FINALPATH = __Path('__FINALPATH__') # /var/www/$app
|
||||||
assert FINAL_HOME_PATH.is_dir(), f'Directory not exists: {FINAL_HOME_PATH}'
|
assert FINALPATH.is_dir(), f'Directory not exists: {FINALPATH}'
|
||||||
|
|
||||||
FINAL_WWW_PATH = __Path('__FINAL_WWW_PATH__') # /var/www/$app
|
|
||||||
assert FINAL_WWW_PATH.is_dir(), f'Directory not exists: {FINAL_WWW_PATH}'
|
|
||||||
|
|
||||||
LOG_FILE = __Path('__LOG_FILE__') # /var/log/$app/django_example_ynh.log
|
LOG_FILE = __Path('__LOG_FILE__') # /var/log/$app/django_example_ynh.log
|
||||||
assert LOG_FILE.is_file(), f'File not exists: {LOG_FILE}'
|
assert LOG_FILE.is_file(), f'File not exists: {LOG_FILE}'
|
||||||
|
@ -36,7 +33,7 @@ PATH_URL = PATH_URL.strip('/')
|
||||||
# Function that will be called to finalize a user profile:
|
# Function that will be called to finalize a user profile:
|
||||||
YNH_SETUP_USER = 'setup_user.setup_project_user'
|
YNH_SETUP_USER = 'setup_user.setup_project_user'
|
||||||
|
|
||||||
SECRET_KEY = __get_or_create_secret(FINAL_HOME_PATH / 'secret.txt') # /opt/yunohost/$app/secret.txt
|
SECRET_KEY = __get_or_create_secret(FINALPATH / 'secret.txt') # /opt/yunohost/$app/secret.txt
|
||||||
|
|
||||||
# INSTALLED_APPS.append('<insert-your-app-here>')
|
# INSTALLED_APPS.append('<insert-your-app-here>')
|
||||||
|
|
||||||
|
@ -106,8 +103,8 @@ else:
|
||||||
STATIC_URL = '/static/'
|
STATIC_URL = '/static/'
|
||||||
MEDIA_URL = '/media/'
|
MEDIA_URL = '/media/'
|
||||||
|
|
||||||
STATIC_ROOT = str(FINAL_WWW_PATH / 'static')
|
STATIC_ROOT = str(FINALPATH / 'static')
|
||||||
MEDIA_ROOT = str(FINAL_WWW_PATH / 'media')
|
MEDIA_ROOT = str(FINALPATH / 'media')
|
||||||
|
|
||||||
|
|
||||||
# -----------------------------------------------------------------------------
|
# -----------------------------------------------------------------------------
|
||||||
|
|
32
conf/urls.py
32
conf/urls.py
|
@ -1,12 +1,36 @@
|
||||||
|
"""
|
||||||
|
urls.py
|
||||||
|
~~~~~~~
|
||||||
|
|
||||||
|
Note: This is not a good example how your urls.py can look like.
|
||||||
|
Because this setup is just an example without a real Python application.
|
||||||
|
|
||||||
|
Look at real examples, here:
|
||||||
|
|
||||||
|
* https://github.com/YunoHost-Apps/django-fritzconnection_ynh/blob/master/conf/urls.py
|
||||||
|
* https://github.com/YunoHost-Apps/django-for-runners_ynh/blob/testing/conf/urls.py
|
||||||
|
* https://github.com/YunoHost-Apps/pyinventory_ynh/blob/testing/conf/urls.py
|
||||||
|
|
||||||
|
"""
|
||||||
|
|
||||||
|
|
||||||
from django.conf import settings
|
from django.conf import settings
|
||||||
from django.contrib import admin
|
from django.contrib import admin
|
||||||
from django.urls import path
|
from django.urls import path
|
||||||
|
|
||||||
from django_yunohost_integration.views import request_media_debug_view
|
from django_yunohost_integration.views import request_media_debug_view
|
||||||
|
|
||||||
|
|
||||||
# settings.PATH_URL is the $YNH_APP_ARG_PATH
|
if settings.PATH_URL:
|
||||||
# Prefix all urls with "PATH_URL":
|
# settings.PATH_URL is the $YNH_APP_ARG_PATH
|
||||||
urlpatterns = [
|
# Prefix all urls with "PATH_URL":
|
||||||
|
urlpatterns = [
|
||||||
path(f'{settings.PATH_URL}/', admin.site.urls),
|
path(f'{settings.PATH_URL}/', admin.site.urls),
|
||||||
path(f'{settings.PATH_URL}/debug/', request_media_debug_view),
|
path(f'{settings.PATH_URL}/debug/', request_media_debug_view),
|
||||||
]
|
]
|
||||||
|
else:
|
||||||
|
# Installed to domain root, without a path prefix
|
||||||
|
urlpatterns = [
|
||||||
|
path('/', admin.site.urls),
|
||||||
|
path('/debug/', request_media_debug_view),
|
||||||
|
]
|
||||||
|
|
|
@ -55,7 +55,7 @@ line_length = 100
|
||||||
atomic=true
|
atomic=true
|
||||||
profile='black'
|
profile='black'
|
||||||
skip_glob=["*/htmlcov/*","*/migrations/*"]
|
skip_glob=["*/htmlcov/*","*/migrations/*"]
|
||||||
known_first_party=[]
|
known_first_party=['django_yunohost_integration']
|
||||||
line_length=100
|
line_length=100
|
||||||
lines_after_imports=2
|
lines_after_imports=2
|
||||||
|
|
||||||
|
|
|
@ -15,8 +15,7 @@ app=$YNH_APP_INSTANCE_NAME
|
||||||
# SET CONSTANTS
|
# SET CONSTANTS
|
||||||
#=================================================
|
#=================================================
|
||||||
|
|
||||||
public_path=/var/www/$app
|
final_path=/var/www/$app
|
||||||
final_path=/opt/yunohost/$app
|
|
||||||
log_path=/var/log/$app
|
log_path=/var/log/$app
|
||||||
log_file="${log_path}/django_example_ynh.log"
|
log_file="${log_path}/django_example_ynh.log"
|
||||||
|
|
||||||
|
|
|
@ -18,7 +18,7 @@ ynh_print_info --message="Loading installation settings..."
|
||||||
|
|
||||||
app=$YNH_APP_INSTANCE_NAME
|
app=$YNH_APP_INSTANCE_NAME
|
||||||
|
|
||||||
public_path=$(ynh_app_setting_get --app="$app" --key=public_path)
|
final_path=$(ynh_app_setting_get --app="$app" --key=final_path)
|
||||||
final_path=$(ynh_app_setting_get --app="$app" --key=final_path)
|
final_path=$(ynh_app_setting_get --app="$app" --key=final_path)
|
||||||
db_name=$(ynh_app_setting_get --app="$app" --key=db_name)
|
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"
|
ynh_backup --src_path="$final_path"
|
||||||
|
|
||||||
#=================================================
|
#=================================================
|
||||||
# BACKUP THE NGINX CONFIGURATION
|
# BACKUP THE NGINX CONFIGURATION
|
||||||
|
|
|
@ -25,7 +25,7 @@ new_path=$YNH_APP_NEW_PATH
|
||||||
ynh_script_progression --message="Loading installation settings..."
|
ynh_script_progression --message="Loading installation settings..."
|
||||||
|
|
||||||
admin=$(ynh_app_setting_get --app="$app" --key=admin)
|
admin=$(ynh_app_setting_get --app="$app" --key=admin)
|
||||||
public_path=$(ynh_app_setting_get --app="$app" --key=public_path)
|
final_path=$(ynh_app_setting_get --app="$app" --key=final_path)
|
||||||
final_path=$(ynh_app_setting_get --app="$app" --key=final_path)
|
final_path=$(ynh_app_setting_get --app="$app" --key=final_path)
|
||||||
log_path=$(ynh_app_setting_get --app="$app" --key=log_path)
|
log_path=$(ynh_app_setting_get --app="$app" --key=log_path)
|
||||||
|
|
||||||
|
@ -94,7 +94,7 @@ then
|
||||||
domain="$old_domain"
|
domain="$old_domain"
|
||||||
path_url="$new_path"
|
path_url="$new_path"
|
||||||
# Create a dedicated nginx config
|
# Create a dedicated nginx config
|
||||||
ynh_add_nginx_config "public_path" "port"
|
ynh_add_nginx_config "final_path" "port"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# Change the domain for nginx
|
# Change the domain for nginx
|
||||||
|
|
|
@ -20,7 +20,7 @@ ynh_abort_if_errors
|
||||||
ynh_script_progression --message="Validating installation parameters..."
|
ynh_script_progression --message="Validating installation parameters..."
|
||||||
|
|
||||||
# Path for e.g. "static" files, served by nginx:
|
# Path for e.g. "static" files, served by nginx:
|
||||||
test ! -e "$public_path" || ynh_die --message="This path already contains a folder"
|
test ! -e "$final_path" || ynh_die --message="This path already contains a folder"
|
||||||
|
|
||||||
# Path for own config files, e.g.: Django's settings.py:
|
# Path for own config files, e.g.: Django's settings.py:
|
||||||
test ! -e "$final_path" || ynh_die --message="This path already contains a folder"
|
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
|
# Register (book) web path
|
||||||
ynh_webpath_register --app="$app" --domain="$domain" --path_url="$path_url"
|
ynh_webpath_register --app="$app" --domain="$domain" --path_url="$path_url"
|
||||||
|
|
||||||
mkdir -p "$public_path/media" "$public_path/static"
|
mkdir -p "$final_path/media" "$final_path/static"
|
||||||
mkdir -p "$final_path"
|
mkdir -p "$final_path"
|
||||||
|
|
||||||
mkdir -p "$log_path"
|
mkdir -p "$log_path"
|
||||||
|
@ -40,7 +40,7 @@ touch "${log_file}"
|
||||||
ynh_script_progression --message="Storing installation settings..."
|
ynh_script_progression --message="Storing installation settings..."
|
||||||
|
|
||||||
ynh_app_setting_set --app="$app" --key=admin --value="$admin"
|
ynh_app_setting_set --app="$app" --key=admin --value="$admin"
|
||||||
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=final_path --value="$final_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"
|
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
|
# Create a dedicated nginx config
|
||||||
# https://github.com/YunoHost/yunohost/blob/dev/data/helpers.d/nginx
|
# https://github.com/YunoHost/yunohost/blob/dev/data/helpers.d/nginx
|
||||||
ynh_add_nginx_config "public_path" "port"
|
ynh_add_nginx_config "final_path" "port"
|
||||||
|
|
||||||
#=================================================
|
#=================================================
|
||||||
# CREATE DEDICATED USER
|
# CREATE DEDICATED USER
|
||||||
|
@ -186,11 +186,11 @@ yunohost service add $app --description="Web based management to catalog things"
|
||||||
|
|
||||||
# Set permissions to app files
|
# Set permissions to app files
|
||||||
chown -R "$app:" "$log_path"
|
chown -R "$app:" "$log_path"
|
||||||
chown -R "$app:www-data" "$public_path"
|
chown -R "$app:www-data" "$final_path"
|
||||||
chown -R "$app:" "$final_path"
|
chown -R "$app:" "$final_path"
|
||||||
|
|
||||||
chmod o-rwx "$log_path"
|
chmod o-rwx "$log_path"
|
||||||
chmod o-rwx "$public_path"
|
chmod o-rwx "$final_path"
|
||||||
chmod o-rwx "$final_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)
|
domain=$(ynh_app_setting_get --app="$app" --key=domain)
|
||||||
db_name=$(ynh_app_setting_get --app="$app" --key=db_name)
|
db_name=$(ynh_app_setting_get --app="$app" --key=db_name)
|
||||||
db_user=$db_name
|
db_user=$db_name
|
||||||
public_path=$(ynh_app_setting_get --app="$app" --key=public_path)
|
final_path=$(ynh_app_setting_get --app="$app" --key=final_path)
|
||||||
final_path=$(ynh_app_setting_get --app="$app" --key=final_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..."
|
ynh_script_progression --message="Removing app main directory..."
|
||||||
|
|
||||||
# Remove the app directory securely
|
# Remove the app directory securely
|
||||||
ynh_secure_remove --file="$public_path"
|
ynh_secure_remove --file="$final_path"
|
||||||
ynh_secure_remove --file="$final_path"
|
ynh_secure_remove --file="$final_path"
|
||||||
|
|
||||||
#=================================================
|
#=================================================
|
||||||
|
|
|
@ -20,7 +20,7 @@ ynh_abort_if_errors
|
||||||
#=================================================
|
#=================================================
|
||||||
ynh_script_progression --message="Loading settings..."
|
ynh_script_progression --message="Loading settings..."
|
||||||
|
|
||||||
public_path=$(ynh_app_setting_get --app="$app" --key=public_path)
|
final_path=$(ynh_app_setting_get --app="$app" --key=final_path)
|
||||||
final_path=$(ynh_app_setting_get --app="$app" --key=final_path)
|
final_path=$(ynh_app_setting_get --app="$app" --key=final_path)
|
||||||
db_name=$(ynh_app_setting_get --app="$app" --key=db_name)
|
db_name=$(ynh_app_setting_get --app="$app" --key=db_name)
|
||||||
db_user=$db_name
|
db_user=$db_name
|
||||||
|
@ -50,7 +50,7 @@ ynh_restore_file --origin_path="/etc/nginx/conf.d/$domain.d/$app.conf"
|
||||||
#=================================================
|
#=================================================
|
||||||
ynh_script_progression --message="Restoring the app main directory..."
|
ynh_script_progression --message="Restoring the app main directory..."
|
||||||
|
|
||||||
ynh_restore_file --origin_path="$public_path"
|
ynh_restore_file --origin_path="$final_path"
|
||||||
ynh_restore_file --origin_path="$final_path"
|
ynh_restore_file --origin_path="$final_path"
|
||||||
|
|
||||||
touch "$final_path/local_settings.py"
|
touch "$final_path/local_settings.py"
|
||||||
|
@ -68,7 +68,7 @@ ynh_system_user_create --username=$app --home_dir="$final_path" --use_shell
|
||||||
#=================================================
|
#=================================================
|
||||||
|
|
||||||
# Restore permissions on app files
|
# Restore permissions on app files
|
||||||
chown -R "$app:www-data" "$public_path"
|
chown -R "$app:www-data" "$final_path"
|
||||||
chown -R "$app:" "$final_path"
|
chown -R "$app:" "$final_path"
|
||||||
|
|
||||||
#=================================================
|
#=================================================
|
||||||
|
@ -144,11 +144,11 @@ ynh_restore_file --origin_path="/etc/logrotate.d/$app"
|
||||||
|
|
||||||
# Set permissions to app files
|
# Set permissions to app files
|
||||||
chown -R "$app:" "$log_path"
|
chown -R "$app:" "$log_path"
|
||||||
chown -R "$app:www-data" "$public_path"
|
chown -R "$app:www-data" "$final_path"
|
||||||
chown -R "$app:" "$final_path"
|
chown -R "$app:" "$final_path"
|
||||||
|
|
||||||
chmod o-rwx "$log_path"
|
chmod o-rwx "$log_path"
|
||||||
chmod o-rwx "$public_path"
|
chmod o-rwx "$final_path"
|
||||||
chmod o-rwx "$final_path"
|
chmod o-rwx "$final_path"
|
||||||
|
|
||||||
#=================================================
|
#=================================================
|
||||||
|
|
|
@ -13,7 +13,7 @@ source /usr/share/yunohost/helpers
|
||||||
ynh_script_progression --message="Loading installation settings..."
|
ynh_script_progression --message="Loading installation settings..."
|
||||||
|
|
||||||
admin=$(ynh_app_setting_get --app="$app" --key=admin)
|
admin=$(ynh_app_setting_get --app="$app" --key=admin)
|
||||||
public_path=$(ynh_app_setting_get --app="$app" --key=public_path)
|
final_path=$(ynh_app_setting_get --app="$app" --key=final_path)
|
||||||
final_path=$(ynh_app_setting_get --app="$app" --key=final_path)
|
final_path=$(ynh_app_setting_get --app="$app" --key=final_path)
|
||||||
log_path=$(ynh_app_setting_get --app="$app" --key=log_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
|
# Create a dedicated nginx config
|
||||||
# https://github.com/YunoHost/yunohost/blob/dev/data/helpers.d/nginx
|
# https://github.com/YunoHost/yunohost/blob/dev/data/helpers.d/nginx
|
||||||
ynh_add_nginx_config "public_path" "port"
|
ynh_add_nginx_config "final_path" "port"
|
||||||
|
|
||||||
#=================================================
|
#=================================================
|
||||||
# SPECIFIC UPGRADE
|
# SPECIFIC UPGRADE
|
||||||
|
@ -178,11 +178,11 @@ yunohost service add $app --description="Web based management to catalog things"
|
||||||
|
|
||||||
# Set permissions to app files
|
# Set permissions to app files
|
||||||
chown -R "$app:" "$log_path"
|
chown -R "$app:" "$log_path"
|
||||||
chown -R "$app:www-data" "$public_path"
|
chown -R "$app:www-data" "$final_path"
|
||||||
chown -R "$app:" "$final_path"
|
chown -R "$app:" "$final_path"
|
||||||
|
|
||||||
chmod o-rwx "$log_path"
|
chmod o-rwx "$log_path"
|
||||||
chmod o-rwx "$public_path"
|
chmod o-rwx "$final_path"
|
||||||
chmod o-rwx "$final_path"
|
chmod o-rwx "$final_path"
|
||||||
|
|
||||||
#=================================================
|
#=================================================
|
||||||
|
|
|
@ -20,8 +20,9 @@ class DjangoYnhTestCase(HtmlAssertionMixin, TestCase):
|
||||||
def test_settings(self):
|
def test_settings(self):
|
||||||
assert settings.PATH_URL == 'app_path'
|
assert settings.PATH_URL == 'app_path'
|
||||||
|
|
||||||
assert str(settings.FINAL_HOME_PATH).endswith('/local_test/opt_yunohost')
|
# TODO: Switch to: assert str(settings.FINALPATH).endswith('/local_test/var_www')
|
||||||
assert str(settings.FINAL_WWW_PATH).endswith('/local_test/var_www')
|
assert str(settings.FINALPATH).endswith('/local_test/opt_yunohost')
|
||||||
|
|
||||||
assert str(settings.LOG_FILE).endswith('/local_test/var_log_django_example_ynh.log')
|
assert str(settings.LOG_FILE).endswith('/local_test/var_log_django_example_ynh.log')
|
||||||
|
|
||||||
assert settings.ROOT_URLCONF == 'urls'
|
assert settings.ROOT_URLCONF == 'urls'
|
||||||
|
|
Loading…
Add table
Reference in a new issue