Deploying on Fly.io
Let's setup a simple web server on fly.io using Docker.
Setup Fly.io
- Create a fly.io account
- Make sure the
flyctlCLI tool is installed
INFO
Check out the fly.io Docs for more information
Setup web server
Now setup a new HTTP web server using:
bash
pnpm create svarta-apppnpm create svarta-appbash
yarn create svarta-appyarn create svarta-appbash
npm create svarta-appnpm create svarta-appAnd follow the in-terminal instructions. Select the starter-http template.
The template comes with a Dockerfile, so we're almost ready to go. Just one thing:
In svarta.config.mjs change defaultPort to 8080 (the default for fly.io). Else, you could change the port by using the PORT or SVARTA_PORT environment variables.
Create Fly.io app
bash
flyctl launchflyctl launchflyctl will detect the Dockerfile. Go through the setup and then deploy using:
Deploy to Fly.io
bash
flyctl deployflyctl deployWait for the docker image to deploy, then your API will be deployed on [app-name].fly.dev.
Continuous deployment
GitHub Actions
- Create a access token at https://fly.io/user/personal_access_tokens
- Set a
FLY_API_TOKENsecret in the GitHub repository settings - Create the following workflow file (change
branchesas needed)
yaml
name: Deploy to Fly
on:
push:
branches:
- main
env:
FLY_API_TOKEN: ${{ secrets.FLY_API_TOKEN }}
jobs:
deploy:
name: Deploy app
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: superfly/flyctl-actions/setup-flyctl@master
- run: flyctl deploy --remote-onlyname: Deploy to Fly
on:
push:
branches:
- main
env:
FLY_API_TOKEN: ${{ secrets.FLY_API_TOKEN }}
jobs:
deploy:
name: Deploy app
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: superfly/flyctl-actions/setup-flyctl@master
- run: flyctl deploy --remote-only