diff --git a/conf/.env b/conf/.env index 865c609..eabf6ea 100644 --- a/conf/.env +++ b/conf/.env @@ -3,3 +3,4 @@ DATABASE_URL=postgresql://__DB_USER__:__DB_PWD__@127.0.0.1:5432/__DB_NAME__ DISABLE_TELEMETRY=1 PORT=__PORT__ DEFAULT_LOCALE="__LANGUAGE__" +NODE_ENV=production diff --git a/conf/systemd.service b/conf/systemd.service index 7f6806e..15b2e0d 100644 --- a/conf/systemd.service +++ b/conf/systemd.service @@ -6,7 +6,7 @@ After=network.target Type=simple User=__APP__ Group=__APP__ -WorkingDirectory=__INSTALL_DIR__/ +WorkingDirectory=__INSTALL_DIR__/release Environment=NODE_ENV=production Environment="__YNH_NODE_LOAD_PATH__" Environment=NEXT_TELEMETRY_DISABLED=1 diff --git a/scripts/install b/scripts/install index 4beff87..2d1be63 100755 --- a/scripts/install +++ b/scripts/install @@ -23,7 +23,7 @@ ynh_exec_warn_less ynh_install_nodejs --nodejs_version=$nodejs_version ynh_script_progression --message="Setting up source files..." --weight=5 # 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/build" chmod -R o-rwx "$install_dir" chown -R $app:www-data "$install_dir" @@ -46,10 +46,10 @@ yunohost service add $app --description="Web Analytics" --log="/var/log/$app/$ap #================================================= ynh_script_progression --message="Adding a configuration file..." --weight=1 -ynh_add_config --template="../conf/.env" --destination="$install_dir/.env" +ynh_add_config --template="../conf/.env" --destination="$install_dir/build/.env" -chmod 650 "$install_dir/.env" -chown $app:$app "$install_dir/.env" +chmod 650 "$install_dir/build/.env" +chown $app:$app "$install_dir/build/.env" ynh_script_progression --message="Provisioning pgcrypto..." --weight=1 @@ -60,12 +60,35 @@ ynh_psql_execute_as_root --sql="CREATE EXTENSION IF NOT EXISTS pgcrypto;" --data #================================================= ynh_script_progression --message="Configuring the app..." --weight=15 -pushd $install_dir +pushd "$install_dir/build" ynh_use_nodejs ynh_exec_warn_less ynh_exec_as $app env $ynh_node_load_PATH yarn install ynh_exec_warn_less ynh_exec_as $app env $ynh_node_load_PATH NEXT_TELEMETRY_DISABLED=1 yarn build + + # Actual app is a subset of release assets + # List of deps based on Dockerfile: https://github.com/umami-software/umami/blob/master/Dockerfile + ynh_secure_remove --file="node_modules/" + mv next.config.js .next/standalone/ + mv public/ .next/standalone/ + mv prisma/ .next/standalone/ + mv scripts/ .next/standalone/ + mv .next/static .next/standalone/ popd +mkdir "$install_dir/release" +chmod -R o-rwx "$install_dir/release" +chown -R $app:www-data "$install_dir/release" + +pushd "$install_dir/release" + ynh_exec_warn_less ynh_exec_as $app env $ynh_node_load_PATH yarn add npm-run-all dotenv prisma +popd + + +mv -f $install_dir/build/.next/standalone/* $install_dir/release + +rm -rf $install_dir/.cache +rm -rf $install_dir/build + #================================================= # START SYSTEMD SERVICE #================================================= diff --git a/scripts/upgrade b/scripts/upgrade index 17363d2..2e91083 100644 --- a/scripts/upgrade +++ b/scripts/upgrade @@ -45,12 +45,14 @@ if [ "$upgrade_type" == "UPGRADE_APP" ] then ynh_script_progression --message="Upgrading source files..." --weight=5 + ynh_secure_remove --file="$install_dir/release" + # Download, check integrity, uncompress and patch the source from app.src - ynh_setup_source --dest_dir="$install_dir" --full_replace=1 #--keep=".env" + ynh_setup_source --dest_dir="$install_dir/build" --full_replace=1 #--keep=".env" fi -chmod -R o-rwx "$install_dir" -chown -R $app:www-data "$install_dir" +chmod -R o-rwx "$install_dir/build" +chown -R $app:www-data "$install_dir/build" #================================================= # UPGRADE DEPENDENCIES