π Deploy marmadilemanteater.dev
#202
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# This is a basic workflow to help you get started with Actions | |
name: π Deploy `marmadilemanteater.dev` | |
# Controls when the workflow will run | |
on: | |
schedule: | |
- cron: "30 1 * * *" | |
# Allows you to run this workflow manually from the Actions tab | |
workflow_dispatch: | |
# Allow one concurrent deployment | |
concurrency: | |
group: "marmadilemanteater-dev" | |
cancel-in-progress: true | |
# A workflow run is made up of one or more jobs that can run sequentially or in parallel | |
jobs: | |
# This workflow contains a single job called "build" | |
build: | |
# The type of runner that the job will run on | |
runs-on: ubuntu-latest | |
# Steps represent a sequence of tasks that will be executed as part of the job | |
steps: | |
# Checks-out your repository under $GITHUB_WORKSPACE, so your job can access it | |
- uses: actions/checkout@v3 | |
- name: β¬ Download SimpleReverseProxy artifact | |
uses: dawidd6/action-download-artifact@v2 | |
with: | |
github_token: ${{ secrets.PERSONAL_ACCESS_TOKEN }} | |
workflow: main.yml | |
workflow_conclusion: success | |
branch: development | |
path: ./artifacts/ | |
# only download the version built for OpenSSL 1.1.1f because it is what I am running on my linode | |
name: SimpleReverseProxy-openssl1.1.1f | |
repo: MarmadileManteater/SimpleReverseProxy | |
check_artifacts: false | |
search_artifacts: false | |
skip_unpack: false | |
if_no_artifact_found: fail | |
- name: Get the latest FT Cordova release | |
run: | | |
FT_DOWNLOAD_URL=$(curl --request GET --url "https://api.github.com/repos/MarmadileManteater/FreeTubeCordova/releases" --header "Authorization: Bearer ${{ secrets.PERSONAL_ACCESS_TOKEN }}" | jq '.[0].assets[1].browser_download_url') | |
curl -L --request GET --url ${FT_DOWNLOAD_URL:1:-1} --header "Authorization: Bearer ${{ secrets.PERSONAL_ACCESS_TOKEN }}" -o ftc.zip | |
- name: π€ Unzip FreeTubeCordova artifact | |
run: | | |
unzip -qq ./ftc.zip -d ./artifacts/public/freetube | |
- name: Make hrefs in FTcordova absolute links | |
run: | | |
sed -i -e 's@href="@href="/freetube/@g' ./artifacts/public/freetube/index.html | |
sed -i -e 's@src="@src="/freetube/@g' ./artifacts/public/freetube/index.html | |
- name: β¬ Download SvelteKitSite artifact | |
uses: dawidd6/action-download-artifact@v2 | |
with: | |
github_token: ${{ secrets.GITHUB_TOKEN }} | |
workflow: main.yml | |
workflow_conclusion: success | |
branch: development | |
path: . | |
name: MarmadileManteaterSvelteStatic | |
repo: MarmadileManteater/SvelteKitSite | |
check_artifacts: false | |
search_artifacts: false | |
skip_unpack: false | |
if_no_artifact_found: fail | |
- name: π€ Unzip SvelteKitSite artifact | |
uses: montudor/action-zip@v1 | |
with: | |
args: unzip -qq static-adapter.zip -d ./artifacts/ | |
- name: Rename artifact folder | |
run: | | |
sudo chown -R $(whoami) . | |
mv ./artifacts/static-adapter ./artifacts/public/sveltekitsite | |
cp -r ./artifacts/public/freetube ./artifacts/public/sveltekitsite/ | |
- name: π Move data.json to artifact folder | |
run: | | |
mv ./marmadilemanteater.dev/data.json ./artifacts/ | |
- name: π€ Zip up artifacts directory for πfaster uploads | |
uses: montudor/action-zip@v1 | |
with: | |
args: zip -r artifacts.zip ./artifacts | |
- name: π¦ Publish artifact | |
uses: actions/upload-artifact@v3 | |
with: | |
name: MarmadileManteater.dev | |
path: artifacts.zip | |
- name: π Install SSH Key | |
uses: shimataro/ssh-key-action@v2 | |
with: | |
key: ${{ secrets.SSH_PRIVATE_KEY }} | |
known_hosts: 'just-a-placeholder' | |
- name: Add known hosts | |
run: ssh-keyscan -H ${{ secrets.LINODE_IP_ADDRESS }} >> ~/.ssh/known_hosts | |
- name: π Deploy with scp | |
run: scp artifacts.zip ${{ secrets.SSH_USER }}@${{ secrets.LINODE_IP_ADDRESS }}:~/ | |
- name: πͺ Kill any running tmux sessions on my linode | |
continue-on-error: true | |
run: | | |
ssh -t ${{ secrets.SSH_USER }}@${{ secrets.LINODE_IP_ADDRESS }} 'tmux kill-session -tsimple-rust-site' | |
ssh -t ${{ secrets.SSH_USER }}@${{ secrets.LINODE_IP_ADDRESS }} 'tmux kill-session -tsvelte-kit-site' | |
- name: π€ Unzip the artifacts on my linode | |
run: | | |
ssh -t ${{ secrets.SSH_USER }}@${{ secrets.LINODE_IP_ADDRESS }} 'rm marmadilemanteater.dev -r' | |
ssh -t ${{ secrets.SSH_USER }}@${{ secrets.LINODE_IP_ADDRESS }} 'unzip -qq artifacts.zip -d .' | |
ssh -t ${{ secrets.SSH_USER }}@${{ secrets.LINODE_IP_ADDRESS }} 'mv artifacts marmadilemanteater.dev' | |
ssh -t ${{ secrets.SSH_USER }}@${{ secrets.LINODE_IP_ADDRESS }} 'ln -s ~/marmadilemanteater.dev/public/freetube/ ~/marmadilemanteater.dev/public/sveltekitsite/freetube' | |
ssh -t ${{ secrets.SSH_USER }}@${{ secrets.LINODE_IP_ADDRESS }} 'rm artifacts.zip' | |
- name: π Allow simple_rust_site to be executed | |
run: | | |
ssh -t ${{ secrets.SSH_USER }}@${{ secrets.LINODE_IP_ADDRESS }} 'cd marmadilemanteater.dev && chmod +x simple_rust_site' | |
- name: β¨ Start tmux session for SimpleReverseProxy | |
run: | | |
ssh -tt ${{ secrets.SSH_USER }}@${{ secrets.LINODE_IP_ADDRESS }} "tmux new -d -s simple-rust-site" | |
ssh -tt ${{ secrets.SSH_USER }}@${{ secrets.LINODE_IP_ADDRESS }} "tmux send-keys -tsimple-rust-site 'cd marmadilemanteater.dev' Enter" | |
# this is a little hacky, but it is important to note I am avoiding accidentally storing the agent's password in `.bash_history` by putting a space before the commands | |
ssh -tt ${{ secrets.SSH_USER }}@${{ secrets.LINODE_IP_ADDRESS }} " echo \"${{ secrets.SUDO_PASSWORD }}\" >> password.txt " | |
ssh -tt ${{ secrets.SSH_USER }}@${{ secrets.LINODE_IP_ADDRESS }} 'tmux send-keys -tsimple-rust-site " sudo -S <<< \"\$(cat ../password.txt)\" ./simple_rust_site ../fullchain.pem ../privkey.pem ./data.json" Enter && sleep 2s && rm password.txt' |