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

Merge pull request #192 from YunoHost-Apps/testing

This commit is contained in:
tituspijean 2022-10-17 22:21:36 +02:00 committed by GitHub
commit d31fd5519e
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
10 changed files with 301 additions and 145 deletions

126
.github/workflows/updater.py vendored Executable file
View file

@ -0,0 +1,126 @@
#!/usr/bin/env python3
"""
This script is meant to be run by GitHub Actions.
It comes with a Github Action updater.yml to run this script periodically.
Since each app is different, maintainers can adapt its contents to perform
automatic actions when a new upstream release is detected.
You need to enable the action by removing `if ${{ false }}` in updater.yml!
"""
import hashlib
import json
import logging
import os
import re
from subprocess import run, PIPE
import textwrap
from typing import List, Tuple, Any
import requests
from packaging import version
logging.getLogger().setLevel(logging.INFO)
# ========================================================================== #
# Functions customizable by app maintainer
def get_latest_version(repo: str) -> Tuple[version.Version, Any]:
"""
May be customized by maintainers for other forges than Github.
Returns a tuple: a comparable version, and some data that will
be passed to get_asset_urls_of_release().
"""
api_url = "https://api.wordpress.org/core/version-check/1.7/"
# Maintainer: use either releases or tags
tags = requests.get(f"{api_url}").json()
tag_info = next(
tag for tag in tags["offers"]
)
return version.Version(tag_info["version"]), tag_info
def generate_src_files(repo: str, release: Any):
"""
Should call write_src_file() for every asset/binary/... to download.
"""
built_release = release["packages"]["full"]
logging.info("Handling main tarball at %s", built_release)
write_src_file("app.src", built_release, "zip")
# ========================================================================== #
# Core generic code of the script, app maintainers should not edit this part
def sha256sum_of_url(url: str) -> str:
"""Compute checksum without saving the file"""
checksum = hashlib.sha256()
for chunk in requests.get(url, stream=True).iter_content(10*1024):
checksum.update(chunk)
return checksum.hexdigest()
def write_src_file(name: str, asset_url: str, extension: str,
extract: bool = True, subdir: bool = True) -> None:
"""Rewrite conf/app.src"""
logging.info("Writing %s...", name)
with open(f"conf/{name}", "w", encoding="utf-8") as conf_file:
conf_file.write(textwrap.dedent(f"""\
SOURCE_URL={asset_url}
SOURCE_SUM={sha256sum_of_url(asset_url)}
SOURCE_SUM_PRG=sha256sum
SOURCE_FORMAT={extension}
SOURCE_IN_SUBDIR={str(subdir).lower()}
SOURCE_EXTRACT={str(extract).lower()}
"""))
def write_github_env(proceed: bool, new_version: str, branch: str):
"""Those values will be used later in the workflow"""
if "GITHUB_ENV" not in os.environ:
logging.warning("GITHUB_ENV is not in the envvars, assuming not in CI")
return
with open(os.environ["GITHUB_ENV"], "w", encoding="utf-8") as github_env:
github_env.write(textwrap.dedent(f"""\
VERSION={new_version}
BRANCH={branch}
PROCEED={str(proceed).lower()}
"""))
def main():
with open("manifest.json", "r", encoding="utf-8") as manifest_file:
manifest = json.load(manifest_file)
repo = manifest["upstream"]["code"]
current_version = version.Version(manifest["version"].split("~")[0])
latest_version, release_info = get_latest_version(repo)
logging.info("Current version: %s", current_version)
logging.info("Latest upstream version: %s", latest_version)
# Proceed only if the retrieved version is greater than the current one
if latest_version <= current_version:
logging.warning("No new version available")
write_github_env(False, "", "")
return
# Proceed only if a PR for this new version does not already exist
branch = f"ci-auto-update-v${latest_version}"
command = ["git", "ls-remote", "--exit-code", "-h", repo, branch]
if run(command, stderr=PIPE, stdout=PIPE, check=False).returncode == 0:
logging.warning("A branch already exists for this update")
write_github_env(False, "", "")
return
generate_src_files(repo, release_info)
manifest["version"] = f"{latest_version}~ynh1"
with open("manifest.json", "w", encoding="utf-8") as manifest_file:
json.dump(manifest, manifest_file, indent=4, ensure_ascii=False)
manifest_file.write("\n")
write_github_env(True, latest_version, branch)
if __name__ == "__main__":
main()

38
.github/workflows/updater.yml vendored Normal file
View file

