1
0
Fork 0
mirror of https://github.com/YunoHost-Apps/streams_ynh.git synced 2024-09-03 20:26:20 +02:00

Merge pull request #26 from YunoHost-Apps/testing

Switch from archive based install to git clone based install
This commit is contained in:
Papa Dragon 2023-11-15 17:20:25 +01:00 committed by GitHub
commit ba3d7df8ab
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
16 changed files with 177 additions and 42 deletions

View file

@ -21,7 +21,7 @@ The [streams repository](https://codeberg.org/streams/streams/) lets you install
Your websites will be compatible with **Mastodon**, **Pleroma**, **Pixelfed**, **Friendica**, **Hubzilla**, **Funkwhale**, **Peertube**, **Plume**, **WriteFreely** and many, many more.
**Shipped version:** 23.11.11~ynh1
**Shipped version:** 23.11.14~ynh1
## Screenshots

View file

@ -21,7 +21,7 @@ Le [dépôt streams](https://codeberg.org/streams/streams/) vous permet d'instal
Vos sites web seront compatibles avec **Mastodon**, **Pleroma**, **Pixelfed**, **Friendica**, **Hubzilla**, **Funkwhale**, **Peertube**, **Plume**, **WriteFreely** et bien d'autres encore.
**Version incluse :** 23.11.11~ynh1
**Version incluse :** 23.11.14~ynh1
## Captures décran

View file

@ -1,2 +1,4 @@
# Run poller periodically to update your website
*/10 * * * * __APP__ /usr/bin/php__PHPVERSION__ -f Code/Daemon/Run.php Cron > /dev/null 2>&1
# Daily software update job
30 05 * * * root /bin/bash __DATA_DIR__/daily-update.sh >> __DATA_DIR__/daily-updates.log 2>&1

17
conf/daily-update.sh Normal file
View file

@ -0,0 +1,17 @@
#!/bin/sh
#
echo " "
echo "+++ $(date) +++"
echo " "
git_branch="$(cd /var/www/__APP__ && sudo -u __APP__ \
git branch --show-current)" 2> /dev/null
if echo $git_branch | grep -q "release"
then
echo "$(date) - Updating website..."
(cd /var/www/__APP__ ; sudo -u __APP__ util/udall)
else
echo "$(date) - Updating release branch code..."
(cd /var/www/__APP__ ; sudo -u __APP__ git fetch origin release:release)
fi
echo "$(date) - Daily update finished."

View file

@ -34,3 +34,15 @@ name.fr = "Configuration de Streams"
default = "medium"
help.en = "<strong>low</strong>: Personal usage, behind the SSO. No RAM footprint when not used, but the impact on the processor can be high if many users are using the service.<br><strong>medium</strong>: Low usage, few people or/and publicly accessible. Low RAM footprint, medium processor footprint when used.<br><strong>high</strong>: High usage, frequently visited website. High RAM footprint, but lower on processor usage and quickly responding."
help.fr = "<strong>low</strong> : Utilisation personnelle, derrière le SSO. Pas d'empreinte RAM en cas de non-utilisation, mais l'impact sur le processeur peut être élevé si de nombreux utilisateurs utilisent le service.<br><strong>medium</strong> : Faible utilisation, peu d'utilisateurs et/ou service pas nécessairement accessible au public. Faible empreinte RAM, empreinte moyenne sur le processeur en cas d'utilisation.<br><strong>high</strong> : Utilisation soutenue, site web fréquemment visité. L'empreinte RAM est élevée, mais l'utilisation du processeur est moindre et le service répond rapidement."
[main.git_branch_mode]
name.en = "Developer Mode"
name.fr = "Mode Développeur"
[main.git_branch_mode.git_branch_mode]
ask.en = "Switch to 'dev' branch"
ask.fr = "Basculer sur la branche 'dev'"
type = "boolean"
default = "0"
help.en = "<strong>This option should only be used if you're either a professional software developer or a certified lunatic (or both).</strong><br><br>You can only return to the 'release' branch if it is ahead of the 'dev' branch.<br><br>If authorised, the switch to the 'release' branch will be immediately followed by a global update of the site - via the util/udall command.<br><br>You must be able to use the command line to solve any problems you may encounter after using this option.<br><br>If you haven't understood any of the above lines <strong>DON'T USE THIS OPTION!!!</strong>"
help.fr = "<strong>Cette option ne devrait être utilisée que si vous êtes un développeur de logiciels professionnel ou une personne passablement déraisonnable (ou les deux à la fois)</strong><br><br>Vous ne pourrez revenir à la branche 'release' que si celle-ci est en avance sur la branche 'dev'.<br><br>Si elle est autorisée, la bascule vers la branche 'release' sera immédiatement suivie d'une mise à jour globale du site - via la commande util/udall.<br><br>Vous devez impérativement être capable d'utiliser la ligne de commande pour résoudre tout problème que vous pourriez rencontrer après avoir utilisé cette option.<br><br>Si vous n'avez rien compris aux lignes ci-dessus <strong>N'UTILISEZ PAS CETTE OPTION!!!</strong>"

View file

@ -11,3 +11,11 @@
- **For logs**: Go to **admin->logs** and enter the file name **php.log**.
- **Failed Database after Upgrade**: If the database upgrade fails after version upgrade, you can visit the dedicated page, `https://mywebsite.domain.tld/admin/dbsync/`, and check the numbers of failed updates. These updates will have to be ran manually using software such as **phpMyAdmin**.
### Git branches and code updates
- **Developer Mode**: the default git branch used is 'release', which should be considered as the stable version of the software. You can, **at your own risk**, switch to the 'dev' branch. You can do this in the config panel of your app in YunoHost admin interface. You can also do it through a SSH connection by using the `git checkout dev` command in the installation directory. **In the config panel you can only switch back to 'release' branch if it is ahead of the 'dev' branch**. You can do it anytime through SSH simply use the `git checkout release` command.
- **Automatic updates**: your website code will be updated automatically every day at 5:30. The updates log `daily-updates.log` is available in the directory /home/yunohost.app/streams (or /home/yunohost.app/streams__X, in the case of multiple installations, 'X' being the number corresponding to the relevant installation). The full website automatic update will be performed if the current branch is 'release' (if not, only `git fetch` will be performed for 'release'), and also immediately after switching back to 'release' in the config panel.
- **Manual updates**: in any branch you can run a manual update at any moment using the command `sudo -u streams util/udall` in the installation directory (or `sudo -u streams__X util/udall` in the case of multiple installations). If you want to keep a record of your manual update in `daily-updates.log`, you can run `bash daily-update.sh >> daily-updates.log` in the /home/yunohost.app/streams directory (or /home/yunohost.app/streams__X).

View file

@ -11,3 +11,11 @@
- **Pour les logs** : Allez dans **admin->logs** et saisissez le nom du fichier **php.log**.
- **Échec de la base de données après la mise à niveau** : Parfois, la mise à niveau de la base de données échoue après la mise à niveau de la version. Allez sur la page dédiée de votre site, `https://monsite.domaine.tld/admin/dbsync/`, et vérifiez les références de mises à jour défaillantes. Ces mises à jour devront être exécutées manuellement, sur **phpMyAdmin**.
### Branches git et mises à jour du code
- **Mode Développeur** : la branche utilisée par défaut est 'release', qui doit être considérée comme la version stable du logiciel. Vous pouvez, **à vos risques et périls**, basculer vers la branche de développement 'dev'. Vous pouvez le faire dans le panneau de configuration de votre application dans l'interface d'administration de YunoHost. Vous pouvez aussi le faire via une connexion SSH en utilisant la commande `git checkout dev` dans le répertoire d'installation. **Dans le panneau de configuration, vous ne pouvez revenir à la branche 'release' que si elle est en avance sur la branche 'dev'**. Vous pouvez le faire à tout moment via SSH en utilisant la commande `git checkout release`.
- **Mises à jour automatiques** : le code de votre site sera mis à jour automatiquement tous les jours à 5:30. Le journal des mises à jours `daily-updates.log` est disponible dans le répertoire /home/yunohost.app/streams (ou /home/yunohost.app/streams__X, en cas d'installations multiples, 'X' étant le nombre correspondant à l'installation concernée). La mise à jour automatique du site web complet sera effectuée si la branche courante est 'release' (sinon, seul `git fetch` sera effectué pour 'release'), et aussi immédiatement après le retour à 'release' par l'intermédiaire du panneau de configuration.
- **Mises à jour manuelles** : quelle que soit la branche courante vous pouvez lancer une mise à jour manuellement en utilisant la commande `sudo -u streams util/udall` dans le répertoire d'installation (ou `sudo -u streams__X util/udall` en cas d'installations multiples). Si vous souhaitez conserver la trace de votre mise à jour manuelle dans `daily-updates.log`, vous pouvez lancer la commande `bash daily-update.sh >> daily-updates.log` dans le répertoire /home/yunohost.app/streams (ou /home/yunohost.app/streams__X).

View file

@ -5,7 +5,7 @@ name = "Streams"
description.en = "Open source fediverse server"
description.fr = "Serveur fediverse open source"
version = "23.11.11~ynh1"
version = "23.11.14~ynh1"
maintainers = ["Papa Dragon"]
@ -37,14 +37,6 @@ ram.runtime = "50M"
type = "user"
[resources]
[resources.sources]
[resources.sources.main]
url = "https://codeberg.org/streams/streams/archive/8fb92b522b8bff562b350070b57954a998875e58.tar.gz"
sha256 = "b06cb71508cdb166002b41d08a9385bac2bfd9ddb3301116a8cdf9b3bc026275"
[resources.sources.addons]
url = "https://codeberg.org/streams/streams-addons/archive/39b1c5af9f2b1c639b6438ac85b0ea85273fc201.tar.gz"
sha256 = "5885665bf3dfbe843387184543be17b6b2061b807a57c1d6962548af80794f75"
[resources.ports]

View file

@ -7,6 +7,7 @@
#=================================================
YNH_COMPOSER_VERSION="2.5.8"
YNH_PHP_VERSION="8.2"
#=================================================
# PERSONAL HELPERS

View file

@ -49,10 +49,11 @@ ynh_backup --src_path="/etc/fail2ban/filter.d/$app.conf"
ynh_backup --src_path="/etc/logrotate.d/$app"
#=================================================
# BACKUP VARIOUS FILES
# BACKUP CRON JOBS
#=================================================
ynh_backup --src_path="/etc/cron.d/$app"
ynh_backup --src_path="/$data_dir"
#=================================================
# BACKUP THE DATABASE

View file

@ -15,13 +15,28 @@ ynh_abort_if_errors
# RETRIEVE ARGUMENTS
#=================================================
phpversion=$(ynh_app_setting_get --app=$app --key=phpversion)
phpversion="$YNH_PHP_VERSION"
current_fpm_footprint=$(ynh_app_setting_get --app=$app --key=fpm_footprint)
#=================================================
# SPECIFIC GETTERS FOR TOML SHORT KEY
#=================================================
get__git_branch_mode() {
# Git branch mode status
git_branch_mode_status="$(cd "$install_dir" && git branch --show-current)" 2> /dev/null
if echo $git_branch_mode_status | grep -q "release"
then
echo "0"
elif echo $git_branch_mode_status | grep -q "dev"
then
echo "1"
else
ynh_print_err --message="Not using \"release\" or \"dev\" branch, please handle this in command line"
exit 0
fi
}
get__fpm_footprint() {
# Free footprint value for php-fpm
# Check if current_fpm_footprint is an integer
@ -49,6 +64,30 @@ get__free_footprint() {
# SPECIFIC SETTERS FOR TOML SHORT KEYS
#=================================================
set__git_branch_mode() {
if [ "$git_branch_mode" -eq "0" ]
then
# We allow switch back to "release" only if the branch is ahead of "dev"
if [ -z "$(cd "$install_dir" && git log --oneline release..dev)" ]
then
# If git_branch was set to 0, switch to "release" branch
ynh_print_info "Switching to \"release\" branch"
(cd "$install_dir" && ynh_exec_as "$app" git checkout release)
ynh_print_info "Full update of the website"
(cd /home/yunohost.app/"$app" && bash daily-update.sh >> daily-updates.log 2>&1)
else
ynh_die --message="\"release\" branch is behind your local \"dev\" branch, rolling back is not allowed here"
exit 1
fi
elif [ "$git_branch_mode" -eq "1" ]; then
# If git_branch was set to 1, switch to "dev" branch
(cd "$install_dir" && ynh_exec_as "$app" git checkout dev)
ynh_print_info "Switching to \"dev\" branch"
fi
ynh_app_setting_set --app=$app --key=git_branch_mode --value="$git_branch_mode"
}
set__fpm_footprint() {
if [ "$fpm_footprint" != "specific" ]
then

View file

@ -45,16 +45,19 @@ ynh_mysql_connect_as --user=$db_user --password="$db_pwd" --database=$db_name \
#=================================================
ynh_script_progression --message="Setting up source files..." --weight=1
# Download, check integrity, uncompress and patch the source from app.src
ynh_setup_source --dest_dir="$install_dir"
ynh_setup_source --dest_dir="$install_dir/addon" --source_id="addons"
mkdir -p "$install_dir"
chown -R $app:www-data "$install_dir"
git config --system --add safe.directory $install_dir
# Download, check integrity, uncompress and patch the source from GitHub
git clone https://codeberg.org/streams/streams.git "$install_dir" --quiet
touch "$install_dir/php.log"
mkdir -p "$install_dir/store"
mkdir -p "$install_dir/cache/smarty3"
chmod -R o-rwx "$install_dir"
chown -R $app:www-data "$install_dir"
chmod -R 775 $install_dir/store $install_dir/cache
#=================================================
@ -73,7 +76,20 @@ ynh_add_nginx_config
#=================================================
ynh_script_progression --message="Pulling in external libraries with Composer..."
ynh_install_composer
ynh_install_composer --workdir="$install_dir"
chown -R $app:www-data "$install_dir"
#=================================================
# ADDONS
#=================================================
ynh_script_progression --message="Installing addons..."
pushd $install_dir
ynh_exec_as $app git config pull.rebase false
ynh_exec_as $app util/add_addon_repo https://codeberg.org/streams/streams-addons.git zaddons
cd /var/www/$app/extend/addon/zaddons
ynh_exec_as $app git config pull.rebase false
popd
#=================================================
# SPECIFIC SETUP
@ -91,24 +107,23 @@ ynh_script_progression --message="Adding a configuration file..." --weight=1
ynh_add_config --template="../conf/htconfig.sample.php" --destination="$install_dir/.htconfig.php"
# addon ldap config
#ynh_script_progression --message="Push LDAP configuration to .htconfig.php..."
#cat ../conf/ldap_conf.php >> $install_dir/.htconfig.php
ynh_store_file_checksum --file=$install_dir/.htconfig.php
chmod 600 "$install_dir/.htconfig.php"
chown $app:$app "$install_dir/.htconfig.php"
#=================================================
# SET CRON JOB
# SET CRON JOBS
#=================================================
ynh_script_progression --message="Setuping cron job..." --weight=1
# Set up cron job
ynh_add_config --template="../conf/poller-cron" --destination="/etc/cron.d/$app"
ynh_add_config --template="../conf/cronjobs" --destination="/etc/cron.d/$app"
chown root: "/etc/cron.d/$app"
chmod 644 "/etc/cron.d/$app"
# Add daily update script
ynh_add_config --template="../conf/daily-update.sh" --destination="/home/yunohost.app/$app/daily-update.sh"
chown root: "/home/yunohost.app/$app/daily-update.sh"
#=================================================
# GENERIC FINALIZATION

View file

@ -29,6 +29,9 @@ ynh_remove_fail2ban_config
# Remove a cron file
ynh_secure_remove --file="/etc/cron.d/$app"
# Remove daily updates logfile
ynh_secure_remove --file="$data_dir/daily-updates.log"
#=================================================
# END OF SCRIPT
#=================================================

View file

@ -38,12 +38,15 @@ ynh_restore_file --origin_path="/etc/fail2ban/jail.d/$app.conf"
ynh_restore_file --origin_path="/etc/fail2ban/filter.d/$app.conf"
ynh_systemd_action --action=restart --service_name=fail2ban
ynh_restore_file --origin_path="/etc/php/$phpversion/fpm/pool.d/$app.conf"
ynh_restore_file --origin_path="/etc/nginx/conf.d/$domain.d/$app.conf"
#=================================================
# RESTORE CRON JOBS
#=================================================
ynh_restore_file --origin_path="/etc/cron.d/$app"
ynh_restore_file --origin_path="$data_dir"
#=================================================
# RESTORE LOGROTATE
#=================================================
ynh_restore_file --origin_path="/etc/logrotate.d/$app"
#=================================================
@ -53,6 +56,10 @@ ynh_restore_file --origin_path="/etc/logrotate.d/$app"
#=================================================
ynh_script_progression --message="Reloading NGINX web server and PHP-FPM..." --weight=1
ynh_restore_file --origin_path="/etc/php/$phpversion/fpm/pool.d/$app.conf"
ynh_restore_file --origin_path="/etc/nginx/conf.d/$domain.d/$app.conf"
ynh_systemd_action --service_name=php$phpversion-fpm --action=reload
ynh_systemd_action --service_name=nginx --action=reload

View file

@ -55,17 +55,31 @@ if [ "$upgrade_type" == "UPGRADE_APP" ]
then
ynh_script_progression --message="Upgrading source files..." --weight=1
# Download, check integrity, uncompress and patch the source from app.src
ynh_setup_source --dest_dir="$install_dir" --keep="store/ .htconfig.php php.log"
ynh_setup_source --dest_dir="$install_dir/addon" --source_id="addons"
fi
# First we save what we need to keep
mv $install_dir/store $data_dir/
mv $install_dir/cache $data_dir/
mv $install_dir/php.log $data_dir/
mkdir -p "$install_dir/store"
mkdir -p "$install_dir/cache/smarty3"
# Then we remove the previous install
ynh_secure_remove $install_dir
# We make the install cloning the repo
mkdir -p "$install_dir"
chown -R $app:www-data "$install_dir"
git config --system --add safe.directory $install_dir
git clone https://codeberg.org/streams/streams.git "$install_dir" --quiet
# We restore what we previously saved
mv $data_dir/store $install_dir/
mv $data_dir/cache $install_dir/
mv $data_dir/php.log $install_dir/
chmod -R o-rwx "$install_dir"
chown -R $app:www-data "$install_dir"
chmod -R 775 $install_dir/store $install_dir/cache
fi
#=================================================
# PHP-FPM CONFIGURATION
@ -84,6 +98,19 @@ ynh_add_nginx_config
ynh_script_progression --message="Pulling in external libraries with Composer..."
ynh_install_composer
chown -R $app:www-data "$install_dir"
#=================================================
# ADDONS
#=================================================
ynh_script_progression --message="Installing addons..."
pushd $install_dir
ynh_exec_as $app git config pull.rebase false
ynh_exec_as $app util/add_addon_repo https://codeberg.org/streams/streams-addons.git zaddons
cd /var/www/$app/extend/addon/zaddons
ynh_exec_as $app git config pull.rebase false
popd
#=================================================
# SPECIFIC UPGRADE
@ -100,12 +127,15 @@ chown $app:$app "$install_dir/.htconfig.php"
#=================================================
# UPGRADE CRON JOB
#=================================================
ynh_script_progression --message="Upgrading cron job..." --weight=1
ynh_script_progression --message="Setuping cron job..." --weight=1
# Set up cron job
ynh_add_config --template="../conf/poller-cron" --destination="/etc/cron.d/$app"
ynh_add_config --template="../conf/cronjobs" --destination="/etc/cron.d/$app"
chown root: "/etc/cron.d/$app"
chmod 644 "/etc/cron.d/$app"
# Add daily update script
ynh_add_config --template="../conf/daily-update.sh" --destination="/home/yunohost.app/$app/daily-update.sh"
chown root: "/home/yunohost.app/$app/daily-update.sh"
#=================================================
# GENERIC FINALIZATION
@ -115,7 +145,7 @@ chmod 644 "/etc/cron.d/$app"
ynh_script_progression --message="Upgrading logrotate configuration..." --weight=1
# Use logrotate to manage app-specific logfile(s)
ynh_use_logrotate --non-append
ynh_use_logrotate "$install_dir/php.log"
# Create a dedicated Fail2Ban config
ynh_add_fail2ban_config --logpath="$install_dir/php.log" --failregex="^.*auth\.php.*failed login attempt.*from IP <HOST>.*$" --max_retry="5"

View file

@ -13,6 +13,6 @@ test_format = 1.0
# Default args to use for install
# -------------------------------
test_upgrade_from.8985f0af2e713f8fc514dcf4b42208d1329f2403.name = "Upgrade from 23.11.05~ynh2"
test_upgrade_from.5112b799be49c5768416ca8c23efd0afbba9cfb5.name = "Upgrade from 23.11.05~ynh3"
test_upgrade_from.d9393d31c20fca899e8e13650cb79f2c0846e81a.name = "Upgrade from 23.11.11~ynh1"