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
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 42 additions and 36 deletions

View File

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

View File

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