diff --git a/.github/workflows/fly-deploy.yaml b/.github/workflows/fly-deploy.yaml new file mode 100644 index 0000000..d283e8f --- /dev/null +++ b/.github/workflows/fly-deploy.yaml @@ -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 }} diff --git a/.taskfiles/Fly.yaml b/.taskfiles/Fly.yaml deleted file mode 100644 index 284e2b4..0000000 --- a/.taskfiles/Fly.yaml +++ /dev/null @@ -1,7 +0,0 @@ ---- -version: "3" - -includes: - app: FlyApp.yaml - volume: FlyVolume.yaml - secrets: FlySecrets.yaml \ No newline at end of file diff --git a/.taskfiles/FlyApp.yaml b/.taskfiles/fly/app.yaml similarity index 95% rename from .taskfiles/FlyApp.yaml rename to .taskfiles/fly/app.yaml index 1c69f8b..7803e9d 100644 --- a/.taskfiles/FlyApp.yaml +++ b/.taskfiles/fly/app.yaml @@ -2,7 +2,7 @@ version: "3" includes: - logs: FlyLogs.yaml + logs: logs.yaml tasks: create: diff --git a/.taskfiles/FlyLogs.yaml b/.taskfiles/fly/logs.yaml similarity index 100% rename from .taskfiles/FlyLogs.yaml rename to .taskfiles/fly/logs.yaml diff --git a/.taskfiles/FlySecrets.yaml b/.taskfiles/fly/secrets.yaml similarity index 100% rename from .taskfiles/FlySecrets.yaml rename to .taskfiles/fly/secrets.yaml diff --git a/.taskfiles/fly/tasks.yaml b/.taskfiles/fly/tasks.yaml new file mode 100644 index 0000000..0e60399 --- /dev/null +++ b/.taskfiles/fly/tasks.yaml @@ -0,0 +1,7 @@ +--- +version: "3" + +includes: + app: app.yaml + volume: volume.yaml + secrets: secrets.yaml \ No newline at end of file diff --git a/.taskfiles/FlyVolume.yaml b/.taskfiles/fly/volume.yaml similarity index 100% rename from .taskfiles/FlyVolume.yaml rename to .taskfiles/fly/volume.yaml diff --git a/.taskfiles/github/secrets.yaml b/.taskfiles/github/secrets.yaml new file mode 100644 index 0000000..2b026f8 --- /dev/null +++ b/.taskfiles/github/secrets.yaml @@ -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 \ No newline at end of file diff --git a/.taskfiles/github/tasks.yaml b/.taskfiles/github/tasks.yaml new file mode 100644 index 0000000..83341e0 --- /dev/null +++ b/.taskfiles/github/tasks.yaml @@ -0,0 +1,6 @@ +--- +version: "3" + +includes: + secrets: secrets.yaml + workflow: workflow.yaml \ No newline at end of file diff --git a/.taskfiles/github/workflow.yaml b/.taskfiles/github/workflow.yaml new file mode 100644 index 0000000..1b609a3 --- /dev/null +++ b/.taskfiles/github/workflow.yaml @@ -0,0 +1,7 @@ +--- +version: "3" + +tasks: + deploy: + cmds: + - gh workflow run fly-deploy.yaml \ No newline at end of file diff --git a/README.md b/README.md index fc148b0..630f2dc 100644 --- a/README.md +++ b/README.md @@ -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`? diff --git a/Taskfile.yaml b/Taskfile.yaml index a26fc4c..c55c80b 100644 --- a/Taskfile.yaml +++ b/Taskfile.yaml @@ -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: