Skip to content

Commit

Permalink
Merge pull request #76 from fermyon/key-value-backing
Browse files Browse the repository at this point in the history
Update FW to use key-value and sql to run on Fermyon Cloud
  • Loading branch information
adamreese authored Aug 24, 2023
2 parents ab901a5 + 2602aae commit a140e03
Show file tree
Hide file tree
Showing 42 changed files with 1,689 additions and 1,359 deletions.
34 changes: 24 additions & 10 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
@@ -1,29 +1,22 @@
name: Build
on:
push:
branches: [main]
pull_request:
branches: [main]
workflow_call:

jobs:
build:
runs-on: "ubuntu-latest"
services:
redis:
image: redis:7
ports:
- 6379:6379

steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v3

- name: Install Wasm Rust target
run: |
rustup target add wasm32-wasi
- name: Install wasi-vfs
run: |
curl -LOs https://github.com/kateinoigakukun/wasi-vfs/releases/download/v0.1.1/wasi-vfs-cli-x86_64-unknown-linux-gnu.zip
curl -LOs https://github.com/kateinoigakukun/wasi-vfs/releases/download/v0.4.0/wasi-vfs-cli-x86_64-unknown-linux-gnu.zip
unzip wasi-vfs-cli-x86_64-unknown-linux-gnu.zip
mv wasi-vfs /usr/local/bin
Expand All @@ -38,6 +31,17 @@ jobs:
tar zxvf spin-v1.4.1-linux-amd64.tar.gz
mv spin /usr/local/bin
- name: Install node
uses: actions/setup-node@v3
with:
node-version: "18"
cache: "npm"
cache-dependency-path: site/package-lock.json

- name: Install npm dependencies
working-directory: site
run: npm ci

