Update fetch_and_deploy_gh_release usage in docs and templates

Standardize the usage of fetch_and_deploy_gh_release by specifying all arguments, including mode, version, and target directory, in AI.md and template scripts. This clarifies the function's usage and ensures consistency across documentation and install/update templates.
This commit is contained in:
CanbiZ
2026-01-18 17:58:08 +01:00
parent acdf4dbb2a
commit 8f23297604
3 changed files with 54 additions and 170 deletions

View File

@@ -71,7 +71,7 @@ function update_script() {
cp -r /opt/appname/data /opt/appname_data_backup
msg_ok "Backed up Data"
CLEAN_INSTALL=1 fetch_and_deploy_gh_release "appname" "owner/repo"
CLEAN_INSTALL=1 fetch_and_deploy_gh_release "appname" "owner/repo" "tarball" "latest" "/opt/appname"
# Build steps...
@@ -130,7 +130,7 @@ PG_VERSION="16" setup_postgresql
setup_uv
# etc.
fetch_and_deploy_gh_release "appname" "owner/repo"
fetch_and_deploy_gh_release "appname" "owner/repo" "tarball" "latest" "/opt/appname"
msg_info "Setting up Application"
cd /opt/appname
@@ -265,7 +265,7 @@ tar -xzf ${RELEASE}.tar.gz
mv repo-${RELEASE} /opt/myapp
# ✅ CORRECT - use our function
fetch_and_deploy_gh_release "myapp" "owner/repo"
fetch_and_deploy_gh_release "myapp" "owner/repo" "tarball" "latest" "/opt/myapp"
```
### 3. Custom Version-Check Logic
@@ -340,13 +340,13 @@ NODE_VERSION="22" setup_nodejs
msg_ok "Installed Node.js"
msg_info "Updating Application"
CLEAN_INSTALL=1 fetch_and_deploy_gh_release "appname" "owner/repo"
CLEAN_INSTALL=1 fetch_and_deploy_gh_release "appname" "owner/repo" "tarball" "latest" "/opt/appname"
msg_ok "Updated Application"
# ✅ CORRECT - call directly without msg wrapper
NODE_VERSION="22" setup_nodejs
CLEAN_INSTALL=1 fetch_and_deploy_gh_release "appname" "owner/repo"
CLEAN_INSTALL=1 fetch_and_deploy_gh_release "appname" "owner/repo" "tarball" "latest" "/opt/appname"
```
**Functions with built-in messages (NEVER wrap in msg blocks):**
@@ -565,7 +565,7 @@ function update_script() {
msg_ok "Backed up Data"
# 5. Perform clean install
CLEAN_INSTALL=1 fetch_and_deploy_gh_release "appname" "owner/repo"
CLEAN_INSTALL=1 fetch_and_deploy_gh_release "appname" "owner/repo" "tarball" "latest" "/opt/appname"
# 6. Rebuild (if needed)
cd /opt/appname

View File

@@ -37,41 +37,30 @@ function update_script() {
check_container_storage
check_container_resources
# Check if installation exists
if [[ ! -d /opt/[appname] ]]; then
msg_error "No ${APP} Installation Found!"
exit
fi
# check_for_gh_release returns 0 (true) if update available, 1 (false) if not
if check_for_gh_release "[appname]" "[owner/repo]"; then
msg_info "Stopping Service"
systemctl stop [appname]
msg_ok "Stopped Service"
# Optional: Backup important data before update
msg_info "Backing up Data"
cp -r /opt/[appname]/data /opt/[appname]_data_backup 2>/dev/null || true
msg_ok "Backed up Data"
# CLEAN_INSTALL=1 removes old directory before extracting new version
CLEAN_INSTALL=1 fetch_and_deploy_gh_release "[appname]" "[owner/repo]"
CLEAN_INSTALL=1 fetch_and_deploy_gh_release "[appname]" "[owner/repo]" "tarball" "latest" "/opt/[appname]"
# Restore configuration and data (if needed)
msg_info "Restoring Data"
cp -r /opt/[appname]_data_backup/. /opt/[appname]/data/ 2>/dev/null || true
rm -rf /opt/[appname]_data_backup
msg_ok "Restored Data"
# Optional: Run any post-update commands (npm, composer, migrations, etc.)
# cd /opt/[appname] && $STD npm ci --production
# cd /opt/[appname] && $STD composer install --no-dev
# cd /opt/[appname] && $STD php artisan migrate --force
msg_info "Starting Service"
systemctl start [appname]
msg_ok "Started Service"
msg_ok "Updated successfully!"
fi
exit

View File

@@ -5,7 +5,6 @@
# License: MIT | https://github.com/community-scripts/ProxmoxVE/raw/main/LICENSE
# Source: [SOURCE_URL e.g. https://github.com/example/app]
# Import Functions and Setup
source /dev/stdin <<<"$FUNCTIONS_FILE_PATH"
color
verb_ip6
@@ -15,179 +14,73 @@ network_check
update_os
# =============================================================================
# AVAILABLE HELPER FUNCTIONS (from tools.func)
# =============================================================================
#
# LANGUAGE/RUNTIME SETUP (use these, DON'T do manual installation!):
# NODE_VERSION="22" setup_nodejs # Node.js (18, 20, 22)
# PYTHON_VERSION="3.13" setup_uv # Python with uv package manager
# GO_VERSION="1.22" setup_go # Go language
# RUST_CRATES="monolith" setup_rust # Rust
# RUBY_VERSION="3.3" setup_ruby # Ruby
# JAVA_VERSION="21" setup_java # Java (17, 21)
# PHP_VERSION="8.4" setup_php # PHP
#
# DATABASE SETUP (use these instead of manual setup!):
# setup_postgresql # PostgreSQL server
# PG_DB_NAME="mydb" PG_DB_USER="myuser" setup_postgresql_db # Create DB & user
# setup_mariadb # MariaDB server
# MARIADB_DB_NAME="mydb" setup_mariadb_db # Create MariaDB DB
# setup_mysql # MySQL server
# setup_mongodb # MongoDB server
#
# GITHUB RELEASES (PREFERRED - handles versioning automatically!):
# fetch_and_deploy_gh_release "appname" "owner/repo" # Auto-detect mode
# fetch_and_deploy_gh_release "appname" "owner/repo" "binary" # .deb package
# CLEAN_INSTALL=1 fetch_and_deploy_gh_release ... # Clean install (remove old dir first)
#
# UTILITIES:
# import_local_ip # Sets $LOCAL_IP variable (call early!)
# setup_ffmpeg # FFmpeg with codecs
# setup_imagemagick # ImageMagick 7
# setup_hwaccel # GPU acceleration
# setup_docker # Docker Engine
# setup_adminer # Adminer (DB web interface)
# =============================================================================
# DEPENDENCIES
# DEPENDENCIES - Only add app-specific dependencies here!
# Don't add: ca-certificates, curl, gnupg, git, build-essential (handled by build.func)
# =============================================================================
msg_info "Installing Dependencies"
$STD apt install -y \
ca-certificates \
curl \
gnupg
libharfbuzz0b \
fontconfig
msg_ok "Installed Dependencies"
# =============================================================================
# EXAMPLE: Node.js App with PostgreSQL
# SETUP RUNTIMES & DATABASES (if needed)
# =============================================================================
# NODE_VERSION="22" setup_nodejs
# PG_VERSION="17" setup_postgresql
# PG_DB_NAME="myapp" PG_DB_USER="myapp" setup_postgresql_db
# import_local_ip
# Examples (uncomment as needed):
#
# msg_info "Deploying Application"
# fetch_and_deploy_gh_release "myapp" "owner/myapp"
# msg_ok "Deployed Application"
# NODE_VERSION="22" setup_nodejs
# PYTHON_VERSION="3.13" setup_uv
# JAVA_VERSION="17" setup_java
# GO_VERSION="1.22" setup_go
# PHP_VERSION="8.4" PHP_FPM="YES" setup_php
# setup_postgresql # Server only
# setup_mariadb # Server only
#
# msg_info "Installing Dependencies"
# cd /opt/myapp
# $STD npm ci --production
# msg_ok "Installed Dependencies"
# Then set up DB and user:
# PG_DB_NAME="myapp" PG_DB_USER="myapp" setup_postgresql_db
# MARIADB_DB_NAME="myapp" MARIADB_DB_USER="myapp" setup_mariadb_db
# =============================================================================
# DOWNLOAD & DEPLOY APPLICATION
# =============================================================================
# fetch_and_deploy_gh_release modes:
# "tarball" - Source tarball (default if omitted)
# "binary" - .deb package (auto-detects amd64/arm64)
# "prebuild" - Pre-built archive (.tar.gz)
# "singlefile" - Single binary file
#
# msg_info "Configuring Environment"
# cat <<EOF >/opt/myapp/.env
# DATABASE_URL=postgresql://${PG_DB_USER}:${PG_DB_PASS}@localhost/${PG_DB_NAME}
# APP_HOST=${LOCAL_IP}
# APP_PORT=3000
# NODE_ENV=production
# EOF
# msg_ok "Configured Environment"
# Examples:
# fetch_and_deploy_gh_release "myapp" "owner/myapp" "tarball" "latest" "/opt/myapp"
# fetch_and_deploy_gh_release "myapp" "owner/myapp" "binary" "latest" "/tmp"
# fetch_and_deploy_gh_release "myapp" "owner/myapp" "prebuild" "latest" "/opt/myapp" "myapp-*.tar.gz"
# =============================================================================
# EXAMPLE: Python App with uv
# =============================================================================
# PYTHON_VERSION="3.13" setup_uv
# import_local_ip
# msg_info "Deploying Application"
# fetch_and_deploy_gh_release "myapp" "owner/myapp"
# msg_ok "Deployed Application"
#
# msg_info "Installing Dependencies"
# cd /opt/myapp
# $STD uv sync --frozen
# msg_ok "Installed Dependencies"
#
# cat <<EOF >/opt/myapp/.env
# HOST=${LOCAL_IP}
# PORT=8000
# DEBUG=false
# EOF
# =============================================================================
# CREATE SYSTEMD SERVICE
# =============================================================================
msg_info "Creating Service"
cat <<EOF >/etc/systemd/system/[appname].service
[Unit]
Description=[AppName] Service
After=network.target
[Service]
Type=simple
User=root
WorkingDirectory=/opt/[appname]
Environment=NODE_ENV=production
ExecStart=/usr/bin/node /opt/[appname]/server.js
Restart=on-failure
RestartSec=5
[Install]
WantedBy=multi-user.target
EOF
systemctl enable -q --now [appname]
msg_ok "Created Service"
# EOF
# msg_ok "Setup MyApp"
# =============================================================================
# EXAMPLE 3: PHP Application with MariaDB + Nginx
# =============================================================================
# PHP_VERSION="8.4" PHP_FPM="YES" PHP_MODULE="bcmath,curl,gd,intl,mbstring,mysql,xml,zip" setup_php
# setup_composer
# setup_mariadb
# MARIADB_DB_NAME="myapp" MARIADB_DB_USER="myapp" setup_mariadb_db
# import_local_ip
# fetch_and_deploy_gh_release "myapp" "owner/myapp" "prebuild" "latest" "/opt/myapp" "myapp-*.tar.gz"
#
# msg_info "Configuring MyApp"
# cd /opt/myapp
# cp .env.example .env
# sed -i "s|APP_URL=.*|APP_URL=http://${LOCAL_IP}|" .env
# sed -i "s|DB_DATABASE=.*|DB_DATABASE=${MARIADB_DB_NAME}|" .env
# sed -i "s|DB_USERNAME=.*|DB_USERNAME=${MARIADB_DB_USER}|" .env
# sed -i "s|DB_PASSWORD=.*|DB_PASSWORD=${MARIADB_DB_PASS}|" .env
# $STD composer install --no-dev --no-interaction
# chown -R www-data:www-data /opt/myapp
# msg_ok "Configured MyApp"
# =============================================================================
# YOUR APPLICATION INSTALLATION
# =============================================================================
# 1. Setup runtimes and databases FIRST
# 2. Call import_local_ip if you need the container IP
# 3. Use fetch_and_deploy_gh_release to download the app (handles version tracking)
# 4. Configure the application
# 5. Create systemd service
# 6. Finalize with motd_ssh, customize, cleanup_lxc
# --- Setup runtimes/databases ---
NODE_VERSION="22" setup_nodejs
import_local_ip
# --- Download and install app ---
fetch_and_deploy_gh_release "[appname]" "[owner/repo]" "tarball" "latest" "/opt/[appname]"
msg_info "Setting up [AppName]"
cd /opt/[appname]
$STD npm ci
msg_ok "Setup [AppName]"
# =============================================================================
# CONFIGURATION
# CONFIGURE APPLICATION
# =============================================================================
msg_info "Configuring [AppName]"
cd /opt/[appname]
# Install application dependencies (uncomment as needed):
# $STD npm ci --production # Node.js apps
# $STD uv sync --frozen # Python apps
# $STD composer install --no-dev # PHP apps
# $STD cargo build --release # Rust apps
# Create .env file if needed:
cat <<EOF >/opt/[appname]/.env
HOST=${LOCAL_IP}
# Use import_local_ip to get container IP, or hardcode if building on Proxmox
APP_URL=http://localhost
PORT=8080
EOF
msg_ok "Configured [AppName]"
# =============================================================================
# SERVICE CREATION
# CREATE SYSTEMD SERVICE
# =============================================================================
msg_info "Creating Service"
@@ -213,9 +106,11 @@ msg_ok "Created Service"
# =============================================================================
# CLEANUP & FINALIZATION
# =============================================================================
# These are called automatically, but shown here for clarity:
# motd_ssh - Displays service info on SSH login
# customize - Enables optional customizations
# cleanup_lxc - Removes temp files, bash history, logs
motd_ssh
customize
# cleanup_lxc handles: apt autoremove, autoclean, temp files, bash history
cleanup_lxc