1
0
Fork 0
mirror of https://github.com/YunoHost-Apps/gitlab_ynh.git synced 2024-09-03 18:36:35 +02:00

Merge branch 'testing' into 12.2.0

This commit is contained in:
Kayou 2019-09-03 20:40:38 +02:00 committed by GitHub
commit ea128e4110
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
7 changed files with 259 additions and 47 deletions

View file

@ -11,9 +11,11 @@
"id": "is_public",
"options": [
{
"name": "Is it a public app ?",
"id": "is_public",
"type": "bool",
"name": "is_public",
"ask": {
"en": "Is it a public app ?"
},
"type": "boolean",
"default": true
}
]
@ -23,10 +25,12 @@
"id": "overwrite_files",
"options": [
{
"name": "Overwrite the nginx config file ?",
"name": "overwrite_nginx",
"ask": {
"en": "Overwrite the nginx config file ?"
},
"help": "If the file is overwritten, a backup will be created.",
"id": "overwrite_nginx",
"type": "bool",
"type": "boolean",
"default": true
}
]
@ -36,10 +40,91 @@
"id": "users",
"options": [
{
"name": "Authorized external user creation ?",
"name": "use_web_account",
"ask": {
"en": "Authorized external user creation ?"
},
"help": "Allow user to be created without yunohost account.",
"id": "use_web_account",
"type": "bool",
"type": "boolean",
"default": true
}
]
},
{
"name": "Backup strategy",
"id": "backup_strategy",
"help": "WARNING: If you disable one of these backup, it will not be restored in case of error, use this feature at your own risk",
"options": [
{
"name": "backup_db",
"ask": {
"en": "Should gitlab backup the database ?"
},
"help": "https://docs.gitlab.com/ce/raketasks/backup_restore.html#excluding-specific-directories-from-the-backup",
"type": "boolean",
"default": true
},
{
"name": "backup_uploads",
"ask": {
"en": "Should gitlab backup attachments ?"
},
"help": "https://docs.gitlab.com/ce/raketasks/backup_restore.html#excluding-specific-directories-from-the-backup",
"type": "boolean",
"default": true
},
{
"name": "backup_repositories",
"ask": {
"en": "Should gitlab backup git repositories data ?"
},
"help": "https://docs.gitlab.com/ce/raketasks/backup_restore.html#excluding-specific-directories-from-the-backup",
"type": "boolean",
"default": true
},
{
"name": "backup_builds",
"ask": {
"en": "Should gitlab backup CI job output logs ?"
},
"help": "https://docs.gitlab.com/ce/raketasks/backup_restore.html#excluding-specific-directories-from-the-backup",
"type": "boolean",
"default": true
},
{
"name": "backup_artifacts",
"ask": {
"en": "Should gitlab backup CI job artifacts ?"
},
"help": "https://docs.gitlab.com/ce/raketasks/backup_restore.html#excluding-specific-directories-from-the-backup",
"type": "boolean",
"default": true
},
{
"name": "backup_lfs",
"ask": {
"en": "Should gitlab backup LFS objects ?"
},
"help": "https://docs.gitlab.com/ce/raketasks/backup_restore.html#excluding-specific-directories-from-the-backup",
"type": "boolean",
"default": true
},
{
"name": "backup_registry",
"ask": {
"en": "Should gitlab backup container registry images ?"
},
"help": "https://docs.gitlab.com/ce/raketasks/backup_restore.html#excluding-specific-directories-from-the-backup",
"type": "boolean",
"default": true
},
{
"name": "backup_pages",
"ask": {
"en": "Should gitlab backup pages content ?"
},
"help": "https://docs.gitlab.com/ce/raketasks/backup_restore.html#excluding-specific-directories-from-the-backup",
"type": "boolean",
"default": true
}
]

View file

@ -14,7 +14,7 @@
"email": "pierre@kayou.io"
},
"requirements": {
"yunohost": ">= 3.5.0"
"yunohost": ">= 3.6.0"
},
"multi_instance": false,
"services": [

View file

@ -6,24 +6,6 @@
pkg_dependencies="openssh-server"
#=================================================
# BOOLEAN CONVERTER
#=================================================
bool_to_01 () {
local var="$1"
[ "$var" = "true" ] && var=1
[ "$var" = "false" ] && var=0
echo "$var"
}
bool_to_true_false () {
local var="$1"
[ "$var" = "1" ] && var=true
[ "$var" = "0" ] && var=false
echo "$var"
}
#=================================================
# EXPERIMENTAL HELPERS
#=================================================

View file

@ -32,6 +32,15 @@ final_path=$(ynh_app_setting_get --app=$app --key=final_path)
config_path=$(ynh_app_setting_get --app=$app --key=config_path)
domain=$(ynh_app_setting_get --app=$app --key=domain)
backup_db=$(ynh_app_setting_get --app="$app" --key=backup_db)
backup_uploads=$(ynh_app_setting_get --app="$app" --key=backup_uploads)
backup_repositories=$(ynh_app_setting_get --app="$app" --key=backup_repositories)
backup_builds=$(ynh_app_setting_get --app="$app" --key=backup_builds)
backup_artifacts=$(ynh_app_setting_get --app="$app" --key=backup_artifacts)
backup_lfs=$(ynh_app_setting_get --app="$app" --key=backup_lfs)
backup_registry=$(ynh_app_setting_get --app="$app" --key=backup_registry)
backup_pages=$(ynh_app_setting_get --app="$app" --key=backup_pages)
#=================================================
# STANDARD BACKUP STEPS
#=================================================
@ -46,10 +55,45 @@ ynh_backup --src_path="/etc/nginx/conf.d/$domain.d/$app.conf"
#=================================================
ynh_script_progression --message="Backuping of Gitlab..." --weight=9
to_skip=""
if [ $backup_db -eq 0 ]; then
to_skip="db,"$to_skip
fi
if [ $backup_uploads -eq 0 ]; then
to_skip="uploads,"$to_skip
fi
if [ $backup_repositories -eq 0 ]; then
to_skip="repositories,"$to_skip
fi
if [ $backup_builds -eq 0 ]; then
to_skip="builds,"$to_skip
fi
if [ $backup_artifacts -eq 0 ]; then
to_skip="artifacts,"$to_skip
fi
if [ $backup_lfs -eq 0 ]; then
to_skip="lfs,"$to_skip
fi
if [ $backup_registry -eq 0 ]; then
to_skip="registry,"$to_skip
fi
if [ $backup_pages -eq 0 ]; then
to_skip="pages,"$to_skip
fi
# Use gitlab-rake to backup
# For the complete doc: https://docs.gitlab.com/ce/raketasks/backup_restore.html
# For the filename: https://docs.gitlab.com/ce/raketasks/backup_restore.html#backup-filename
gitlab-backup create BACKUP=last
# For the backup strategy: https://docs.gitlab.com/ce/raketasks/backup_restore.html#excluding-specific-directories-from-the-backup
gitlab-backup create BACKUP=last SKIP=$to_skip
ynh_backup --src_path="/var/opt/$app/backups/last_gitlab_backup.tar"

View file

@ -27,19 +27,41 @@ app=${YNH_APP_INSTANCE_NAME:-$YNH_APP_ID}
# is_public
old_is_public="$(ynh_app_setting_get --app=$app --key=is_public)"
old_is_public=$(bool_to_true_false $old_is_public)
is_public="${YNH_CONFIG_MAIN_IS_PUBLIC_IS_PUBLIC:-$old_is_public}"
# Overwrite nginx configuration
old_overwrite_nginx="$(ynh_app_setting_get --app=$app --key=overwrite_nginx)"
old_overwrite_nginx=$(bool_to_true_false $old_overwrite_nginx)
overwrite_nginx="${YNH_CONFIG_MAIN_OVERWRITE_FILES_OVERWRITE_NGINX:-$old_overwrite_nginx}"
# use_web_account
old_use_web_account="$(ynh_app_setting_get --app=$app --key=use_web_account)"
old_use_web_account=$(bool_to_true_false $old_use_web_account)
use_web_account="${YNH_CONFIG_MAIN_USERS_USE_WEB_ACCOUNT:-$old_use_web_account}"
# backup_strategy
old_backup_db="$(ynh_app_setting_get --app=$app --key=backup_db)"
backup_db="${YNH_CONFIG_MAIN_BACKUP_STRATEGY_BACKUP_DB:-$old_backup_db}"
old_backup_uploads="$(ynh_app_setting_get --app=$app --key=backup_uploads)"
backup_uploads="${YNH_CONFIG_MAIN_BACKUP_STRATEGY_BACKUP_UPLOADS:-$old_backup_uploads}"
old_backup_repositories="$(ynh_app_setting_get --app=$app --key=backup_repositories)"
backup_repositories="${YNH_CONFIG_MAIN_BACKUP_STRATEGY_BACKUP_REPOSITORIES:-$old_backup_repositories}"
old_backup_builds="$(ynh_app_setting_get --app=$app --key=backup_builds)"
backup_builds="${YNH_CONFIG_MAIN_BACKUP_STRATEGY_BACKUP_BUILDS:-$old_backup_builds}"
old_backup_artifacts="$(ynh_app_setting_get --app=$app --key=backup_artifacts)"
backup_artifacts="${YNH_CONFIG_MAIN_BACKUP_STRATEGY_BACKUP_ARTIFACTS:-$old_backup_artifacts}"
old_backup_lfs="$(ynh_app_setting_get --app=$app --key=backup_lfs)"
backup_lfs="${YNH_CONFIG_MAIN_BACKUP_STRATEGY_BACKUP_LFS:-$old_backup_lfs}"
old_backup_registry="$(ynh_app_setting_get --app=$app --key=backup_registry)"
backup_registry="${YNH_CONFIG_MAIN_BACKUP_STRATEGY_BACKUP_REGISTRY:-$old_backup_registry}"
old_backup_pages="$(ynh_app_setting_get --app=$app --key=backup_pages)"
backup_pages="${YNH_CONFIG_MAIN_BACKUP_STRATEGY_BACKUP_PAGES:-$old_backup_pages}"
#=================================================
# SHOW_CONFIG FUNCTION FOR 'SHOW' COMMAND
#=================================================
@ -48,11 +70,27 @@ show_config() {
# here you are supposed to read some config file/database/other then print the values
# echo "YNH_CONFIG_${PANEL_ID}_${SECTION_ID}_${OPTION_ID}=value"
echo "YNH_CONFIG_MAIN_IS_PUBLIC_IS_PUBLIC=$is_public"
ynh_return "YNH_CONFIG_MAIN_IS_PUBLIC_IS_PUBLIC=$is_public"
echo "YNH_CONFIG_MAIN_OVERWRITE_FILES_OVERWRITE_NGINX=$overwrite_nginx"
ynh_return "YNH_CONFIG_MAIN_OVERWRITE_FILES_OVERWRITE_NGINX=$overwrite_nginx"
echo "YNH_CONFIG_MAIN_USERS_USE_WEB_ACCOUNT=$use_web_account"
ynh_return "YNH_CONFIG_MAIN_USERS_USE_WEB_ACCOUNT=$use_web_account"
ynh_return "YNH_CONFIG_MAIN_BACKUP_STRATEGY_BACKUP_DB=$backup_db"
ynh_return "YNH_CONFIG_MAIN_BACKUP_STRATEGY_BACKUP_UPLOADS=$backup_uploads"
ynh_return "YNH_CONFIG_MAIN_BACKUP_STRATEGY_BACKUP_REPOSITORIES=$backup_repositories"
ynh_return "YNH_CONFIG_MAIN_BACKUP_STRATEGY_BACKUP_BUILDS=$backup_builds"
ynh_return "YNH_CONFIG_MAIN_BACKUP_STRATEGY_BACKUP_ARTIFACTS=$backup_artifacts"
ynh_return "YNH_CONFIG_MAIN_BACKUP_STRATEGY_BACKUP_LFS=$backup_lfs"
ynh_return "YNH_CONFIG_MAIN_BACKUP_STRATEGY_BACKUP_REGISTRY=$backup_registry"
ynh_return "YNH_CONFIG_MAIN_BACKUP_STRATEGY_BACKUP_PAGES=$backup_pages"
}
#=================================================
@ -61,23 +99,30 @@ show_config() {
apply_config() {
# Change public accessibility
if [ "$is_public" = "true" ]
then
yunohost app action run $app public_private --args is_public=1
else
yunohost app action run $app public_private --args is_public=0
fi
yunohost app action run $app public_private --args is_public=$is_public
# Change use_web_account
if [ "$use_web_account" = "true" ]
then
yunohost app action run $app web_account --args use_web_account=1
else
yunohost app action run $app web_account --args use_web_account=0
fi
yunohost app action run $app web_account --args use_web_account=$use_web_account
# Set overwrite_nginx
ynh_app_setting_set --app=$app --key=overwrite_nginx --value="$overwrite_nginx"
# Set backup_db
ynh_app_setting_set --app=$app --key=backup_db --value="$backup_db"
# Set backup_uploads
ynh_app_setting_set --app=$app --key=backup_uploads --value="$backup_uploads"
# Set backup_repositories
ynh_app_setting_set --app=$app --key=backup_repositories --value="$backup_repositories"
# Set backup_builds
ynh_app_setting_set --app=$app --key=backup_builds --value="$backup_builds"
# Set backup_artifacts
ynh_app_setting_set --app=$app --key=backup_artifacts --value="$backup_artifacts"
# Set backup_lfs
ynh_app_setting_set --app=$app --key=backup_lfs --value="$backup_lfs"
# Set backup_registry
ynh_app_setting_set --app=$app --key=backup_registry --value="$backup_registry"
# Set backup_pages
ynh_app_setting_set --app=$app --key=backup_pages --value="$backup_pages"
}
#=================================================

View file

@ -216,6 +216,20 @@ newuser.confirmation_token = nil
newuser.save
ApplicationSetting.last.update_attributes(password_authentication_enabled_for_web: $use_web_account, signup_enabled: $use_web_account)" | gitlab-rails console
#=================================================
# DEFINE THE BACKUP STRATEGY: https://docs.gitlab.com/ce/raketasks/backup_restore.html#excluding-specific-directories-from-the-backup
#=================================================
ynh_app_setting_set --app=$app --key=backup_db --value=1
ynh_app_setting_set --app=$app --key=backup_uploads --value=1
ynh_app_setting_set --app=$app --key=backup_repositories --value=1
ynh_app_setting_set --app=$app --key=backup_builds --value=1
ynh_app_setting_set --app=$app --key=backup_artifacts --value=1
ynh_app_setting_set --app=$app --key=backup_lfs --value=1
ynh_app_setting_set --app=$app --key=backup_registry --value=1
ynh_app_setting_set --app=$app --key=backup_pages --value=1
#=================================================
# RECONFIGURE TO TAKE INTO ACCOUNT CHANGES
#=================================================

View file

@ -33,6 +33,15 @@ unicorn_worker_processes=$(ynh_app_setting_get --app="$app" --key=unicorn_worker
client_max_body_size=$(ynh_app_setting_get --app="$app" --key=client_max_body_size)
overwrite_nginx=$(ynh_app_setting_get --app="$app" --key=overwrite_nginx)
backup_db=$(ynh_app_setting_get --app="$app" --key=backup_db)
backup_uploads=$(ynh_app_setting_get --app="$app" --key=backup_uploads)
backup_repositories=$(ynh_app_setting_get --app="$app" --key=backup_repositories)
backup_builds=$(ynh_app_setting_get --app="$app" --key=backup_builds)
backup_artifacts=$(ynh_app_setting_get --app="$app" --key=backup_artifacts)
backup_lfs=$(ynh_app_setting_get --app="$app" --key=backup_lfs)
backup_registry=$(ynh_app_setting_get --app="$app" --key=backup_registry)
backup_pages=$(ynh_app_setting_get --app="$app" --key=backup_pages)
#=================================================
# CHECK VERSION
#=================================================
@ -146,6 +155,39 @@ if [ -e "/etc/apt/sources.list.d/gitlab-ce.list" ]; then
ynh_secure_remove --file="/etc/apt/sources.list.d/gitlab-ce.list"
fi
# Define the backup strategy: https://docs.gitlab.com/ce/raketasks/backup_restore.html#excluding-specific-directories-from-the-backup
if [ -z "$backup_db" ]; then
ynh_app_setting_set --app=$app --key=backup_db --value=1
fi
if [ -z "$backup_uploads" ]; then
ynh_app_setting_set --app=$app --key=backup_uploads --value=1
fi
if [ -z "$backup_repositories" ]; then
ynh_app_setting_set --app=$app --key=backup_repositories --value=1
fi
if [ -z "$backup_builds" ]; then
ynh_app_setting_set --app=$app --key=backup_builds --value=1
fi
if [ -z "$backup_artifacts" ]; then
ynh_app_setting_set --app=$app --key=backup_artifacts --value=1
fi
if [ -z "$backup_lfs" ]; then
ynh_app_setting_set --app=$app --key=backup_lfs --value=1
fi
if [ -z "$backup_registry" ]; then
ynh_app_setting_set --app=$app --key=backup_registry --value=1
fi
if [ -z "$backup_pages" ]; then
ynh_app_setting_set --app=$app --key=backup_pages --value=1
fi
#=================================================
# BACKUP BEFORE UPGRADE THEN ACTIVE TRAP
#=================================================