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

Less compilation

This commit is contained in:
yalh76 2021-08-27 02:34:54 +02:00
parent eed830d610
commit c4d6a68a4e
9 changed files with 113 additions and 177 deletions

View file

@ -1,5 +1,5 @@
PHOTOVIEW_DATABASE_DRIVER=mysql PHOTOVIEW_DATABASE_DRIVER=mysql
PHOTOVIEW_MYSQL_URL=__DB_NAME__:__DB_PWD__@tcp(localhost)/__DB_NAME__ PHOTOVIEW_MYSQL_URL="__DB_NAME__:__DB_PWD__@tcp(localhost)/__DB_NAME__"
PHOTOVIEW_LISTEN_IP=localhost PHOTOVIEW_LISTEN_IP=localhost
PHOTOVIEW_LISTEN_PORT=__PORT__ PHOTOVIEW_LISTEN_PORT=__PORT__

View file

@ -0,0 +1,7 @@
SOURCE_URL=https://codeload.github.com/jjlin/docker-image-extract/tar.gz/a9e455e44bbbfba897bf3342d9661b182cee67a9
SOURCE_SUM=9eb0c734e83a3fd7102fc7209af4977024ec467fbc819782491af47295675f67
SOURCE_SUM_PRG=sha256sum
SOURCE_FORMAT=tar.gz
SOURCE_IN_SUBDIR=true
SOURCE_FILENAME=
SOURCE_EXTRACT=true

View file

@ -6,9 +6,9 @@ After=network.target mysql.service
Type=simple Type=simple
User=__APP__ User=__APP__
Group=__APP__ Group=__APP__
WorkingDirectory=__FINALPATH__/output WorkingDirectory=__FINALPATH__/live
EnvironmentFile=__FINALPATH__/output/.env EnvironmentFile=__FINALPATH__/.env
ExecStart=/usr/bin/env bash -c "LD_LIBRARY_PATH=__FINALPATH__/local/lib:$LD_LIBRARY_PATH __FINALPATH__/output/photoview" ExecStart=__FINALPATH__/live/photoview
StandardOutput=append:/var/log/__APP__/__APP__.log StandardOutput=append:/var/log/__APP__/__APP__.log
StandardError=inherit StandardError=inherit

View file

