Skip to content

[wip]: Deploy rewritten highscore api as container app #179

[wip]: Deploy rewritten highscore api as container app

[wip]: Deploy rewritten highscore api as container app #179

Workflow file for this run

name: wasm_app
on:
push:
branches: [main]
pull_request:
types: [opened, synchronize, reopened, closed]
branches: [main]
permissions:
packages: write
defaults:
run:
working-directory: front-end
jobs:
test:
runs-on: ubuntu-22.04
steps:
- uses: actions/checkout@v3
- name: Install
run: curl https://rustwasm.github.io/wasm-pack/installer/init.sh -sSf | sh
- name: Cargo test
run: cargo test
- name: Wasm test
run: wasm-pack test --headless --chrome
build_and_deploy:
if: github.event_name == 'push' || (github.event_name == 'pull_request' && github.event.action != 'closed')
runs-on: ubuntu-22.04
name: Build and Deploy
env:
DOCKER_BUILDKIT: "1"
steps:
- uses: actions/checkout@v3
- name: Set variables for staging
if: github.event_name == 'pull_request'
run: |
echo "BUILD_VERSION=pr_build_$(git rev-parse --short HEAD)" >> $GITHUB_ENV
echo "HIGHSCORE_API_BASE_URL=https://highscores-staging.playsnake.no" >> $GITHUB_ENV
- name: Set variables for prod
if: github.event_name != 'pull_request'
run: |
echo "BUILD_VERSION=$(git rev-parse --short HEAD)" >> $GITHUB_ENV
echo "HIGHSCORE_API_BASE_URL=https://highscores.playsnake.no" >> $GITHUB_ENV
- name: Docker build
run: |
docker build \
--build-arg VERSION=$BUILD_VERSION \
--build-arg HIGHSCORE_API_BASE_URL=$HIGHSCORE_API_BASE_URL \
-t ghcr.io/christianfosli/snake/wasm-app:$BUILD_VERSION \
-t ghcr.io/christianfosli/snake/wasm-app:latest \
.
- name: Login to ghcr
if: github.event_name != 'pull_request'
uses: docker/login-action@v2
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Push
# Not needed for deployment, but might be nice for running locally
if: github.event_name != 'pull_request'
run: |
docker push --all-tags ghcr.io/christianfosli/snake/wasm-app
- name: Extract files to deploy
# Since we deploy to azure static web app rather than container we need to extract the build files to deploy
run: |
container="$(docker create ghcr.io/christianfosli/snake/wasm-app:latest)"
docker cp "$container:/usr/share/nginx/html" out
- name: Deploy
id: builddeploy
uses: Azure/static-web-apps-deploy@v1
with:
azure_static_web_apps_api_token: ${{ secrets.AZURE_STATIC_WEB_APPS_API_TOKEN_VICTORIOUS_ISLAND_0A8DCC303 }}
repo_token: ${{ secrets.GITHUB_TOKEN }}
action: upload
app_location: front-end/out
api_location: "" # leave blank or bring-your-own functions
output_location: ""
skip_app_build: true
close_pull_request:
if: github.event_name == 'pull_request' && github.event.action == 'closed'
runs-on: ubuntu-22.04
name: Close Pull Request
steps:
- name: Close Pull Request
id: closepullrequest
uses: Azure/static-web-apps-deploy@v1
with:
azure_static_web_apps_api_token: ${{ secrets.AZURE_STATIC_WEB_APPS_API_TOKEN_VICTORIOUS_ISLAND_0A8DCC303 }}
action: close