refactor A LOT

This commit is contained in:
CeciliaKelley33Mm 2024-10-16 17:02:12 +07:00
parent e0848197e0
commit d4b5ce271a
3 changed files with 30 additions and 70 deletions

View file

@ -29,11 +29,6 @@ jobs:
- name: Setup Python (for use with Pool Kit)
uses: actions/setup-python@v5
with:
# pagekite doesn't work with >=3.12
# the version that pagekite said in the docs was 2.7
# but since setup-python removed 2.7 i had to use 3.11,
# which surprisingly works
python-version: '3.11'
- name: Setup Java 21 (Eclipse Temurin)
uses: actions/setup-java@v4
@ -43,7 +38,7 @@ jobs:
- name: Installs some stuff
run: |
sudo apt update -y
sudo apt install git wget docker-compose mosh -y
sudo apt install mosh -y
wget -O /tmp/mega.deb https://mega.nz/linux/repo/xUbuntu_24.04/amd64/megacmd-xUbuntu_24.04_amd64.deb
sudo apt install -y "/tmp/mega.deb"
@ -66,12 +61,6 @@ jobs:
run: |
sudo mkdir /mnt/globalData
sudo chown $(whoami) /mnt/globalData/
- name: Clone the website repo to run the backend server
working-directory: /mnt/globalData
run: |
wget -O archive.zip https://codeload.github.com/CeciliaKelley33Mm/CeciliaKelley33Mm.github.io/zip/refs/heads/main
unzip archive.zip
rm -rf archive.zip
- name: Dump GitHub token, GitHub context and other environment variables to the home directory (useful for debugging purposes)
env:
GITHUB_CONTEXT: ${{ toJSON(github) }}
@ -88,45 +77,11 @@ jobs:
tar xf archive.tar.gz
rm -rf archive.tar.gz
- name: Make new Minecraft Server files if on new runtime
if: ${{ inputs.oldTailscaleHostname == '' }}
run: |
mkdir -p /mnt/globalData/toBackup/minecraft
cd /mnt/globalData/toBackup/minecraft
wget -O docker-compose.yml https://raw.githubusercontent.com/CeciliaKelley33Mm/global/refs/heads/master/minecraft-compose.yml
- name: Start Minecraft Server
working-directory: /mnt/globalData/toBackup/minecraft
run: docker compose up -d &
- name: Setup MUSE
run: |
mkdir /mnt/globalData/muse
cd /mnt/globalData/muse
wget -O docker-compose.yml https://raw.githubusercontent.com/CeciliaKelley33Mm/global/refs/heads/master/muse-compose.yml
sed -i 's/DISCORD_TOKEN_PLACEHOLDER/${{ secrets.DISCORD_TOKEN }}/g' docker-compose.yml
sed -i 's/YOUTUBE_API_KEY_PLACEHOLDER/${{ secrets.YOUTUBE_API_KEY }}/g' docker-compose.yml
sed -i 's/SPOTIFY_CLIENT_ID_PLACEHOLDER/${{ secrets.SPOTIFY_CLIENT_ID }}/g' docker-compose.yml
sed -i 's/SPOTIFY_CLIENT_SECRET_PLACEHOLDER/${{ secrets.SPOTIFY_CLIENT_SECRET }}/g' docker-compose.yml
docker compose up -d &
- name: Setup website backend server
working-directory: /mnt/globalData/CeciliaKelley33Mm.github.io-main/backend
run: |
npm i
node index.js &
- name: Setup Pool Kit
run: |
curl -O https://pagekite.net/pk/pagekite.py
wget https://raw.githubusercontent.com/CeciliaKelley33Mm/global/refs/heads/master/.pagekite.rc
cp .pagekite.rc ~
sed -i 's*KITENAMEPK*${{ secrets.KITENAME }}*g' ~/.pagekite.rc
sed -i 's*KITESECRETPK*${{ secrets.KITESECRET }}*g' ~/.pagekite.rc
python pagekite.py &
- name: Run post-install script (if exists)
working-directory: /mnt/globalData/toBackup
run: |
if [ -f postinstall.sh ]; then
. postinstall.sh
. postinstall.sh &
fi
- name: Run the long-lived process
working-directory: /mnt/globalData

View file

@ -1,5 +1,30 @@
# global
# Global
This repo is responsible for running all the stuff (except [Docker-VNC](https://github.com/CeciliaKelley33Mm/Docker-VNC), which takes up a lot of resources).
### NOTE: this repo is meant to be used for me only. if you somehow stumbled on this, be sure to change some stuff in `runglobal.yml`.
This repository transforms GitHub Actions into a (12 * 2)/(3.5 * 2) s36v36. It is originally a fork of [Docker-VNC](https://github.com/Efebey2903/Docker-VNC), but I got too addicted into this and turned it into another project with a lot more improvements.
# How It Works
During the first runtime, a data directory named `globalData` is created in `/mnt/`, which is [Azure's temporary storage partition](https://learn.microsoft.com/en-us/azure/virtual-machines/managed-disks-overview#temporary-disk). This partition, by default is used for storing the swap file, but also offers a lot of space for storing large files.
Now here's where my stuff comes in. The runtime will make a `globalData` directory in that temporary storage partition. You can store the stuff that you don't want to keep throughout the runtimes inside that folder. But theres also another folder called `toBackup` inside `globalData`. Files in this folder will persist across the runtimes. It also contains these two scripts:
- `postinstall.sh` runs after the runtime finishes setting things up.
- `postruntime.sh` executes 30 minutes before the runtime stops (which has a maximum limit of 6 hours).
You can configure tasks that you want to start or stop at each runtime.
For the `toBackup` data bridge, I first archive the folder into the file `archive.tar.gz`. Then I used [serve](https://github.com/vercel/serve), which runs on the old runtime's port 5000, then on the new runtime, I used [aria2](https://github.com/aria2/aria2) to download the archive in parallel and finally extract the archive.
And with all of this, I also have Discord Webhook integration so you get notified on new runtimes, and [Tail with a Scale](https://tailscale.com/) set up so you can actually access the runtime.
# Why not just use action's [`cron`](https://docs.github.com/en/actions/writing-workflows/workflow-syntax-for-github-actions#onschedule)?
The time is not accurate, which may lead to a downtime gap between each runtime. See [https://github.com/orgs/community/discussions/52477](https://github.com/orgs/community/discussions/52477)
# Secrets that are NEEDED to set
- `WEBHOOK_URL` - discord webhook url
- `TAILSCALE_KEY` - tailscale auth key
I have split the steps in the workflow file as many as I could so hopefully it is not really a big mess

20
loop.sh
View file

@ -88,28 +88,8 @@ check() {
. postruntime.sh
fi
cd /mnt/globalData/toBackup/minecraft
timeLeft=30
while [ $timeLeft -gt 0 ]; do
if [ $(($timeLeft % 10)) -eq 0 ]; then
docker compose exec minecraft rcon-cli broadcast The server will stop and move to a new host in $timeLeft seconds. Please leave the server.
fi
sleep 1
timeLeft=$((timeLeft - 1))
done
# not stopping the server would cause problems
# like new world files not getting written
# or even file corruptions
docker compose down
cd /mnt/globalData
# sudo is necessary because we run minecraft in a docker container
sudo tar cf archive.tar.gz toBackup/
serve -p 5000 &