- name: Build
env:
ENABLE_WASM_OPT: false
Expand All @@ -49,3 +53,13 @@ jobs:
TIMEOUT: 1m
run: |
make test-server
- name: Archive app artifacts
uses: actions/upload-artifact@v3
with:
name: app
path: |
spin.toml
components/*.wasm
site/dist/
highscore/migration.sql
116 changes: 22 additions & 94 deletions .github/workflows/deploy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,18 +6,6 @@ on:
- 'main'

workflow_dispatch:
inputs:
ref:
description: 'Git ref to deploy from (refs/tags/v* for tag)'
default: 'refs/heads/main'
commit:
description: 'Commit SHA to deploy from (optional)'
environment:
type: choice
description: 'Environment to deploy to (Default: canary)'
options:
- canary
- prod

# Construct a concurrency group to be shared across workflow runs.
# The default behavior ensures that only one is running at a time, with
Expand All @@ -26,97 +14,37 @@ concurrency: ${{ github.workflow }}

permissions:
contents: read
id-token: write # Allow the workflow to create a JWT for AWS auth

jobs:
echo-inputs:
runs-on: ubuntu-latest
if: ${{ github.event_name == 'workflow_dispatch' }}
steps:
- name: Echo Inputs
run: |
echo ref: ${{ github.event.inputs.ref }}
echo commit: ${{ github.event.inputs.commit }}
echo environment: ${{ github.event.inputs.environment }}
build:
uses: fermyon/finicky-whiskers/.github/workflows/build.yml@main

deploy:
runs-on: ubuntu-latest
needs: build
steps:
- uses: actions/checkout@v3

- name: Install Nomad
env:
NOMAD_VERSION: "1.4.3"
run: |
curl -Os https://releases.hashicorp.com/nomad/${NOMAD_VERSION}/nomad_${NOMAD_VERSION}_linux_$(dpkg --print-architecture).zip
unzip nomad_${NOMAD_VERSION}_linux_$(dpkg --print-architecture).zip -d /usr/local/bin
chmod +x /usr/local/bin/nomad
# This action currently generates a warning due to using deprecated features.
# https://github.com/aws-actions/configure-aws-credentials/issues/521 tracks the new behaviour.
- name: Configure AWS Credentials
uses: aws-actions/configure-aws-credentials@v1
- name: Download build artifacts
uses: actions/download-artifact@v3
with:
role-to-assume: arn:aws:iam::${{ secrets.AWS_ACCOUNT_ID }}:role/${{ secrets.INFRA_NAMESPACE }}-${{ secrets.AWS_REGION }}-gha-certs
role-session-name: fermyon-developer-deploy
aws-region: ${{ secrets.AWS_REGION }}

- name: Fetch Nomad Certs from S3
shell: bash
run: |
set -euo pipefail
for cert in infra_ca \
api_client_cert_private_key \
api_client_cert_public_key; do
name: app
path: "${{ github.workspace }}"

aws s3api get-object \
--bucket "infra-certs-${{ secrets.INFRA_NAMESPACE }}-${{ secrets.AWS_REGION }}" \
--key "${cert}" \
"/tmp/${cert}"
done
- name: Configure Nomad
shell: bash
run: |
echo "NOMAD_CACERT=/tmp/infra_ca" >> $GITHUB_ENV
echo "NOMAD_CLIENT_CERT=/tmp/api_client_cert_public_key" >> $GITHUB_ENV
echo "NOMAD_CLIENT_KEY=/tmp/api_client_cert_private_key" >> $GITHUB_ENV
echo "NOMAD_ADDR=https://nomad.${{ secrets.INFRA_NAMESPACE }}.${{ secrets.AWS_REGION }}.fermyon.link:4646" >> $GITHUB_ENV
- name: Configure manual deploy
if: ${{ github.event_name == 'workflow_dispatch' }}
shell: bash
run: |
echo "GIT_REF=${{ github.event.inputs.ref }}" >> $GITHUB_ENV
echo "GIT_SHA=${{ github.event.inputs.commit }}" >> $GITHUB_ENV
if [[ "${{ github.event.inputs.environment }}" == "prod" ]]; then
echo "PRODUCTION=true" >> $GITHUB_ENV
echo "NOMAD_NAMESPACE=prod" >> $GITHUB_ENV
else
echo "PRODUCTION=false" >> $GITHUB_ENV
echo "NOMAD_NAMESPACE=staging" >> $GITHUB_ENV
fi
- name: Configure auto-deploy
if: ${{ github.event_name == 'push' }}
shell: bash
run: |
echo "GIT_REF=${{ github.ref }}" >> $GITHUB_ENV
echo "GIT_SHA=${{ github.sha }}" >> $GITHUB_ENV
- name: Setup Spin
uses: fermyon/actions/spin/setup@v1
with:
version: v1.4.1

echo "PRODUCTION=true" >> $GITHUB_ENV
echo "NOMAD_NAMESPACE=prod" >> $GITHUB_ENV
- name: Login to Fermyon Cloud
run: spin cloud login --token "${{ secrets.FERMYAPPS_CLOUD_TOKEN }}"

- name: Deploy
shell: bash
- name: Run sqlite migration(s)
run: |
set -euo pipefail
# NOTE: workaround for not being able to use 'default' as the database name
SQLITE_DB_NAME="$(spin cloud sqlite list | grep 'default' | cut -d ' ' -f1)"
spin cloud sqlite execute "$SQLITE_DB_NAME" "@highscore/migration.sql"
nomad run \
-var "region=${{ secrets.AWS_REGION }}" \
-var "production=${{ env.PRODUCTION }}" \
-var "git_ref=${{ env.GIT_REF }}" \
-var "commit_sha=${{ env.GIT_SHA }}" \
deploy/finicky-whiskers.nomad
- name: Deploy to Fermyon Cloud
uses: fermyon/actions/spin/deploy@v1
with:
run_build: false
fermyon_token: "${{ secrets.FERMYAPPS_CLOUD_TOKEN }}"
96 changes: 0 additions & 96 deletions .github/workflows/restart.yml

This file was deleted.

2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
.spin/
tally/target/*
scoreboard/target/*
highscore/target/*
reset/target/*
site/.parcel-cache/
site/dist/
site/node_modules/
Expand Down
10 changes: 1 addition & 9 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,6 @@ build:
serve:
./serve.sh

.PHONY: start-redis
start-redis:
@docker start fw-redis &>/dev/null || docker run -p 6379:6379 --name fw-redis redis:7 &

.PHONY: stop-redis
stop-redis:
@docker stop fw-redis &>/dev/null

.PHONY: test-server
test-server:
./tests/test-server.sh
./tests/test-server.sh
16 changes: 0 additions & 16 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
Finicky Whiskers is comprised of a handful of microservices. Click on each item
below to see more details around a particular microservice.

- [morsel_event](./morsel_event/README.md)
- [redirect](./redirect/README.md)
- [scoreboard](./scoreboard/README.md)
- [session](./session/README.md)
Expand Down Expand Up @@ -37,15 +36,6 @@ make build-session

## To Run

Finicky Whiskers depends on a Redis instance to run. The default connection
string is `redis://localhost:6379`.

If you have Docker installed, you can start a redis container like so:

```console
make start-redis
```

The following command will serve the Finicky Whiskers site locally:

```console
Expand All @@ -54,12 +44,6 @@ make serve

This will run the game at [http://127.0.0.1:3000](http://127.0.0.1:3000)

When finished, the following command will stop the redis container:

```console
make stop-redis
```

## To Test

The following command will serve the site and then run the integration test
Expand Down
Binary file modified components/highscore.wasm
Binary file not shown.
Binary file removed components/morsel_event.wasm
Binary file not shown.
Binary file added components/reset.wasm
Binary file not shown.
Binary file modified components/scoreboard.wasm
Binary file not shown.
Binary file added components/session.wasm
Binary file not shown.
Binary file modified components/tally.wasm
Binary file not shown.
12 changes: 6 additions & 6 deletions highscore/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit a140e03

Please sign in to comment.