Refactor: migrate AdventureLog update to uv and GitHub release logic (#5318)

This commit is contained in:
CanbiZ
2025-06-20 11:29:10 +02:00
committed by GitHub
parent bcdeeaafb3
commit f81f7fb1c0
2 changed files with 42 additions and 36 deletions

View File

@ -27,43 +27,51 @@ function update_script() {
msg_error "No ${APP} Installation Found!"
exit
fi
RELEASE=$(curl -fsSL https://api.github.com/repos/seanmorley15/AdventureLog/releases/latest | grep "tag_name" | awk '{print substr($2, 3, length($2)-4) }')
if [[ ! -f /opt/${APP}_version.txt ]] || [[ "${RELEASE}" != "$(cat /opt/${APP}_version.txt)" ]]; then
if [[ "${RELEASE}" != "$(cat ~/.adventurelog 2>/dev/null)" ]] || [[ ! -f ~/.adventurelog ]]; then
msg_info "Stopping Services"
systemctl stop adventurelog-backend
systemctl stop adventurelog-frontend
msg_ok "Services Stopped"
msg_info "Updating ${APP} to ${RELEASE}"
mv /opt/adventurelog/ /opt/adventurelog-backup/
curl -fsSL -o /opt/v${RELEASE}.zip "https://github.com/seanmorley15/AdventureLog/archive/refs/tags/v${RELEASE}.zip"
$STD unzip /opt/v${RELEASE}.zip -d /opt/
mv /opt/AdventureLog-${RELEASE} /opt/adventurelog
fetch_and_deploy_gh_release "adventurelog" "seanmorley15/adventurelog"
PYTHON_VERSION="3.12" setup_uv
msg_info "Updating ${APP} to v${RELEASE}"
# Backend Migration
cp /opt/adventurelog-backup/backend/server/.env /opt/adventurelog/backend/server/.env
cp -r /opt/adventurelog-backup/backend/server/media /opt/adventurelog/backend/server/media
mv /opt/adventurelog-backup/backend/server/.env /opt/adventurelog/backend/server/.env
mv /opt/adventurelog-backup/backend/server/media /opt/adventurelog/backend/server/media
cd /opt/adventurelog/backend/server
$STD pip install --upgrade pip
$STD pip install -r requirements.txt
$STD python3 manage.py collectstatic --noinput
$STD python3 manage.py migrate
if [[ ! -x .venv/bin/python ]]; then
$STD uv venv .venv
$STD .venv/bin/python -m ensurepip --upgrade
fi
mv /opt/adventurelog-backup/frontend/.env /opt/adventurelog/frontend/.env
$STD .venv/bin/python -m pip install --upgrade pip
$STD .venv/bin/python -m pip install -r requirements.txt
$STD .venv/bin/python -m manage collectstatic --noinput
$STD .venv/bin/python -m manage migrate
# Frontend Migration
cp /opt/adventurelog-backup/frontend/.env /opt/adventurelog/frontend/.env
cd /opt/adventurelog/frontend
$STD pnpm install
$STD pnpm run build
echo "${RELEASE}" >/opt/${APP}_version.txt
$STD pnpm i
$STD pnpm build
msg_ok "Updated ${APP}"
msg_info "Starting Services"
systemctl daemon-reexec
systemctl start adventurelog-backend
systemctl start adventurelog-frontend
msg_ok "Started Services"
msg_ok "Services Started"
msg_info "Cleaning Up"
rm -rf /opt/v${RELEASE}.zip
rm -rf /opt/adventurelog-backup
msg_ok "Cleaned"
msg_ok "Updated Successfully"
else
msg_ok "No update required. ${APP} is already at ${RELEASE}"

View File

@ -1,8 +1,7 @@
#!/usr/bin/env bash
# Copyright (c) 2021-2025 tteck
# Author: tteck
# Co-Author: MickLesk (Canbiz)
# Author: MickLesk (CanbiZ)
# License: MIT | https://github.com/community-scripts/ProxmoxVE/raw/main/LICENSE
# Source: https://github.com/seanmorley15/AdventureLog
@ -18,13 +17,12 @@ msg_info "Installing Dependencies"
$STD apt-get install -y \
gdal-bin \
libgdal-dev \
git \
python3-venv \
python3-pip
git
msg_ok "Installed Dependencies"
NODE_VERSION="22" NODE_MODULE="pnpm@latest" setup_nodejs
PG_VERSION="16" PG_MODULES="postgis" setup_postgresql
PYTHON_VERSION="3.12" setup_uv
NODE_VERSION="22" NODE_MODULE="pnpm@latest" install_node_and_modules
PG_VERSION="16" PG_MODULES="postgis" install_postgresql
msg_info "Set up PostgreSQL Database"
DB_NAME="adventurelog_db"
@ -46,15 +44,12 @@ $STD sudo -u postgres psql -c "ALTER ROLE $DB_USER SET timezone TO 'UTC';"
} >>~/adventurelog.creds
msg_ok "Set up PostgreSQL"
fetch_and_deploy_gh_release "adventurelog" "seanmorley15/adventurelog"
msg_info "Installing AdventureLog (Patience)"
DJANGO_ADMIN_USER="djangoadmin"
DJANGO_ADMIN_PASS="$(openssl rand -base64 18 | tr -dc 'a-zA-Z0-9' | cut -c1-13)"
LOCAL_IP="$(hostname -I | awk '{print $1}')"
cd /opt
RELEASE=$(curl -fsSL https://api.github.com/repos/seanmorley15/AdventureLog/releases/latest | grep "tag_name" | awk '{print substr($2, 3, length($2)-4) }')
curl -fsSL "https://github.com/seanmorley15/AdventureLog/archive/refs/tags/v${RELEASE}.zip" -o "v${RELEASE}.zip"
$STD unzip v${RELEASE}.zip
mv AdventureLog-${RELEASE} /opt/adventurelog
cat <<EOF >/opt/adventurelog/backend/server/.env
PGHOST='localhost'
PGDATABASE='${DB_NAME}'
@ -79,11 +74,13 @@ DISABLE_REGISTRATION=False
EOF
cd /opt/adventurelog/backend/server
mkdir -p /opt/adventurelog/backend/server/media
$STD pip install --upgrade pip
$STD pip install -r requirements.txt
$STD python3 manage.py collectstatic --noinput
$STD python3 manage.py migrate
$STD python3 manage.py download-countries
$STD uv venv /opt/adventurelog/backend/server/.venv
$STD /opt/adventurelog/backend/server/.venv/bin/python -m ensurepip --upgrade
$STD /opt/adventurelog/backend/server/.venv/bin/python -m pip install --upgrade pip
$STD /opt/adventurelog/backend/server/.venv/bin/python -m pip install -r requirements.txt
$STD /opt/adventurelog/backend/server/.venv/bin/python -m manage collectstatic --noinput
$STD /opt/adventurelog/backend/server/.venv/bin/python -m manage migrate
$STD /opt/adventurelog/backend/server/.venv/bin/python -m manage download-countries
cat <<EOF >/opt/adventurelog/frontend/.env
PUBLIC_SERVER_URL=http://$LOCAL_IP:8000
BODY_SIZE_LIMIT=Infinity
@ -96,7 +93,8 @@ echo "${RELEASE}" >"/opt/${APPLICATION}_version.txt"
msg_ok "Installed AdventureLog"
msg_info "Setting up Django Admin"
$STD python3 /opt/adventurelog/backend/server/manage.py shell <<EOF
cd /opt/adventurelog/backend/server
$STD .venv/bin/python -m manage shell <<EOF
from django.contrib.auth import get_user_model
UserModel = get_user_model()
user = UserModel.objects.create_user('$DJANGO_ADMIN_USER', password='$DJANGO_ADMIN_PASS')
@ -120,7 +118,7 @@ After=network.target postgresql.service
[Service]
WorkingDirectory=/opt/adventurelog/backend/server
ExecStart=python3 manage.py runserver 0.0.0.0:8000
ExecStart=/opt/adventurelog/backend/server/.venv/bin/python -m manage runserver 0.0.0.0:8000
Restart=always
EnvironmentFile=/opt/adventurelog/backend/server/.env