@ -5,115 +5,23 @@
#================================================= #=================================================
# dependencies used by the app # dependencies used by the app
pkg_dependencies="curl gpg libdlib19 ffmpeg exiftool libheif1 ca-certificates golang libdlib-dev libblas-dev libatlas-base-dev liblapack-dev libjpeg-dev libheif-dev build-essential pkg-config autoconf automake libx265-dev libde265-dev libaom-dev" pkg_dependencies="libdlib19 ffmpeg exiftool libheif1"
if ! (apt-cache -q=0 show darktable |& grep ': No packages found' &>/dev/null); then if ! (apt-cache -q=0 show darktable |& grep ': No packages found' &>/dev/null); then
pkg_dependencies="$pkg_dependencies darktable" pkg_dependencies="$pkg_dependencies darktable"
fi fi
PHOTOVIEW_VERSION=2.3.5
#================================================= #=================================================
# PERSONAL HELPERS # PERSONAL HELPERS
#================================================= #=================================================
function setup_sources {
ynh_secure_remove "$final_path"
ynh_setup_source --dest_dir="$final_path"
ynh_setup_source --source_id=libheif --dest_dir="$final_path/libheif"
set_permissions
}
function build_libheif {
pushd "$final_path/libheif" || ynh_die
chown -R $app:$app "$final_path/libheif"
mkdir -p "$final_path/local"
chown -R $app:$app "$final_path/libheif"
chown -R $app:$app "$final_path/local"
sudo -u $app "$final_path/libheif/autogen.sh" 2>&1
sudo -u $app "$final_path/libheif/configure" --prefix="$final_path/local" --disable-gdk-pixbuf 2>&1
make clean 2>&1
make 2>&1
make install 2>&1
make clean 2>&1
popd || ynh_die
set_permissions
}
function set_go_vars {
ynh_install_go --go_version=1.16
ynh_use_go
go_shims_path=$goenv_install_dir/shims
go_path_full="$go_shims_path":"$(sudo -u $app bash -c 'echo $PATH')"
heif_lib_path="$final_path/local/lib":"$(sudo -u $app bash -c 'echo $LIBRARY_PATH')"
heif_ld_lib_path="$final_path/local/lib":"$(sudo -u $app bash -c 'echo $LD_LIBRARY_PATH')"
heif_cgo_cflags="-I$final_path/local/include"
}
function build_api {
set_go_vars
pushd "$final_path/api" || ynh_die
chown -R $app:$app "$final_path"
set +e ; for i in {1..5}; do
sudo -u $app env "PATH=$go_path_full" "LIBRARY_PATH=$heif_lib_path" "LD_LIBRARY_PATH=$heif_ld_lib_path" "CGO_CFLAGS=$heif_cgo_cflags" GOENV_VERSION=$go_version CGO_ENABLED=1 go mod download 2>&1 && break
sleep 5
done; set -e
sudo -u $app env "PATH=$go_path_full" "LIBRARY_PATH=$heif_lib_path" "LD_LIBRARY_PATH=$heif_ld_lib_path" "CGO_CFLAGS=$heif_cgo_cflags" GOENV_VERSION=$go_version CGO_ENABLED=1 go install github.com/mattn/go-sqlite3 github.com/Kagami/go-face 2>&1
sudo -u $app env "PATH=$go_path_full" "LIBRARY_PATH=$heif_lib_path" "LD_LIBRARY_PATH=$heif_ld_lib_path" "CGO_CFLAGS=$heif_cgo_cflags" GOENV_VERSION=$go_version go build -o photoview "$final_path/api" 2>&1
popd || ynh_die
cp -T "$final_path/api/photoview" "$final_path/output/photoview"
cp -rT "$final_path/api/data" "$final_path/output/data"
set_permissions
}
function build_ui {
set_node_vars
ui_path="$final_path/ui"
ynh_replace_string -m "npm" -r "yarn" -f "$ui_path/package.json"
ynh_replace_string -m "npx" -r "yarn run" -f "$ui_path/package.json"
ynh_replace_string -m "cd .. && " -r "" -f "$ui_path/package.json"
pushd "$ui_path" || ynh_die
chown -R $app:$app $final_path
sudo -u $app touch $ui_path/.yarnrc
sudo -u $app env "PATH=$node_path" yarn --cache-folder "$ui_path/yarn-cache" --use-yarnrc "$ui_path/.yarnrc" install 2>&1
sudo -u $app env "PATH=$node_path" yarn --cache-folder "$ui_path/yarn-cache" --use-yarnrc "$ui_path/.yarnrc" add graphql 2>&1
grep -q "build complete" <((sudo -u $app env "PATH=$node_path" yarn --cache-folder "$ui_path/yarn-cache" --use-yarnrc "$ui_path/.yarnrc" run build -- --public-url "$path_url" 2>&1 & echo $! >&3 ) 3>pid) ; kill "$(<pid)"
popd || ynh_die
cp -rT "$final_path/ui/dist" "$final_path/output/ui"
set_permissions
}
function set_node_vars {
ynh_exec_warn_less ynh_install_nodejs --nodejs_version=15
ynh_use_nodejs
node_path=$nodejs_path:$(sudo -u $app sh -c 'echo $PATH')
}
function set_permissions {
mkdir -p "$final_path/output/"{data,ui}
chown -R root:$app $final_path
chmod -R g=u,g-w,o-rwx "$final_path"
mkdir -p "$data_path/media_cache"
chown -R $app:$app "$data_path"
mkdir -p /var/log/$app
chmod -R o-rwx /var/log/$app
}
#================================================= #=================================================
# EXPERIMENTAL HELPERS # EXPERIMENTAL HELPERS
#================================================= #=================================================
# YNH_INSTALL_GO
#!/bin/bash #=================================================
ynh_go_try_bash_extension() { ynh_go_try_bash_extension() {
if [ -x src/configure ]; then if [ -x src/configure ]; then

View file

@ -75,7 +75,7 @@ change_path=0
#================================================= #=================================================
ynh_script_progression --message="Stopping a systemd service..." --weight=1 ynh_script_progression --message="Stopping a systemd service..." --weight=1
ynh_systemd_action --service_name=$app --action="stop" --log_path="/var/log/$app/$app.log" ynh_systemd_action --service_name=$app --action="stop" --log_path="systemd" --line_match="Stopped Photoview"
#================================================= #=================================================
# MODIFY URL IN NGINX CONF # MODIFY URL IN NGINX CONF
@ -113,7 +113,7 @@ set_permissions
ynh_script_progression --message="Starting a systemd service..." --weight=1 ynh_script_progression --message="Starting a systemd service..." --weight=1
# Start a systemd service # Start a systemd service
ynh_systemd_action --service_name=$app --action="start" --log_path="/var/log/$app/$app.log" ynh_systemd_action --service_name=$app --action="start" --log_path="/var/log/$app/$app.log" --line_match="Photoview UI public endpoint ready"
#================================================= #=================================================
# RELOAD NGINX # RELOAD NGINX

View file

@ -14,7 +14,7 @@ source /usr/share/yunohost/helpers
#================================================= #=================================================
ynh_clean_setup () { ynh_clean_setup () {
true ynh_clean_check_starting
} }
# Exit if an error occurs during the execution of the script # Exit if an error occurs during the execution of the script
ynh_abort_if_errors ynh_abort_if_errors
@ -38,9 +38,6 @@ ynh_script_progression --message="Validating installation parameters..." --weigh
final_path=/opt/yunohost/$app final_path=/opt/yunohost/$app
test ! -e "$final_path" || ynh_die --message="This path already contains a folder" test ! -e "$final_path" || ynh_die --message="This path already contains a folder"
data_path=/home/yunohost.app/$app
test ! -e "$data_path" || ynh_die --message="This path already contains a folder"
# Register (book) web path # Register (book) web path
ynh_webpath_register --app=$app --domain=$domain --path_url=$path_url ynh_webpath_register --app=$app --domain=$domain --path_url=$path_url
@ -70,7 +67,6 @@ ynh_app_setting_set --app=$app --key=port --value=$port
ynh_script_progression --message="Installing dependencies..." --weight=60 ynh_script_progression --message="Installing dependencies..." --weight=60
ynh_install_app_dependencies $pkg_dependencies ynh_install_app_dependencies $pkg_dependencies
ynh_install_extra_app_dependencies --repo="deb https://dl.yarnpkg.com/debian/ stable main" --package="yarn" --key="https://dl.yarnpkg.com/debian/pubkey.gpg"
#================================================= #=================================================
# CREATE DEDICATED USER # CREATE DEDICATED USER
@ -96,9 +92,12 @@ ynh_mysql_setup_db --db_user=$db_user --db_name=$db_name
ynh_script_progression --message="Setting up source files..." --weight=10 ynh_script_progression --message="Setting up source files..." --weight=10
ynh_app_setting_set --app=$app --key=final_path --value=$final_path ynh_app_setting_set --app=$app --key=final_path --value=$final_path
ynh_app_setting_set --app=$app --key=data_path --value=$data_path
# Download, check integrity, uncompress and patch the source from app.src # Download, check integrity, uncompress and patch the source from app.src
setup_sources ynh_setup_source --dest_dir="$final_path/build-photoview/" --source_id="docker-image-extract"
chmod 750 "$final_path"
chmod -R o-rwx "$final_path"
chown -R $app:$app "$final_path"
#================================================= #=================================================
# NGINX CONFIGURATION # NGINX CONFIGURATION
@ -111,34 +110,46 @@ ynh_add_nginx_config
#================================================= #=================================================
# SPECIFIC SETUP # SPECIFIC SETUP
#================================================= #=================================================
# BUILD LIBHEIF # CREATE DATA DIRECTORY
#================================================= #=================================================
ynh_script_progression --message="Compiling libheif..." --weight=70 ynh_script_progression --message="Creating a data directory..."
build_libheif data_path=/home/yunohost.app/$app
ynh_app_setting_set --app=$app --key=data_path --value=$data_path
mkdir -p "$data_path/media_cache"
chmod 750 "$data_path"
chmod -R o-rwx "$data_path"
chown -R $app:$app "$data_path"
#================================================= #=================================================
# BUILD API # MAKE INSTALL
#================================================= #=================================================
ynh_script_progression --message="Compiling Go API..." --weight=165 ynh_script_progression --message="Making install..."
build_api # Install photoview
pushd $final_path/build-photoview
./docker-image-extract viktorstrate/photoview:$PHOTOVIEW_VERSION
popd
mkdir -p "$final_path/live/ui/"
rsync -a "$final_path/build-photoview/output/app/" "$final_path/live/"
rsync -a "$final_path/build-photoview/output/ui/" "$final_path/live/ui/"
ynh_secure_remove --file="$final_path/build-photoview"
#================================================= chmod 750 "$final_path"
# BUILD UI chmod -R o-rwx "$final_path"
#================================================= chown -R $app:$app "$final_path"
ynh_script_progression --message="Building static UI files..." --weight=45
build_ui
#================================================= #=================================================
# ADD A CONFIGURATION # ADD A CONFIGURATION
#================================================= #=================================================
ynh_script_progression --message="Adding a configuration file..." ynh_script_progression --message="Adding a configuration file..."
ynh_add_config --template=".env" --destination="$final_path/output/.env" ynh_add_config --template=".env" --destination="$final_path/.env"
set_permissions chmod 400 "$final_path/.env"
chown $app:$app "$final_path/.env"
#================================================= #=================================================
# SETUP SYSTEMD # SETUP SYSTEMD
@ -171,7 +182,7 @@ yunohost service add $app --description="Photoview photo manager API" --log="/va
ynh_script_progression --message="Starting a systemd service..." --weight=1 ynh_script_progression --message="Starting a systemd service..." --weight=1
# Start a systemd service # Start a systemd service
ynh_systemd_action --service_name=$app --action="start" --log_path="/var/log/$app/$app.log" ynh_systemd_action --service_name=$app --action="start" --log_path="/var/log/$app/$app.log" --line_match="Photoview UI public endpoint ready"
#================================================= #=================================================
# SETUP SSOWAT # SETUP SSOWAT

View file

@ -66,8 +66,6 @@ ynh_mysql_remove_db --db_user=$db_user --db_name=$db_name
ynh_script_progression --message="Removing dependencies..." --weight=5 ynh_script_progression --message="Removing dependencies..." --weight=5
# Remove metapackage and its dependencies # Remove metapackage and its dependencies
ynh_remove_go
ynh_remove_nodejs
ynh_remove_app_dependencies ynh_remove_app_dependencies
#================================================= #=================================================
@ -96,11 +94,6 @@ ynh_script_progression --message="Removing various files..."
# Remove the log files # Remove the log files
ynh_secure_remove --file="/var/log/$app" ynh_secure_remove --file="/var/log/$app"
#=================================================
# REMOVE APP DATA DIR
#=================================================
ynh_script_progression --message="Removing app data directory..." --weight=1
# Remove the app directory securely # Remove the app directory securely
ynh_secure_remove --file="$data_path" ynh_secure_remove --file="$data_path"

View file

@ -15,7 +15,7 @@ source /usr/share/yunohost/helpers
#================================================= #=================================================
ynh_clean_setup () { ynh_clean_setup () {
true ynh_clean_check_starting
} }
# Exit if an error occurs during the execution of the script # Exit if an error occurs during the execution of the script
ynh_abort_if_errors ynh_abort_if_errors
@ -71,7 +71,9 @@ ynh_script_progression --message="Restoring the app main directory..." --weight=
ynh_restore_file --origin_path="$final_path" ynh_restore_file --origin_path="$final_path"
set_permissions chmod 750 "$final_path"
chmod -R o-rwx "$final_path"
chown -R $app:$app "$final_path"
#================================================= #=================================================
# RESTORE THE APP DATA DIR # RESTORE THE APP DATA DIR
@ -80,7 +82,11 @@ ynh_script_progression --message="Restoring the app data directory..." --weight=
ynh_restore_file --origin_path="$data_path" --not_mandatory ynh_restore_file --origin_path="$data_path" --not_mandatory
set_permissions mkdir -p "$data_path/media_cache"
chmod 750 "$data_path"
chmod -R o-rwx "$data_path"
chown -R $app:$app "$data_path"
#================================================= #=================================================
# SPECIFIC RESTORATION # SPECIFIC RESTORATION
@ -101,20 +107,6 @@ db_pwd=$(ynh_app_setting_get --app=$app --key=mysqlpwd)
ynh_mysql_setup_db --db_user=$db_user --db_name=$db_name --db_pwd=$db_pwd ynh_mysql_setup_db --db_user=$db_user --db_name=$db_name --db_pwd=$db_pwd
ynh_mysql_connect_as --user=$db_user --password=$db_pwd --database=$db_name < ./db.sql ynh_mysql_connect_as --user=$db_user --password=$db_pwd --database=$db_name < ./db.sql
#=================================================
# RESTORE GO
#=================================================
ynh_script_progression --message="Restoring Go..." --weight=1
set_go_vars
#=================================================
# RESTORE NODE.JS
#=================================================
ynh_script_progression --message="Restoring Node.js..." --weight=1
set_node_vars
#================================================= #=================================================
# RESTORE SYSTEMD # RESTORE SYSTEMD
#================================================= #=================================================
@ -128,9 +120,12 @@ systemctl enable $app.service --quiet
#================================================= #=================================================
ynh_script_progression --message="Restoring the logrotate configuration..." ynh_script_progression --message="Restoring the logrotate configuration..."
ynh_restore_file --origin_path="/etc/logrotate.d/$app" mkdir -p "/var/log/$app"
chmod 750 "/var/log/$app"
chmod -R o-rwx "/var/log/$app"
chown -R $app:$app "/var/log/$app"
set_permissions ynh_restore_file --origin_path="/etc/logrotate.d/$app"
#================================================= #=================================================
# INTEGRATE SERVICE IN YUNOHOST # INTEGRATE SERVICE IN YUNOHOST
@ -144,7 +139,7 @@ yunohost service add $app --description="Photoview photo manager API" --log="/va
#================================================= #=================================================
ynh_script_progression --message="Starting a systemd service..." --weight=1 ynh_script_progression --message="Starting a systemd service..." --weight=1
ynh_systemd_action --service_name=$app --action="start" --log_path="/var/log/$app/$app.log" ynh_systemd_action --service_name=$app --action="start" --log_path="/var/log/$app/$app.log" --line_match="Photoview UI public endpoint ready"
#================================================= #=================================================
# GENERIC FINALIZATION # GENERIC FINALIZATION

View file

@ -41,6 +41,7 @@ ynh_script_progression --message="Backing up the app before upgrading (may take
# Backup the current version of the app # Backup the current version of the app
ynh_backup_before_upgrade ynh_backup_before_upgrade
ynh_clean_setup () { ynh_clean_setup () {
ynh_clean_check_starting
# Restore it if the upgrade fails # Restore it if the upgrade fails
ynh_restore_upgradebackup ynh_restore_upgradebackup
} }
@ -54,7 +55,7 @@ ynh_abort_if_errors
#================================================= #=================================================
ynh_script_progression --message="Stopping a systemd service..." --weight=1 ynh_script_progression --message="Stopping a systemd service..." --weight=1
ynh_systemd_action --service_name=$app --action="stop" --log_path="/var/log/$app/$app.log" ynh_systemd_action --service_name=$app --action="stop" --log_path="systemd" --line_match="Stopped Photoview"
#================================================= #=================================================
# ENSURE DOWNWARD COMPATIBILITY # ENSURE DOWNWARD COMPATIBILITY
@ -68,6 +69,25 @@ if ynh_legacy_permissions_exists; then
ynh_app_setting_delete --app=$app --key=is_public ynh_app_setting_delete --app=$app --key=is_public
fi fi
# If .env doesn't exist at right destination, move it
if [ -f "$final_path/.env" ]; then
tmpdir="$(mktemp -d)"
ynh_delete_file_checksum --file="$final_path/output/.env"
cp -af "$final_path/output/.env" "$tmpdir/.env"
ynh_secure_remove --file="$final_path"
mkdir -p "$final_path"
cp -af "$tmpdir/.env" "$final_path/.env"
ynh_store_file_checksum --file="$final_path/.env"
chmod 400 "$final_path/.env"
chown $app:$app "$final_path/.env"
fi
ynh_remove_go
ynh_remove_nodejs
#================================================= #=================================================
# CREATE DEDICATED USER # CREATE DEDICATED USER
#================================================= #=================================================
@ -84,9 +104,13 @@ if [ "$upgrade_type" == "UPGRADE_APP" ]
then then
ynh_script_progression --message="Upgrading source files..." --weight=5 ynh_script_progression --message="Upgrading source files..." --weight=5
setup_sources ynh_setup_source --dest_dir="$final_path/build-photoview/" --source_id="docker-image-extract"
fi fi
chmod 750 "$final_path"
chmod -R o-rwx "$final_path"
chown -R $app:$app "$final_path"
#================================================= #=================================================
# NGINX CONFIGURATION # NGINX CONFIGURATION
#================================================= #=================================================
@ -105,38 +129,36 @@ ynh_install_app_dependencies $pkg_dependencies
#================================================= #=================================================
# SPECIFIC UPGRADE # SPECIFIC UPGRADE
#================================================= #=================================================
# MAKE INSTALL
if [ "$upgrade_type" == "UPGRADE_APP" ]; then
#================================================= #=================================================
# BUILD LIBHEIF ynh_script_progression --message="Making install..."
#=================================================
ynh_script_progression --message="Compiling libheif..." --weight=70
build_libheif if [ "$upgrade_type" == "UPGRADE_APP" ]
then
#================================================= # Install photoview
# BUILD API pushd $final_path/build-photoview
#================================================= ./docker-image-extract viktorstrate/photoview:$PHOTOVIEW_VERSION
ynh_script_progression --message="Compiling Go API..." --weight=165 popd
mkdir -p "$final_path/live/ui/"
build_api rsync -a "$final_path/build-photoview/output/app/" "$final_path/live/"
rsync -a "$final_path/build-photoview/output/ui/" "$final_path/live/ui/"
#================================================= ynh_secure_remove --file="$final_path/build-photoview"
# BUILD UI
#=================================================
ynh_script_progression --message="Building static UI files..." --weight=45
build_ui
fi fi
chmod 750 "$final_path"
chmod -R o-rwx "$final_path"
chown -R $app:$app "$final_path"
#================================================= #=================================================
# UPDATE A CONFIG FILE # UPDATE A CONFIG FILE
#================================================= #=================================================
ynh_script_progression --message="Updating a configuration file..." ynh_script_progression --message="Updating a configuration file..."
ynh_add_config --template=".env" --destination="$final_path/output/.env" ynh_add_config --template=".env" --destination="$final_path/.env"
set_permissions chmod 400 "$final_path/.env"
chown $app:$app "$final_path/.env"
#================================================= #=================================================
# SETUP SYSTEMD # SETUP SYSTEMD
@ -168,7 +190,7 @@ yunohost service add $app --description="Photoview photo manager API" --log="/va
#================================================= #=================================================
ynh_script_progression --message="Starting a systemd service..." --weight=1 ynh_script_progression --message="Starting a systemd service..." --weight=1
ynh_systemd_action --service_name=$app --action="start" --log_path="/var/log/$app/$app.log" ynh_systemd_action --service_name=$app --action="start" --log_path="/var/log/$app/$app.log" --line_match="Photoview UI public endpoint ready"
#================================================= #=================================================
# RELOAD NGINX # RELOAD NGINX