From b449376119c1b6706e714ea5354abd4581572311 Mon Sep 17 00:00:00 2001 From: albert Date: Thu, 28 Nov 2024 18:19:28 +0100 Subject: [PATCH] Update workflows --- .../manual-deploy-rs.yml} | 6 +- .../{ => cron}/update-flake-lock.yml | 4 +- .../workflows/{ => cron}/update-steamdeck.yml | 4 +- .../workflows/dispatch/manual-deploy-rs.yml | 121 ++++++++++++++++++ .../workflows/dispatch/update-flake-lock.yml | 116 +++++++++++++++++ .../workflows/dispatch/update-steamdeck.yml | 118 +++++++++++++++++ 6 files changed, 358 insertions(+), 11 deletions(-) rename .forgejo/workflows/{deploy-rs.yml => cron/manual-deploy-rs.yml} (96%) rename .forgejo/workflows/{ => cron}/update-flake-lock.yml (98%) rename .forgejo/workflows/{ => cron}/update-steamdeck.yml (98%) create mode 100644 .forgejo/workflows/dispatch/manual-deploy-rs.yml create mode 100644 .forgejo/workflows/dispatch/update-flake-lock.yml create mode 100644 .forgejo/workflows/dispatch/update-steamdeck.yml diff --git a/.forgejo/workflows/deploy-rs.yml b/.forgejo/workflows/cron/manual-deploy-rs.yml similarity index 96% rename from .forgejo/workflows/deploy-rs.yml rename to .forgejo/workflows/cron/manual-deploy-rs.yml index 981ea779..d76de229 100644 --- a/.forgejo/workflows/deploy-rs.yml +++ b/.forgejo/workflows/cron/manual-deploy-rs.yml @@ -1,13 +1,11 @@ # yamllint disable rule:line-length rule:truthy --- -name: deploy-rs +name: Cron - deploy-rs run-name: ${{ github.actor }} - deploy-rs on: schedule: - cron: '0 2 * * 0' # “At 02:00 Sunday." - workflow_dispatch: - inputs: jobs: deploy-rs: @@ -56,8 +54,6 @@ jobs: echo "${{ secrets.SSH_PUBLIC_KEY }}" > /root/.ssh/id_ed25519.pub echo "${{ secrets.SSH_PRIVATE_KEY }}" > /root/.ssh/id_ed25519 chmod 700 /root/.ssh - chmod 600 /root/.ssh/id_ed25519 - chmod 644 /root/.ssh/id_ed25519.pub - name: "Setup: Headscale Network" run: | diff --git a/.forgejo/workflows/update-flake-lock.yml b/.forgejo/workflows/cron/update-flake-lock.yml similarity index 98% rename from .forgejo/workflows/update-flake-lock.yml rename to .forgejo/workflows/cron/update-flake-lock.yml index 772e3b4f..f6f5eb3c 100644 --- a/.forgejo/workflows/update-flake-lock.yml +++ b/.forgejo/workflows/cron/update-flake-lock.yml @@ -1,13 +1,11 @@ # yamllint disable rule:line-length rule:truthy --- -name: update-flake-lock +name: Cron - Flake Lock Update run-name: ${{ github.actor }} - update-flake-lock on: schedule: - cron: '0 0 * * 0' # “At 00:00 Sunday." - workflow_dispatch: - inputs: jobs: update-flake-lock: runs-on: ubuntu diff --git a/.forgejo/workflows/update-steamdeck.yml b/.forgejo/workflows/cron/update-steamdeck.yml similarity index 98% rename from .forgejo/workflows/update-steamdeck.yml rename to .forgejo/workflows/cron/update-steamdeck.yml index 39a50358..9458102a 100644 --- a/.forgejo/workflows/update-steamdeck.yml +++ b/.forgejo/workflows/cron/update-steamdeck.yml @@ -1,13 +1,11 @@ # yamllint disable rule:line-length rule:truthy --- -name: update-steamdeck +name: Cron - Update Steam Deck run-name: ${{ github.actor }} - update-steamdeck on: schedule: - cron: '0 2 * * 1' # “At 02:00 Monday" - workflow_dispatch: - inputs: jobs: deploy-rs: diff --git a/.forgejo/workflows/dispatch/manual-deploy-rs.yml b/.forgejo/workflows/dispatch/manual-deploy-rs.yml new file mode 100644 index 00000000..257aec17 --- /dev/null +++ b/.forgejo/workflows/dispatch/manual-deploy-rs.yml @@ -0,0 +1,121 @@ +# yamllint disable rule:line-length rule:truthy +--- +name: Cron - deploy-rs +run-name: ${{ github.actor }} - deploy-rs +on: + workflow_dispatch: + inputs: + +jobs: + deploy-rs: + runs-on: ubuntu + container: + image: ubuntu:24.04 + options: --mount type=bind,src=/dev/net/tun,dst=/dev/net/tun --privileged + steps: + - name: "Runner: Info" + run: | + set -x + pwd + ls -lah + id + uname -a + hostname + cat /etc/os-release + whoami + id + cat /etc/resolv.conf + + - name: "Setup: Runner" + run: | + set -x + echo 'Why is nothing being output here' + apt update -y + apt install git nodejs nix-bin sudo curl -y + git config --global user.email ${{github.actor}} + git config --global user.name "Forgejo Runner" + echo "100.64.0.13 gotify.sysctl.io" >> /etc/hosts + + - name: "Setup: Tailscale Repo" + run: | + set -x + mkdir -p --mode=0755 /usr/share/keyrings + curl -fsSL https://pkgs.tailscale.com/stable/ubuntu/lunar.noarmor.gpg | sudo tee /usr/share/keyrings/tailscale-archive-keyring.gpg >/dev/null + curl -fsSL https://pkgs.tailscale.com/stable/ubuntu/lunar.tailscale-keyring.list | sudo tee /etc/apt/sources.list.d/tailscale.list + apt update -y + apt install tailscale -y + + - name: "Setup: SSH" + run: | + set -x + rm -rf /root/.ssh + mkdir /root/.ssh + echo "${{ secrets.SSH_PUBLIC_KEY }}" > /root/.ssh/id_ed25519.pub + echo "${{ secrets.SSH_PRIVATE_KEY }}" > /root/.ssh/id_ed25519 + chmod 700 /root/.ssh + + - name: "Setup: Headscale Network" + run: | + set -x + sudo tailscaled --cleanup + sudo tailscaled --state=mem: 2> ~/tailscaled.log & + sudo tailscale up \ + --login-server=https://headscale.sysctl.io \ + --accept-routes \ + --accept-dns \ + --authkey ${{ secrets.TAILSCALE_KEY }} \ + --hostname forgejo-runner \ + --advertise-tags "tag:forgejo,tag:container,tag:ephemeral" + sudo tailscale status + sudo tailscale netcheck + + - name: "nixos-version (Pre)" + run: | + ssh -q -A -o StrictHostKeyChecking=no albert@warsaw-ovh-01 \ + " + nixos-version + " + + - name: "SSH and Deploy" + run: | + ssh -q -A -o StrictHostKeyChecking=no albert@warsaw-ovh-01 \ + " + set -x + eval (ssh-agent -c) + ssh-add + env | grep SSH + cd /etc/nixos/git + git pull + ssh -qA osaka-linode-01 'sudo systemctl restart podman-derp' + ssh -qA frankfurt-linode-01 'sudo systemctl restart podman-derp' + ssh -qA milan-linode-01 'sudo systemctl restart podman-derp' + ssh -qA warsaw-ovh-01 'sudo systemctl restart container@rdesktop' + sleep 30 + deploy -sd + deploy -sd + " + + - name: "nixos-version (Post)" + run: | + ssh -q -A -o StrictHostKeyChecking=no albert@warsaw-ovh-01 \ + " + nixos-version + " + tailscale down + + - if: success() + uses: https://git.sysctl.io/actions/gotify-action@master + with: + gotify_api_base: '${{ secrets.GOTIFY_URL }}' + gotify_app_token: '${{ secrets.GOTIFY_TOKEN }}' + notification_title: '[ ${{ github.repository }}: ${{ github.workflow }} ] NixOS Deployed' + notification_message: 'Deployment completed successfully.' + name: "Send Notification - Success" + - if: failure() + uses: https://git.sysctl.io/actions/gotify-action@master + with: + gotify_api_base: '${{ secrets.GOTIFY_URL }}' + gotify_app_token: '${{ secrets.GOTIFY_TOKEN }}' + notification_title: '[ ${{ github.repository }}: ${{ github.workflow }} ] Deployment Failed' + notification_message: 'Your deployment has failed. Check Forgejo.' + name: "Send Notification - Failure" diff --git a/.forgejo/workflows/dispatch/update-flake-lock.yml b/.forgejo/workflows/dispatch/update-flake-lock.yml new file mode 100644 index 00000000..aa3fcc98 --- /dev/null +++ b/.forgejo/workflows/dispatch/update-flake-lock.yml @@ -0,0 +1,116 @@ +# yamllint disable rule:line-length rule:truthy +--- +name: Dispatch - Update Flake Lock +run-name: ${{ github.actor }} - update-flake-lock +on: + workflow_dispatch: + inputs: +jobs: + update-flake-lock: + runs-on: ubuntu + container: + image: ubuntu:24.04 + options: --mount type=bind,src=/dev/net/tun,dst=/dev/net/tun --privileged + steps: + - name: "Runner: Info" + run: | + set -x + pwd + ls -lah + id + uname -a + hostname + cat /etc/os-release + whoami + id + cat /etc/resolv.conf + + - name: "Setup: Runner" + run: | + apt update -y + apt install git nodejs nix-bin sudo curl -y + git config --global user.email "${{github.actor}}" + git config --global user.name "Forgejo Runner" + echo "100.64.0.13 gotify.sysctl.io" >> /etc/hosts + + - name: "Setup: Tailscale Repo" + run: | + mkdir -p --mode=0755 /usr/share/keyrings + curl -fsSL https://pkgs.tailscale.com/stable/ubuntu/lunar.noarmor.gpg | sudo tee /usr/share/keyrings/tailscale-archive-keyring.gpg >/dev/null + curl -fsSL https://pkgs.tailscale.com/stable/ubuntu/lunar.tailscale-keyring.list | sudo tee /etc/apt/sources.list.d/tailscale.list + apt update -y + apt install tailscale -y + + - name: "Setup: SSH" + run: | + rm -rf /root/.ssh + mkdir /root/.ssh + echo "${{ secrets.SSH_PUBLIC_KEY }}" > /root/.ssh/id_ed25519.pub + echo "${{ secrets.SSH_PRIVATE_KEY }}" > /root/.ssh/id_ed25519 + chmod 700 /root/.ssh + chmod 600 /root/.ssh/id_ed25519 + chmod 644 /root/.ssh/id_ed25519.pub + + - name: "Setup: Headscale Network" + run: | + echo "tailscaled --cleanup" + sudo tailscaled --cleanup + echo "" + echo "tailscaled --state=mem 2> ~/tailscaled.log &" + sudo tailscaled --state=mem: 2> ~/tailscaled.log & + echo "" + echo "tailscale up" + sudo tailscale up \ + --login-server=https://headscale.sysctl.io \ + --accept-routes \ + --accept-dns \ + --authkey ${{ secrets.TAILSCALE_KEY }} \ + --hostname forgejo-runner \ + --advertise-tags "tag:forgejo,tag:container,tag:ephemeral" + sudo tailscale status + sudo tailscale netcheck + + + - name: "SSH and Update / Check" + run: | + ssh -q -A -o StrictHostKeyChecking=no albert@warsaw-ovh-01 \ + " + set -x + eval (ssh-agent -c) + ssh-add + env | grep SSH + cd /etc/nixos/git + git pull + nix flake update + nix flake check --show-trace + " + + - if: success() + name: "Sucess: Git Commit & Push" + run: | + ssh -q -A -o StrictHostKeyChecking=no albert@warsaw-ovh-01 \ + " + set -x + eval (ssh-agent -c) + ssh-add + env | grep SSH + cd /etc/nixos/git + git -c commit.gpgsign=false commit -am '[ACTIONS] Flake Update (`date +%Y-%m-%d`)' \ + && git push + " + + - if: success() + uses: https://git.sysctl.io/actions/gotify-action@master + with: + gotify_api_base: '${{ secrets.GOTIFY_URL }}' + gotify_app_token: '${{ secrets.GOTIFY_TOKEN }}' + notification_title: '[ ${{ github.repository }}: ${{ github.workflow }} ] NixOS Flake Updated' + notification_message: 'Build completed successfully.' + - if: failure() + uses: https://git.sysctl.io/actions/gotify-action@master + with: + gotify_api_base: '${{ secrets.GOTIFY_URL }}' + gotify_app_token: '${{ secrets.GOTIFY_TOKEN }}' + notification_title: '[ ${{ github.repository }}: ${{ github.workflow }} ] Build Failed' + notification_message: 'Your build has failed. Check Forgejo.' + name: "Send Notification" diff --git a/.forgejo/workflows/dispatch/update-steamdeck.yml b/.forgejo/workflows/dispatch/update-steamdeck.yml new file mode 100644 index 00000000..ae2bdd44 --- /dev/null +++ b/.forgejo/workflows/dispatch/update-steamdeck.yml @@ -0,0 +1,118 @@ +# yamllint disable rule:line-length rule:truthy +--- +name: Dispatch - Update Steam Deck +run-name: ${{ github.actor }} - update-steamdeck +on: + workflow_dispatch: + inputs: + +jobs: + deploy-rs: + runs-on: ubuntu + container: + image: ubuntu:23.10 + options: --mount type=bind,src=/dev/net/tun,dst=/dev/net/tun --privileged + steps: + - name: "Runner: Info" + run: | + set -x + pwd + ls -lah + id + uname -a + hostname + cat /etc/os-release + whoami + id + cat /etc/resolv.conf + + - name: "Setup: Runner" + run: | + apt update -y + apt install git nodejs nix-bin sudo sudo curl -y + git config user.email "${{github.actor}}" + git config user.name "Forgejo Runner" + echo "100.64.0.13 gotify.sysctl.io" >> /etc/hosts + + - name: "Setup: Tailscale Repo" + run: | + mkdir -p --mode=0755 /usr/share/keyrings + curl -fsSL https://pkgs.tailscale.com/stable/ubuntu/lunar.noarmor.gpg | sudo tee /usr/share/keyrings/tailscale-archive-keyring.gpg >/dev/null + curl -fsSL https://pkgs.tailscale.com/stable/ubuntu/lunar.tailscale-keyring.list | sudo tee /etc/apt/sources.list.d/tailscale.list + apt update -y + apt install tailscale -y + + - name: "Setup: SSH" + run: | + rm -rf /root/.ssh + mkdir /root/.ssh + echo "${{ secrets.SSH_PUBLIC_KEY }}" > /root/.ssh/id_ed25519.pub + echo "${{ secrets.SSH_PRIVATE_KEY }}" > /root/.ssh/id_ed25519 + chmod 700 /root/.ssh + chmod 600 /root/.ssh/id_ed25519 + chmod 644 /root/.ssh/id_ed25519.pub + echo "Public Key: " + cat /root/.ssh/id_ed25519.pub + + - name: "Setup: Headscale Network" + run: | + echo "tailscaled --cleanup" + sudo tailscaled --cleanup + echo "" + echo "tailscaled --state=mem 2> ~/tailscaled.log &" + sudo tailscaled --state=mem: 2> ~/tailscaled.log & + echo "" + echo "tailscale up" + sudo tailscale up \ + --login-server=https://headscale.sysctl.io \ + --accept-routes \ + --accept-dns \ + --authkey ${{ secrets.TAILSCALE_KEY }} \ + --hostname forgejo-runner \ + --advertise-tags "tag:forgejo,tag:container,tag:ephemeral" + sudo tailscale status + sudo tailscale netcheck + + - name: "nixos-version (Pre)" + run: | + ssh -q -A -o StrictHostKeyChecking=no albert@steamdeck \ + " + nixos-version + " + + - name: "SSH and Deploy" + run: | + ssh -o StrictHostKeyChecking=no albert@steamdeck \ + " + set -x + source ~/.config/fish/config.fish + cd /etc/nixos/git + git pull + sudo nixos-rebuild switch --flake /etc/nixos/git + home-manager switch -b backup --flake /etc/nixos/git + " + + - name: "nixos-version (Post)" + run: | + ssh -q -A -o StrictHostKeyChecking=no albert@steamdeck \ + " + nixos-version + " + tailscale down + + - if: success() + uses: https://git.sysctl.io/actions/gotify-action@master + with: + gotify_api_base: '${{ secrets.GOTIFY_URL }}' + gotify_app_token: '${{ secrets.GOTIFY_TOKEN }}' + notification_title: '[ ${{ github.repository }}: ${{ github.workflow }} ] Steam Deck Updated' + notification_message: 'Deployment completed successfully.' + name: "Send Notification - Success" + - if: failure() + uses: https://git.sysctl.io/actions/gotify-action@master + with: + gotify_api_base: '${{ secrets.GOTIFY_URL }}' + gotify_app_token: '${{ secrets.GOTIFY_TOKEN }}' + notification_title: '[ ${{ github.repository }}: ${{ github.workflow }} ] Deployment Failed' + notification_message: 'Your deployment has failed. Check Forgejo.' + name: "Send Notification - Failure"