@ -0,0 +1,38 @@
# This workflow allows GitHub Actions to automagically update your app whenever a new upstream release is detected.
# You need to enable Actions in your repository settings, and fetch this Action from the YunoHost-Apps organization.
# This file should be enough by itself, but feel free to tune it to your needs.
# It calls updater.sh, which is where you should put the app-specific update steps.
name: Check for new upstream releases
on:
# Allow to manually trigger the workflow
workflow_dispatch:
# Run it every day at 8:00 UTC
schedule:
- cron: '0 8 * * *'
jobs:
updater:
runs-on: ubuntu-latest
steps:
- name: Fetch the source code
uses: actions/checkout@v2
with:
token: ${{ secrets.GITHUB_TOKEN }}
- name: Run the updater script
run: .github/workflows/updater.py
- name: Create Pull Request
if: ${{ env.PROCEED == 'true' }}
uses: peter-evans/create-pull-request@v3
with:
token: ${{ secrets.GITHUB_TOKEN }}
title: Upgrade ${{ env.APP_NAME }} to version ${{ env.VERSION }}
body: Upgrade ${{ env.APP_NAME }} to version ${{ env.VERSION }}
commit-message: Upgrade ${{ env.APP_NAME }} to version ${{ env.VERSION }}
committer: 'yunohost-bot <yunohost-bot@users.noreply.github.com>'
author: 'yunohost-bot <yunohost-bot@users.noreply.github.com>'
base: testing
branch: ${{ env.BRANCH }}
delete-branch: true

View file

