Skip to content

Commit

Permalink
Chore: expand examples
Browse files Browse the repository at this point in the history
- add quoting to ssh keys
- add an example for preview apps
- add an example workflow how to do housekeeping
  • Loading branch information
till committed Nov 27, 2023
1 parent c0cf019 commit b8b17c3
Showing 1 changed file with 86 additions and 50 deletions.
136 changes: 86 additions & 50 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,11 @@ A GitHub action to setup the runway CLI! Questions, issues? Please use discussio
## Quick Start

```yaml
# ...
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0
- uses: hostwithquantum/[email protected]
with:
username: ${{ secrets.RUNWAY_USERNAME }}
Expand Down Expand Up @@ -34,11 +39,11 @@ Currently supported options:

## Examples

### Setup the runway CLI
### Setup the runway CLI to deploy

This is an example how to setup the runway CLI and then how to deploy your app `cool-app`.
This is an example workflow which shows runway CLI setup and then how to use the CLI to deploy your app `cool-app`.

Once you have the client setup, you can run commands and play around with output and so on. To keep it simple, we're only deploying the code. :) Since the app exists already on runway we use the `runway gitremote` command to initialize the setup.
Once the client is setup, you can run all commands and play around with output and so on. To keep it simple, we're only deploying the code. :) Since the app exists already on runway we use the `runway gitremote` command to initialize the setup.

```yaml
# .github/workflows/release.yml
Expand All @@ -55,27 +60,31 @@ jobs:
env:
YOUR_APPLICATION_NAME: cool-app
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0
- name: create public/private key on GHA
run: |
mkdir -p ~/.ssh/
echo ${{ secrets.PRIVATE_KEY }} > ~/.ssh/id_rsa
echo ${{ secrets.PUBLIC_KEY }} > ~/.ssh/id_rsa.pub
chmod 0600 ~/.ssh/id_rsa*
- uses: hostwithquantum/[email protected]
with:
username: ${{ secrets.RUNWAY_USERNAME }}
password: ${{ secrets.RUNWAY_PASSWORD }}
setup-ssh: true
- run: runway -y gitremote -a ${YOUR_APPLICATION_NAME}
- run: runway -y app deploy
- uses: actions/checkout@v4
with:
fetch-depth: 0
- name: create public/private key on GHA
run: |
mkdir -p ~/.ssh/
echo "${{ secrets.PRIVATE_KEY }}" > ~/.ssh/id_rsa
echo "${{ secrets.PUBLIC_KEY }}" > ~/.ssh/id_rsa.pub
chmod 0600 ~/.ssh/id_rsa*
- uses: hostwithquantum/[email protected]
with:
username: ${{ secrets.RUNWAY_USERNAME }}
password: ${{ secrets.RUNWAY_PASSWORD }}
setup-ssh: true
- run: runway -y gitremote -a ${YOUR_APPLICATION_NAME}
- run: runway -y app deploy
```

### Running e2e tests

GitHub Actions provides a robust and comprehensive environment. In the following workflow we leverage some of its context in form of `${{ github.run_id }} to deploy your app with a unique name. Once deployed, you can run end-to-end tests against it and in the end, shut it down by deleting the app (and key). :)
GitHub Actions provides a robust and comprehensive environment to run e2e tests and here's how runway can help:

The following workflow leverages some of the context in form of `${{ github.run_id }}`. We'll use this _identifier_ to deploy an app with a unique name. Another viable option is to use the pull-requests's number: `${{ github.event.number }}`.

Once deployed, you can run end-to-end tests against it and in the end, shut it down by deleting the app (and key). :) If you decide to keep the application to have a preview available, you may also do that.

```yaml
# .github/workflows/e2e.yml
Expand All @@ -90,34 +99,61 @@ jobs:
runs-on: ubuntu-latest
timeout-minutes: 15
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0 # this is important!
- name: create an ssh key just for this run
run: |
mkdir -p ~/.ssh/
ssh-keygen -b 2048 -t rsa -f ~/.ssh/test-runner -c "test-key-${{ github.run_id }}" -q -N ""
- name: install CLI, login and add ssh key
uses: hostwithquantum/[email protected]
with:
username: ${{ secrets.RUNWAY_USERNAME }}
password: ${{ secrets.RUNWAY_PASSWORD }}
public-key: ~/.ssh/test-runner.pub
private-key: ~/.ssh/test-runner
add-key: true
setup-ssh: true
- name: create app on runway (with a **unique name**)
run: runway -y app create -a my-cool-app-${{ github.run_id }}
- name: deploy your app to runway
run: runway -y app deploy
# this is where your tests run!
- name: run your e2e tests here
run: curl https://my-cool-app-${{ github.run_id }}.pqapp.dev/
# then hopefully you are done :)
- name: cleanup app
if: always()
run : runway -y app rm -a my-cool-app-${{ github.run_id }} || true
- name: cleanup key - this is brute force
if: always()
run: runway -y key rm "test-key-${{ github.run_id }}" || true
- uses: actions/checkout@v4
with:
fetch-depth: 0 # this is important!
- name: create the application name
run: echo "APP_NAME=my-app-${{ github.run_id }}" >> $GITHUB_ENV
- name: create an ssh key just for this run
run: |
mkdir -p ~/.ssh/
ssh-keygen -b 2048 -t rsa -f ~/.ssh/test-runner -c "test-key-${{ github.run_id }}" -q -N ""
- name: install CLI, login and add ssh key
uses: hostwithquantum/[email protected]
with:
username: ${{ secrets.RUNWAY_USERNAME }}
password: ${{ secrets.RUNWAY_PASSWORD }}
public-key: ~/.ssh/test-runner.pub
private-key: ~/.ssh/test-runner
add-key: true
setup-ssh: true
- name: create app on runway
run: runway -y app create -a $APP_NAME || runway -y gitremote -a $APP_NAME
- name: deploy your app to runway
run: runway -y app deploy
# this is where your tests run!
- name: run your e2e tests here
run: curl https://$APP_NAME.pqapp.dev/
# then hopefully you are done :)
- name: cleanup app
if: always()
run : runway -y app rm -a $APP_NAME || true
- name: cleanup key - this is brute force
if: always()
run: runway -y key rm "test-key-${{ github.run_id }}" || true
```

### Preview apps

In the previous example, we mentioned that keeping an app for people (humans!) to look at it, may be beneficial.

The following workflow expands on that concepts and deletes an application from runway when a pull-request is closes (merged or closed without merge). This example _assumes_ that you constructed the application name like, `my-app-${{ github.event.number }}` (instead of `github.run_id`).

```yaml
name: delete app
on:
pull_request:
types:
- closed
jobs:
delete:
runs-on: ubuntu-latest
steps:
- uses: hostwithquantum/[email protected]
with:
username: ${{ secrets.QUANTUM_RUNWAY_USERNAME }}
password: ${{ secrets.QUANTUM_RUNWAY_PASSWORD }}
- run: runway -y app delete my-app-${{ github.event.number }} || true
```

0 comments on commit b8b17c3

Please sign in to comment.