Skip to content

Commit

Permalink
feat: adds automatic fly deploy via github action (#5)
Browse files Browse the repository at this point in the history
Co-authored-by: Arthur Zapparoli <[email protected]>
  • Loading branch information
arthurgeek and arthurgeek authored Jul 12, 2023
1 parent 155eeaf commit b6b3655
Show file tree
Hide file tree
Showing 12 changed files with 115 additions and 9 deletions.
51 changes: 51 additions & 0 deletions .github/workflows/fly-deploy.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
name: Deploy to Fly

on:
workflow_dispatch: {}
push:
branches:
- main
paths:
- Dockerfile
- fly.toml
- config/**
- scripts/**

jobs:
check-fly-secret:
runs-on: ubuntu-latest
outputs:
fly-secret-exists: ${{ steps.fly-secret-check.outputs.defined }}
steps:
- name: Check for Fly secrets availability
id: fly-secret-check
# perform secret check & put boolean result as an output
shell: bash
run: |
if [ "${{ secrets.FLY_API_TOKEN }}" != '' ] && [ "${{ secrets.FLY_APP }}" != '' ]; then
echo "defined=true" >> $GITHUB_OUTPUT;
else
echo "defined=false" >> $GITHUB_OUTPUT;
fi
deploy:
name: Deploy app
runs-on: ubuntu-latest
needs: [check-fly-secret]
if: needs.check-fly-secret.outputs.fly-secret-exists == 'true'
steps:
- uses: actions/checkout@v2
- uses: superfly/flyctl-actions/setup-flyctl@master
with:
version: 0.1.54
- name: Install Task
uses: arduino/setup-task@v1
with:
# renovate: datasource=github-releases depName=go-task/task
version: 3.27.1
repo-token: ${{ secrets.GITHUB_TOKEN }}
- name: Deploy app
run: flyctl deploy --remote-only -a $FLY_APP
env:
FLY_APP: ${{ secrets.FLY_APP }}
FLY_API_TOKEN: ${{ secrets.FLY_API_TOKEN }}
7 changes: 0 additions & 7 deletions .taskfiles/Fly.yaml

This file was deleted.

2 changes: 1 addition & 1 deletion .taskfiles/FlyApp.yaml → .taskfiles/fly/app.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
version: "3"

includes:
logs: FlyLogs.yaml
logs: logs.yaml

tasks:
create:
Expand Down
File renamed without changes.
File renamed without changes.
7 changes: 7 additions & 0 deletions .taskfiles/fly/tasks.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
---
version: "3"

includes:
app: app.yaml
volume: volume.yaml
secrets: secrets.yaml
File renamed without changes.
10 changes: 10 additions & 0 deletions .taskfiles/github/secrets.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
---
version: "3"

tasks:
set:
cmds:
- |
fly_token=$(fly auth token 2>&1)
gh secret set FLY_APP -b {{.FLY_APP}}
gh secret set FLY_API_TOKEN -b $fly_token
6 changes: 6 additions & 0 deletions .taskfiles/github/tasks.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
version: "3"

includes:
secrets: secrets.yaml
workflow: workflow.yaml
7 changes: 7 additions & 0 deletions .taskfiles/github/workflow.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
---
version: "3"

tasks:
deploy:
cmds:
- gh workflow run fly-deploy.yaml
31 changes: 31 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,37 @@ You can scroll your tmux window with `Ctrl-B-]` and use
Substitute `vaultwarden` with `caddy`, or `backup` to see logs for
other apps.

## Automatically deploy to Fly.io

After your first manual deploy to Fly.io, per instructions above, you can automatically deploy via Github Actions.

1. Install [Github CLI](https://cli.github.com)

```sh
brew install gh
```

1. Login to Github

```sh
gh auth login
```

1. Set Fly secrets to your Github repo

```sh
task github:secrets:set
```

1. Test your workflow deployment

```sh
task github:workflow:deploy
```

That's all! Now, any changes to your `Dockerfile`, `fly.toml` or
`scripts`/`config` will trigger an automatic fly deploy.
## FAQ
1. Why every `fly` command I run errors with: `Error: the config for your app is missing an app name`?
Expand Down
3 changes: 2 additions & 1 deletion Taskfile.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@ version: "3"
dotenv: [".config.env"]

includes:
fly: .taskfiles/Fly.yaml
fly: .taskfiles/fly/tasks.yaml
github: .taskfiles/github/tasks.yaml

tasks:
default:
Expand Down

0 comments on commit b6b3655

Please sign in to comment.