@ -19,7 +19,7 @@ WordPress is open source software you can use to create a beautiful website, blo
With this package, you can even activate the [multisite](https://wordpress.org/support/article/glossary/#multisite) option.
**Shipped version:** 6.0.2~ynh1
**Shipped version:** 6.0.2~ynh2 *(:warning: This is the `testing` branch. The [`master` branch](https://github.com/YunoHost-Apps/wordpress_ynh/tree/master) used in the catalog is currently on version 6.0.2\~ynh1.)*
## Screenshots
@ -58,6 +58,12 @@ Don't forget to comply with good security principles (strong password, frequent
Furthermore, you might take a look at the [Hardening Wordpress Guide](https://wordpress.org/support/article/hardening-wordpress/). You might see some benefits in the use of Wordpress security plugins.
## :red_circle: Antifeatures
- **Non-free Addons**: Promotes other non-free applications or plugins.
- **Paid content**: Promotes or depends, entirely or partially, on a paid service.
## Documentation and resources
* Official app website: <https://wordpress.org/>

View file

@ -19,7 +19,7 @@ WordPress est un logiciel libre que vous pouvez utiliser pour créer un site ou
Avec ce package, vous pouvez même activer l'option [multisite](https://codex.wordpress.org/Glossary#Multisite).
**Version incluse :** 6.0.2~ynh1
**Version incluse :** 6.0.2~ynh2 *(:warning: Il s'agit de la branche `testing`. La [branche `master`](https://github.com/YunoHost-Apps/wordpress_ynh/tree/master) utilisée dans le catalogue est actuellement en 6.0.2\~ynh1.)*
## Captures d'écran
@ -58,6 +58,12 @@ N'oubliez pas d'appliquer les principes de sécurité de base (mots de passe for
Par ailleurs, vous pourriez avoir besoin de regarder [ce guide](https://wordpress.org/support/article/hardening-wordpress/). Installer des extensions de sécurité peut-être une bonne chose.
## :red_circle: Fonctions indésirables
- **Non-free Addons**: Promotes other non-free applications or plugins.
- **Paid content**: Promotes or depends, entirely or partially, on a paid service.
## Documentations et ressources
* Site officiel de l'app : <https://wordpress.org/>

View file

@ -1,9 +1,15 @@
version = "1.0"
name = "Wordpress configuration panel"
[main]
name = "Wordpress configuration"
name = "WordPress configuration"
[main.maintenance_mode]
name = "Maintenance mode"
[main.maintenance_mode.maintenance_mode]
ask = "Enable maintenance mode"
type = "boolean"
default = "0"
[main.overwrite_files]
name = "Overwriting config files"
@ -20,40 +26,37 @@ name = "Wordpress configuration"
default = true
help = "If the file is overwritten, a backup will be created."
[main.global_config]
name = "Global configuration"
[main.global_config.email_type]
[main.global_config.admin_mail_html]
ask = "Send HTML email to admin?"
type = "boolean"
default = true
help = "Allow app scripts to send HTML mails instead of plain text."
[main.php_fpm_config]
name = "PHP-FPM configuration"
[main.php_fpm_config.footprint]
ask = "Memory footprint of the service?"
choices = ["low", "medium", "high", "specific"]
[main.php_fpm_config.fpm_footprint]
ask = "Memory footprint"
type = "select"
choices.low = "Low, <= 20Mb per pool"
choices.medium = "Medium, between 20Mb and 40Mb per pool"
choices.high = "High, > 40Mb per pool"
choices.specific = "Use specific value"
default = "low"
help = "low <= 20Mb per pool. medium between 20Mb and 40Mb per pool. high > 40Mb per pool.<br>Use specific to set a value with the following option."
[main.php_fpm_config.free_footprint]
[main.php_fpm_config.fpm_free_footprint]
visible = "fpm_footprint == 'specific'"
ask = "Memory footprint of the service?"
type = "number"
default = "0"
help = "Free field to specify exactly the footprint in Mb if you don't want to use one of the three previous values."
[main.php_fpm_config.usage]
ask = "Expected usage of the service?"
[main.php_fpm_config.fpm_usage]
ask = "Expected usage"
type = "select"
choices = ["low", "medium", "high"]
default = "low"
help = "low: 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>medium: Low usage, few people or/and publicly accessible. Low RAM footprint, medium processor footprint when used.<br>high: High usage, frequently visited website. High RAM footprint, but lower on processor usage and quickly responding."
[main.php_fpm_config.force_max_children]
ask = "Force the value of pm.max_children?"
type = "number"
default = "0"
help = "Do not change this value unless you are sure about what you are doing!<br>pm.max_children is automatically defined by this formula: $max_ram / 2 / $footprint<br>You can force that value, and ignore the formula by changing the value here.<br>To reset to the default value, set to 0."

View file

@ -6,7 +6,7 @@
"en": "Create a beautiful blog or website easily",
"fr": "Logiciel de création de blog ou de site Web"
},
"version": "6.0.2~ynh1",
"version": "6.0.2~ynh2",
"url": "https://wordpress.org/",
"upstream": {
"license": "GPL-2.0",

View file

@ -9,149 +9,111 @@
source _common.sh
source /usr/share/yunohost/helpers
ynh_abort_if_errors
#=================================================
# RETRIEVE ARGUMENTS
#=================================================
app=$YNH_APP_INSTANCE_NAME
fpm_config_dir=$(ynh_app_setting_get --app=$app --key=fpm_config_dir)
final_path=$(ynh_app_setting_get --app=$app --key=final_path)
phpversion=$(ynh_app_setting_get --app=$app --key=phpversion)
current_fpm_footprint=$(ynh_app_setting_get --app=$app --key=fpm_footprint)
#=================================================
# LOAD VALUES
# SPECIFIC GETTERS FOR TOML SHORT KEY
#=================================================
# Load the real value from the app config or elsewhere.
# Then get the value from the form.
# If the form has a value for a variable, take the value from the form,
# Otherwise, keep the value from the app config.
get__maintenance_mode() {
# Maintenance mode status
if [ -f $final_path/.maintenance ]
then
echo "1"
else
echo "0"
fi
}
# Overwrite nginx configuration
old_overwrite_nginx="$(ynh_app_setting_get --app=$app --key=overwrite_nginx)"
overwrite_nginx="${YNH_CONFIG_MAIN_OVERWRITE_FILES_OVERWRITE_NGINX:-$old_overwrite_nginx}"
get__fpm_footprint() {
# Free footprint value for php-fpm
# Check if current_fpm_footprint is an integer
if [ "$current_fpm_footprint" -eq "$current_fpm_footprint" ] 2> /dev/null
then
echo "specific"
else
echo "$current_fpm_footprint"
fi
}
# Overwrite php-fpm configuration
old_overwrite_phpfpm="$(ynh_app_setting_get --app=$app --key=overwrite_phpfpm)"
overwrite_phpfpm="${YNH_CONFIG_MAIN_OVERWRITE_FILES_OVERWRITE_PHPFPM:-$old_overwrite_phpfpm}"
# Type of admin mail configuration
old_admin_mail_html="$(ynh_app_setting_get $app admin_mail_html)"
admin_mail_html="${YNH_CONFIG_MAIN_GLOBAL_CONFIG_EMAIL_TYPE:-$old_admin_mail_html}"
# Footprint for php-fpm
old_fpm_footprint="$(ynh_app_setting_get --app=$app --key=fpm_footprint)"
fpm_footprint="${YNH_CONFIG_MAIN_PHP_FPM_CONFIG_FOOTPRINT:-$old_fpm_footprint}"
# Free footprint value for php-fpm
# Check if fpm_footprint is an integer
if [ "$fpm_footprint" -eq "$fpm_footprint" ] 2> /dev/null
then
# If fpm_footprint is an integer, that's a numeric value for the footprint
old_free_footprint=$fpm_footprint
fpm_footprint=specific
else
old_free_footprint=0
fi
free_footprint="${YNH_CONFIG_MAIN_PHP_FPM_CONFIG_FREE_FOOTPRINT:-$old_free_footprint}"
# Usage for php-fpm
old_fpm_usage="$(ynh_app_setting_get --app=$app --key=fpm_usage)"
fpm_usage="${YNH_CONFIG_MAIN_PHP_FPM_CONFIG_USAGE:-$old_fpm_usage}"
# php_forced_max_children for php-fpm
old_php_forced_max_children="$(ynh_app_setting_get --app=$app --key=php_forced_max_children)"
# If php_forced_max_children isn't into settings.yml, get the current value from the fpm config
if [ -z "$old_php_forced_max_children" ]; then
old_php_forced_max_children="$(grep "^pm.max_children" "$fpm_config_dir/pool.d/$app.conf" | awk '{print $3}')"
fi
php_forced_max_children="${YNH_CONFIG_MAIN_PHP_FPM_CONFIG_FORCE_MAX_CHILDREN:-$old_php_forced_max_children}"
#=================================================
# SHOW_CONFIG FUNCTION FOR 'SHOW' COMMAND
#=================================================
show_config() {
# here you are supposed to read some config file/database/other then print the values
# ynh_return "YNH_CONFIG_${PANEL_ID}_${SECTION_ID}_${OPTION_ID}=value"
ynh_return "YNH_CONFIG_MAIN_OVERWRITE_FILES_OVERWRITE_NGINX=$overwrite_nginx"
ynh_return "YNH_CONFIG_MAIN_OVERWRITE_FILES_OVERWRITE_PHPFPM=$overwrite_phpfpm"
ynh_return "YNH_CONFIG_MAIN_GLOBAL_CONFIG_EMAIL_TYPE=$admin_mail_html"
ynh_return "YNH_CONFIG_MAIN_PHP_FPM_CONFIG_FOOTPRINT=$fpm_footprint"
ynh_return "YNH_CONFIG_MAIN_PHP_FPM_CONFIG_FREE_FOOTPRINT=$free_footprint"
ynh_return "YNH_CONFIG_MAIN_PHP_FPM_CONFIG_USAGE=$fpm_usage"
ynh_return "YNH_CONFIG_MAIN_PHP_FPM_CONFIG_FORCE_MAX_CHILDREN=$php_forced_max_children"
get__free_footprint() {
# Free footprint value for php-fpm
# Check if current_fpm_footprint is an integer
if [ "$current_fpm_footprint" -eq "$current_fpm_footprint" ] 2> /dev/null
then
# If current_fpm_footprint is an integer, that's a numeric value for the footprint
echo "$current_fpm_footprint"
else
echo "0"
fi
}
#=================================================
# MODIFY THE CONFIGURATION
# SPECIFIC SETTERS FOR TOML SHORT KEYS
#=================================================
apply_config() {
set__maintenance_mode() {
if [ "$maintenance_mode" -eq "1" ]; then
# If maintenance_mode was set to 1, enable maintenance mode
(cd "$final_path" && ynh_exec_as "$app" \
echo "Site under maintenance." > .maintenance)
ynh_print_info "Maintenance mode disabled"
elif [ "$maintenance_mode" -eq "0" ]; then
# If maintenance_mode was set to 0, disable maintenance mode
ynh_secure_remove --file=$final_path/.maintenance
ynh_print_info "Maintenance mode enabled"
fi
ynh_app_setting_set --app=$app --key=maintenance_mode --value="$maintenance_mode"
}
#=================================================
# MODIFY OVERWRITTING SETTINGS
#=================================================
# Set overwrite_nginx
ynh_app_setting_set --app=$app --key=overwrite_nginx --value="$overwrite_nginx"
# Set overwrite_phpfpm
ynh_app_setting_set --app=$app --key=overwrite_phpfpm --value="$overwrite_phpfpm"
#=================================================
# MODIFY EMAIL SETTING
#=================================================
# Set admin_mail_html
ynh_app_setting_set --app=$app --key=admin_mail_html --value="$admin_mail_html"
#=================================================
# RECONFIGURE PHP-FPM
#=================================================
if [ "$fpm_usage" != "$old_fpm_usage" ] || \
[ "$fpm_footprint" != "$old_fpm_footprint" ] || \
[ "$free_footprint" != "$old_free_footprint" ] || \
[ "$php_forced_max_children" != "$old_php_forced_max_children" ]
set__fpm_footprint() {
if [ "$fpm_footprint" != "specific" ]
then
# If fpm_footprint is set to 'specific', use $free_footprint value.
if [ "$fpm_footprint" = "specific" ]
then
fpm_footprint=$free_footprint
fi
ynh_app_setting_set --app=$app --key=fpm_footprint --value="$fpm_footprint"
fi
}
if [ "$php_forced_max_children" != "$old_php_forced_max_children" ]
then
# Set php_forced_max_children
if [ $php_forced_max_children -ne 0 ]
then
ynh_app_setting_set --app=$app --key=php_forced_max_children --value="$php_forced_max_children"
else
# If the value is set to 0, remove the setting
ynh_app_setting_delete --app=$app --key=php_forced_max_children
fi
fi
if [ "$fpm_footprint" != "0" ]
then
ynh_add_fpm_config --usage=$fpm_usage --footprint=$fpm_footprint
else
ynh_print_err --message="When selecting 'specific', you have to set a footprint value into the field below."
fi
set__fpm_free_footprint() {
if [ "$fpm_footprint" = "specific" ]
then
ynh_app_setting_set --app=$app --key=fpm_footprint --value="$fpm_free_footprint"
fi
}
#=================================================
# GENERIC FINALIZATION
#=================================================
# SELECT THE ACTION FOLLOWING THE GIVEN ARGUMENT
#=================================================
case $1 in
show) show_config;;
apply) apply_config;;
esac
ynh_app_config_validate() {
_ynh_app_config_validate
if [ "${changed[fpm_usage]}" == "true" ] || [ "${changed[fpm_footprint]}" == "true" ] || [ "${changed[fpm_free_footprint]}" == "true" ]; then
# If fpm_footprint is set to 'specific', use $fpm_free_footprint value.
if [ "$fpm_footprint" = "specific" ]
then
fpm_footprint=$fpm_free_footprint
fi
if [ "$fpm_footprint" == "0" ]
then
ynh_print_err --message="When selecting 'specific', you have to set a footprint value into the field below."
exit 0
fi
fi
}
ynh_app_config_apply() {
_ynh_app_config_apply
ynh_add_fpm_config --phpversion=$phpversion --usage=$fpm_usage --footprint=$fpm_footprint
}
ynh_app_config_run $1

View file

@ -108,15 +108,23 @@ ynh_add_nginx_config
#=================================================
ynh_script_progression --message="Configuring PHP-FPM..." --weight=2
fpm_footprint="medium"
fpm_free_footprint=0
# If the app is private, set the usage to low, otherwise to high.
if [ $is_public -eq 0 ]
then
usage=low
fpm_usage="low"
else
usage=high
fpm_usage="high"
fi
ynh_app_setting_set --app=$app --key=fpm_footprint --value=$fpm_footprint
ynh_app_setting_set --app=$app --key=fpm_free_footprint --value=$fpm_free_footprint
ynh_app_setting_set --app=$app --key=fpm_usage --value=$fpm_usage
# Create a dedicated PHP-FPM config
ynh_add_fpm_config --usage=$usage --footprint=medium
ynh_add_fpm_config --usage=$fpm_usage --footprint=$fpm_footprint
phpversion=$(ynh_app_setting_get --app=$app --key=phpversion)
#=================================================

View file

@ -29,6 +29,7 @@ overwrite_phpfpm=$(ynh_app_setting_get --app=$app --key=overwrite_phpfpm)
admin_mail_html=$(ynh_app_setting_get --app=$app --key=admin_mail_html)
fpm_footprint=$(ynh_app_setting_get --app=$app --key=fpm_footprint)
fpm_free_footprint=$(ynh_app_setting_get --app=$app --key=fpm_free_footprint)
fpm_usage=$(ynh_app_setting_get --app=$app --key=fpm_usage)
phpversion=$(ynh_app_setting_get --app=$app --key=phpversion)
@ -131,6 +132,12 @@ if [ -z "$fpm_footprint" ]; then
ynh_app_setting_set --app=$app --key=fpm_footprint --value=$fpm_footprint
fi
# If fpm_free_footprint doesn't exist, create it
if [ -z "$fpm_free_footprint" ]; then
fpm_free_footprint=0
ynh_app_setting_set --app=$app --key=fpm_free_footprint --value=$fpm_free_footprint
fi
# If fpm_usage doesn't exist, create it
if [ -z "$fpm_usage" ]; then
# If the app is private, set the usage to low, otherwise to high.