Skip to content

Commit

Permalink
initial idea for how to structure ephemeral deployment moons
Browse files Browse the repository at this point in the history
  • Loading branch information
dosullivan committed Mar 6, 2024
1 parent 33156fe commit 77a3e9b
Show file tree
Hide file tree
Showing 2 changed files with 150 additions and 0 deletions.
43 changes: 43 additions & 0 deletions .github/helpers/create_moon.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
#!/usr/bin/env bash

# this script creates a moon for an ephemeral deployment on a ship.
# assumes gcloud credentials are loaded and gcloud installed.

ship=$1
zone=$2
project=$3

echo "Creating a moon under $ship in $zone of $project"
set -e
set -o pipefail
cmdfile=$(mktemp "${TMPDIR:-/tmp/}moonspawn.XXXXXXXXX")
moondir=$(mktemp "${TMPDIR:-/urbit/}moondir.XXXXXXXXX")
# mktemp only used for generating a random folder name below
cmds='
click -kp /urbit/natmud-mogzod \
(our hoon thread to make a moon here) > $moondir/details ## need to provide actual hoon thread to extract moon name and keys + write to file
moon_name =$(cat $moondir/details | grep "some pattern for getting moon name")
moon_key =$(cat $moondir/details | grep "some pattern for getting moon key")
mkdir $moondir/$moon_name
urbit -w $moondir/$moon_name -k $moon_key ## we need to run this in a detached way
curl ... #some check to see if the moon is up
'
echo "$cmds"
echo "$cmds" >> "$cmdfile"
sshpriv=$(mktemp "${TMPDIR:-/tmp/}ssh.XXXXXXXXX")
sshpub=$sshpriv.pub
echo "$SSH_PUB_KEY" >> "$sshpub"
echo "$SSH_SEC_KEY" >> "$sshpriv"
chmod 600 $sshpub
chmod 600 $sshpriv

gcloud compute \
--project "$project" \
ssh \
--tunnel-through-iap \
--ssh-key-file "$sshpriv" \
--ssh-flag="-T" \
--zone "$zone" --verbosity info \
urb@"$ship" < "$cmdfile"

echo "moon created"
107 changes: 107 additions & 0 deletions .github/workflows/deploy-ephemeral.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,107 @@
name: Deploy Groups (ephemeral)
on:
push:
branches:
- 'do/ephemeral-moons'

#pull_request:

jobs:
build-frontend:
runs-on: ubuntu-latest
name: 'Build Frontend'
steps:
- name: Checkout
uses: actions/checkout@v4

- name: Setup Node.js environment
uses: actions/setup-node@v4
with:
node-version-file: .nvmrc

- name: Install Dependencies
run: npm ci

- working-directory: ./apps/tlon-web
run:
npm run build

- uses: actions/upload-artifact@v4
with:
name: 'ui-dist'
path: apps/tlon-web/dist

glob:
runs-on: ubuntu-latest
name: 'Make a glob'
needs: build-frontend
steps:
- uses: actions/checkout@v4

- uses: actions/download-artifact@v4
with:
name: 'ui-dist'
path: apps/tlon-web/dist
- id: 'auth'
uses: 'google-github-actions/auth@v1'
with:
credentials_json: '${{ secrets.GCP_SERVICE_KEY }}'
- name: 'Set up Cloud SDK'
uses: 'google-github-actions/setup-gcloud@v1'
- name: 'glob'
uses: ./.github/actions/glob
with:
folder: 'apps/tlon-web/dist/*'
docket: 'desk/desk.docket-0'
- name: Commit and Push Glob
run: |
git config --global user.name github-actions
git config --global user.email [email protected]
git add desk/desk.docket-0
git commit -n -m "update glob: ${{ steps.glob.outputs.hash }} [skip actions]" || echo "No changes to commit"
INPUT=${{ env.tag }}
BRANCH=${INPUT:-"staging"}
git pull origin $BRANCH --rebase --autostash
git push
create_moon:
runs-on: ubuntu-latest
name: "Create Moon"
needs: glob
steps:
- uses: actions/checkout@v4
- id: 'auth'
uses: 'google-github-actions/auth@v1'
with:
credentials_json: '${{ secrets.GCP_SERVICE_KEY }}'
- name: 'Set up Cloud SDK'
uses: 'google-github-actions/setup-gcloud@v1'
- id: create_moon
name: Create Moon
run: |
./.github/helpers/create_moon.sh ephemeral-landscape-apps-moon-host us-central1-a mainnet-tlon-other-2d
env:
SSH_SEC_KEY: ${{ secrets.GCP_SSH_SEC_KEY }}
SSH_PUB_KEY: ${{ secrets.GCP_SSH_PUB_KEY }}


deploy:
needs: create_moon
runs-on: ubuntu-latest
name: "Release to ~binnec-dozzod-marnus (canary)"
steps:
- uses: actions/checkout@v4
- id: 'auth'
uses: 'google-github-actions/auth@v1'
with:
credentials_json: '${{ secrets.GCP_SERVICE_KEY }}'
- name: 'Set up Cloud SDK'
uses: 'google-github-actions/setup-gcloud@v1'
- id: deploy
name: Deploy
run:
./.github/helpers/deploy.sh tloncorp/landscape-apps groups ${{ needs.build_test_images.outputs.moon_name }} us-central1-a mainnet-tlon-other-2d
env:
SSH_SEC_KEY: ${{ secrets.GCP_SSH_SEC_KEY }}
SSH_PUB_KEY: ${{ secrets.GCP_SSH_PUB_KEY }}
URBIT_REPO_TAG: ${{ vars.URBIT_REPO_TAG }}

0 comments on commit 77a3e9b

Please sign in to comment.