2023-12-25 03:32:41 +01:00
|
|
|
name: deploy-rs
|
2023-12-25 03:30:44 +01:00
|
|
|
run-name: ${{ github.actor }} - deploy-rs
|
|
|
|
on:
|
2024-04-16 07:46:40 +02:00
|
|
|
schedule:
|
2024-05-21 10:43:59 +02:00
|
|
|
- cron: '0 2 * * 0'
|
|
|
|
# “At 02:00 Sunday."
|
2023-12-25 08:48:57 +01:00
|
|
|
|
2023-12-25 03:30:44 +01:00
|
|
|
jobs:
|
2023-12-25 03:32:41 +01:00
|
|
|
deploy-rs:
|
2024-04-05 01:26:10 +02:00
|
|
|
runs-on: ubuntu
|
2023-12-25 05:44:31 +01:00
|
|
|
container:
|
2024-04-05 01:26:10 +02:00
|
|
|
image: ubuntu:23.10
|
2023-12-25 05:44:31 +01:00
|
|
|
options: --mount type=bind,src=/dev/net/tun,dst=/dev/net/tun --privileged
|
2023-12-25 03:30:44 +01:00
|
|
|
steps:
|
|
|
|
- name: "Runner: Info"
|
|
|
|
run: |
|
2024-01-10 02:38:04 +01:00
|
|
|
set -x
|
2023-12-25 03:30:44 +01:00
|
|
|
pwd
|
|
|
|
ls -lah
|
|
|
|
id
|
|
|
|
uname -a
|
|
|
|
hostname
|
|
|
|
cat /etc/os-release
|
|
|
|
whoami
|
|
|
|
id
|
|
|
|
cat /etc/resolv.conf
|
|
|
|
|
2023-12-25 05:44:31 +01:00
|
|
|
- name: "Setup: Runner"
|
|
|
|
run: |
|
2024-04-08 04:23:23 +02:00
|
|
|
apt update -y
|
2024-04-16 07:24:10 +02:00
|
|
|
apt install git nodejs nix-bin sudo sudo curl -y
|
2024-04-08 04:23:23 +02:00
|
|
|
git config --global user.email "${{github.actor}}"
|
2024-04-24 04:17:10 +02:00
|
|
|
git config --global user.name "Forgejo Runner"
|
2024-04-24 02:30:25 +02:00
|
|
|
echo "100.64.0.14 gotify.sysctl.io" >> /etc/hosts
|
2024-04-13 16:33:14 +02:00
|
|
|
|
2024-04-16 07:24:10 +02:00
|
|
|
- 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
|
2024-04-16 07:26:00 +02:00
|
|
|
apt update -y
|
2024-04-16 07:24:10 +02:00
|
|
|
apt install tailscale -y
|
2024-04-15 03:36:03 +02:00
|
|
|
|
2023-12-25 05:44:31 +01:00
|
|
|
- name: "Setup: SSH"
|
|
|
|
run: |
|
2024-04-09 01:15:15 +02:00
|
|
|
rm -rf /root/.ssh
|
2023-12-25 05:44:31 +01:00
|
|
|
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
|
|
|
|
|
2024-04-13 16:33:14 +02:00
|
|
|
- name: "Setup: Headscale Network"
|
2023-12-25 03:30:44 +01:00
|
|
|
run: |
|
2023-12-25 05:44:31 +01:00
|
|
|
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
|
2023-12-25 03:30:44 +01:00
|
|
|
|
2024-01-16 00:43:14 +01:00
|
|
|
- name: "nixos-version (Pre)"
|
|
|
|
run: |
|
2024-01-22 07:47:41 +01:00
|
|
|
ssh -q -A -o StrictHostKeyChecking=no albert@framework-server \
|
2024-01-16 00:43:14 +01:00
|
|
|
"
|
|
|
|
nixos-version
|
|
|
|
"
|
|
|
|
|
2023-12-25 08:59:27 +01:00
|
|
|
- name: "SSH and Deploy"
|
2023-12-25 05:44:31 +01:00
|
|
|
run: |
|
2024-01-22 07:47:41 +01:00
|
|
|
ssh -q -A -o StrictHostKeyChecking=no albert@framework-server \
|
2023-12-25 08:15:03 +01:00
|
|
|
"
|
2024-05-03 04:03:50 +02:00
|
|
|
set -x
|
2024-05-03 03:28:09 +02:00
|
|
|
eval (ssh-agent -c)
|
2024-05-03 03:24:34 +02:00
|
|
|
ssh-add
|
|
|
|
env | grep SSH
|
2023-12-25 08:15:03 +01:00
|
|
|
cd /etc/nixos/git
|
|
|
|
git pull
|
2024-05-03 04:44:50 +02:00
|
|
|
deploy -d
|
2023-12-25 08:15:03 +01:00
|
|
|
"
|
2023-12-25 03:30:44 +01:00
|
|
|
|
2024-01-16 00:43:14 +01:00
|
|
|
- name: "nixos-version (Post)"
|
|
|
|
run: |
|
2024-01-22 07:47:41 +01:00
|
|
|
ssh -q -A -o StrictHostKeyChecking=no albert@framework-server \
|
2024-01-16 00:43:14 +01:00
|
|
|
"
|
|
|
|
nixos-version
|
|
|
|
"
|
2024-04-16 07:35:56 +02:00
|
|
|
tailscale down
|
2024-01-16 00:43:14 +01:00
|
|
|
|
2023-12-25 03:34:04 +01:00
|
|
|
- if: success()
|
2023-12-25 03:30:44 +01:00
|
|
|
uses: https://git.sysctl.io/actions/gotify-action@master
|
|
|
|
with:
|
|
|
|
gotify_api_base: '${{ secrets.GOTIFY_URL }}'
|
|
|
|
gotify_app_token: '${{ secrets.GOTIFY_TOKEN }}'
|
2023-12-25 03:34:04 +01:00
|
|
|
notification_title: '[ ${{ github.repository }}: ${{ github.workflow }} ] NixOS Deployed'
|
|
|
|
notification_message: 'Deployment completed successfully.'
|
2023-12-25 03:34:40 +01:00
|
|
|
name: "Send Notification - Success"
|
2023-12-25 03:34:04 +01:00
|
|
|
- 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.'
|
2024-02-16 01:35:01 +01:00
|
|
|
name: "Send Notification - Failure"
|