diff --git a/Vagrantfile b/Vagrantfile index d3e86f4..74c6b78 100644 --- a/Vagrantfile +++ b/Vagrantfile @@ -10,8 +10,8 @@ Vagrant.configure("2") do |config| # For a complete reference, please see the online documentation at # https://docs.vagrantup.com. - config.vm.define :mattermost_ynh - config.vm.box = "debian/contrib-jessie64" + config.vm.define :ynh_tests + config.vm.box = "yunohost/jessie-stable" # Disable auto updates checks. Run `vagrant outdated` to perform manual updates. config.vm.box_check_update = false @@ -36,36 +36,27 @@ Vagrant.configure("2") do |config| # Puppet, Chef, Ansible, Salt, and Docker are also available. Please see the # documentation for more information about their specific syntax and use. config.vm.provision "shell", privileged: false, keep_color: true, inline: <<-SHELL - TESTS_DIR="/home/vagrant/tests" - APP_DIR="$TESTS_DIR/mattermost_ynh" - VM_ROOT_PASSWORD="alpine" + DOMAIN=ynh-tests.local YUNOHOST_ADMIN_PASSWORD="alpine" # Stop on first error set -e - # Upgrade the system packages - #DEBIAN_FRONTEND=noninteractive sudo apt-get update - #DEBIAN_FRONTEND=noninteractive sudo apt-get upgrade --yes -o Dpkg::Options::='--force-confdef' -o Dpkg::Options::='--force-confold' + # Upgrade Yunohost and the system packages (disabled) + sudo apt-get update + sudo apt-get upgrade --yes + sudo apt-get dist-upgrade --yes - # Install git - hash git 2>/dev/null || sudo apt-get install git --yes - - # Install Yunohost - if ! hash yunohost 2>/dev/null; then - git clone https://github.com/YunoHost/install_script /tmp/install_script - yes ${VM_ROOT_PASSWORD} | sudo passwd - cd /tmp/install_script - echo "Running Yunohost install script…" - sudo ./install_yunohost -a - sudo yunohost tools postinstall --domain mattermost-ynh.local --password ${YUNOHOST_ADMIN_PASSWORD} + # Finish Yunohost installation + if ! [[ -f /etc/yunohost/installed ]]; then + sudo yunohost tools postinstall --domain ${DOMAIN} --password ${YUNOHOST_ADMIN_PASSWORD} --ignore-dyndns fi # Install lxc - if ! hash lxc-start 2>/dev/null; then - DEBIAN_FRONTEND=noninteractive sudo apt-get update - DEBIAN_FRONTEND=noninteractive sudo apt-get install --yes --fix-missing lxc - fi + # if ! hash lxc-start 2>/dev/null; then + # DEBIAN_FRONTEND=noninteractive sudo apt-get update + # DEBIAN_FRONTEND=noninteractive sudo apt-get install --yes --fix-missing lxc + # fi # Install package_check if ! [ -f "$HOME/package_check/package_check.sh" ]; then diff --git a/scripts/backup b/scripts/backup index 73bf523..fa1df5e 100755 --- a/scripts/backup +++ b/scripts/backup @@ -10,6 +10,7 @@ source /usr/share/yunohost/helpers #================================================= # LOAD SETTINGS #================================================= + app=$YNH_APP_INSTANCE_NAME final_path="/var/www/$app" diff --git a/scripts/restore b/scripts/restore new file mode 100644 index 0000000..d187861 --- /dev/null +++ b/scripts/restore @@ -0,0 +1,96 @@ +#!/bin/bash +set -eu # exit on error ; treat unset variables as error + +#================================================= +# IMPORT GENERIC HELPERS +#================================================= + +source /usr/share/yunohost/helpers + +#================================================= +# LOAD SETTINGS +#================================================= + +app=$YNH_APP_INSTANCE_NAME + +domain=$(ynh_app_setting_get $app domain) +final_path="/var/www/$app" +data_path="/home/yunohost.app/$app" +db_name="$app" +db_user="mmuser" + +#================================================= +# CHECK IF THE APP CAN BE RESTORED +#================================================= + +yunohost app checkurl "${domain}" -a "$app" \ + || ynh_die "Path not available: ${domain}" +test ! -d $final_path \ + || ynh_die "There is already a directory: $final_path " + +#================================================= +# STANDARD RESTORATION STEPS +#================================================= +# RESTORE THE NGINX CONFIGURATION +#================================================= + +ynh_restore_file "/etc/nginx/conf.d/$domain.d/$app.conf" + +#================================================= +# RESTORE THE APP MAIN DIR +#================================================= + +ynh_restore_file "$final_path" + +#================================================= +# RESTORE THE MYSQL DATABASE +#================================================= + +db_pwd=$(ynh_app_setting_get $app mysqlpwd) +ynh_mysql_setup_db $db_user $db_name $db_pwd +ynh_mysql_connect_as $db_user $db_pwd $db_name < ./db.sql + +#================================================= +# RECREATE THE DEDICATED USER +#================================================= + +# Create the dedicated user (if not existing) +smtp_user="$app" +if ! ynh_system_user_exists "$smtp_user"; then + smtp_password=$(ynh_app_setting_get $app smtp_password) + useradd -M --shell /bin/false -p $(openssl passwd -1 "$smtp_password") "$smtp_user" +fi + +#================================================= +# RESTORE USER RIGHTS +#================================================= + +# Restore permissions on app files +chown -R www-data: $final_path +mkdir -p $data_path +chown -R www-data: $data_path + +#================================================= +# SPECIFIC RESTORATION +#================================================= +# REINSTALL DEPENDENCIES +#================================================= + +# Define and install dependencies +# TODO: use ynh_install_app_dependencies once we'll stop supporting Yunohost < 2.6.4 +command -v supervisorctl >/dev/null 2>&1 || sudo apt-get install -y supervisor + +#================================================= +# RESTORE SUPERVISOR CONF +#================================================= + +ynh_restore_file "/etc/supervisor/conf.d/$app.conf" + +#================================================= +# GENERIC FINALIZATION +#================================================= +# RELOAD NGINX AND START THE APP +#================================================= + +sudo service nginx reload +sudo supervisorctl reload diff --git a/test.sh b/test.sh index 59b2e65..c8e8289 100755 --- a/test.sh +++ b/test.sh @@ -10,7 +10,8 @@ set -e # Configuration constants APP_NAME="mattermost" TESTS_DIR="/home/vagrant/tests" -APP_DIR="$TESTS_DIR/mattermost_ynh" +APP_DIR="$TESTS_DIR/app" +DOMAIN="ynh-tests.local" VM_ROOT_PASSWORD="alpine" YUNOHOST_ADMIN_PASSWORD="alpine" @@ -76,21 +77,24 @@ function _assert_success() { function setup() { if $SKIP_SNAPSHOT; then echo "--- Starting Vagrant box ---" - vagrant up + vagrant up --no-provision echo "--- (Skipping snapshot restore) ---" return fi - if (vagrant snapshot list | grep 'yunohost-2.4-pristine' > /dev/null); then + if (vagrant snapshot list | grep 'yunohost-jessie-pristine' > /dev/null); then echo "--- Restoring Vagrant snapshot ---" - vagrant snapshot restore yunohost-2.4-pristine + vagrant snapshot restore --no-provision yunohost-jessie-pristine else echo "--- Provisioning Vagrant box ---" vagrant up --provision echo "--- Saving Vagrant snapshot ---" - vagrant snapshot save yunohost-2.4-pristine + vagrant snapshot save yunohost-jessie-pristine fi + # Copy the files inside the VM, rather than using the mounted + # files directly. + # This avoids tests screwing up our files if something goes wrong. echo "--- Copying app content into the box ---" if ! [ -d "$APP_DIR" ]; then _vagrant_ssh "mkdir -p '$TESTS_DIR'" @@ -100,7 +104,7 @@ function setup() { function test_simple_install() { echo "--- Running simple installation test ---" - _vagrant_ssh "sudo yunohost app install '$APP_DIR' --args 'domain=mattermost-ynh.local&public_site=Yes&analytics=0' $VERBOSE_OPT" + _vagrant_ssh "sudo yunohost app install '$APP_DIR' --args 'domain=${DOMAIN}&public_site=Yes&analytics=0' $VERBOSE_OPT" } function test_simple_upgrade() { @@ -110,8 +114,18 @@ function test_simple_upgrade() { function test_simple_backup() { echo "--- Running simple backup test ---" - local BACKUP_DIR="$TESTS_DIR/backups" - _vagrant_ssh "sudo yunohost backup create --ignore-hooks --no-compress --apps $APP_NAME --output-directory $BACKUP_DIR $VERBOSE_OPT" + _vagrant_ssh "sudo yunohost backup create --ignore-hooks --apps $APP_NAME $VERBOSE_OPT" +} + +function test_simple_remove() { + echo "--- Running simple remove test ---" + _vagrant_ssh "sudo yunohost app remove $APP_NAME" +} + +function test_simple_restore() { + echo "--- Running simple restore test ---" + _vagrant_ssh "sudo yunohost backup list | cut -d ' ' -f 2 > backup_name" + _vagrant_ssh "sudo yunohost backup restore \$(cat backup_name) --force --ignore-hooks --apps $APP_NAME $VERBOSE_OPT" } function test_package_check() { @@ -130,5 +144,7 @@ setup test_simple_install test_simple_upgrade test_simple_backup +test_simple_remove +test_simple_restore test_package_check teardown