- Published on
Deploy Golang App by fly.io

TOC
Modify the Dockerfile can make it adapt to any languages
Full Pipeline
- Install
curl -L https://fly.io/install.sh | sh
fly auth signup # or fly auth login
follow the instruction to add the flyctl binary to your PATH
sudo nano ~/.bashrc
# add the following lines
export FLYCTL_INSTALL="/home/username/.fly"
export PATH="$FLYCTL_INSTALL/bin:$PATH"
- Initialize your fly.io project
fly launch
# select app name, region, etc.
# fly.toml generated automatically
- Create Redis instance
fly redis create
# get Redis URL,e.g. redis://default:password@redis.xxx.fly.dev:6379
- Set environmental variables
fly secrets set REDIS_URL='redis://default:password@redis.xxx.fly.dev:6379'
fly secrets set OTHER_ENV_VAR='value'
- fly.toml settings A free tier example
# fly.toml app configuration file generated for ebbilogue-backend on 2025-02-03T03:25:42+09:00
#
# See https://fly.io/docs/reference/configuration/ for information about how to use this file.
#
app = 'app-name'
primary_region = 'nrt'
[build]
[http_service]
internal_port = 6061
force_https = true
auto_stop_machines = 'stop'
auto_start_machines = true
min_machines_running = 0
processes = ['app']
[[vm]]
memory = '256mb'
cpu_kind = 'shared'
cpus = 1
- Dockerfile
FROM golang:1.22-alpine
WORKDIR /app
COPY . .
RUN go mod download
RUN CGO_ENABLED=0 GOOS=linux go build -o main ./cmd/main.go
CMD ["/app/main"]
- Deploy app
fly deploy
- Check status
fly status
fly logs
Automatic Deployment with Github
- Create config file in your workdir:
.github/workflows/fly.yml
This would be created automatically when you runfly deploy
for the first time
name: Fly Deploy
on:
push:
branches:
- main
jobs:
deploy:
name: Deploy app
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: superfly/flyctl-actions/setup-flyctl@master
- name: Deploy to fly.io
run: flyctl deploy --remote-only
env:
FLY_API_TOKEN: ${{ secrets.FLY_API_TOKEN }}
- Get your token
fly auth token
- Add Github Secret
- Go to Settings > Secrets and variables > Actions
- Create FLY_API_TOKEN
- Paste token
The app will now auto-deploy on push to main branch