Example Project from A First Look at Fly
Fly is a platform for full stack applications and databases that need to run globally. Fly executes your code close to users and scales compute in cities where your app is busiest. You can run arbitrary Docker containers and host popular databases like Postgres.
git clone https://github.com/ajcwebdev/a-first-look.git
cd deployment/docker-fly
You can download the CLI on Mac, Linux, or Windows.
brew install superfly/tap/flyctl
flyctl auth signup
flyctl auth login
const express = require("express")
const app = express()
const port = process.env.PORT || 3000
app.get(
"/", (req, res) => {
greeting = "<h1>ajcwebdev-fly</h1>"
res.send(greeting)
}
)
app.listen(
port,
() => console.log(`Hello from port ${port}!`)
)
node index.js
Hello from port 3000!
FROM node:14-alpine
WORKDIR /usr/src/app
COPY package*.json ./
RUN npm i
COPY . ./
EXPOSE 8080
CMD [ "node", "index.js" ]
node_modules
Dockerfile
.dockerignore
.git
.gitignore
npm-debug.log
Run flyctl launch
in the directory with your source code to configure your app for deployment. This will create and configure a fly app by inspecting your source code and prompting you to deploy.
flyctl launch --name ajcwebdev-fly --region sjc
This creates a fly.toml
file.
app = "ajcwebdev-fly"
kill_signal = "SIGINT"
kill_timeout = 5
[env]
[experimental]
allowed_public_ports = []
auto_rollback = true
[[services]]
http_checks = []
internal_port = 8080
protocol = "tcp"
script_checks = []
[services.concurrency]
hard_limit = 25
soft_limit = 20
type = "connections"
[[services.ports]]
handlers = ["http"]
port = 80
[[services.ports]]
handlers = ["tls", "http"]
port = 443
[[services.tcp_checks]]
grace_period = "1s"
interval = "15s"
restart_limit = 6
timeout = "2s"
Add the following PORT
number under env
.
[env]
PORT = 8080
flyctl deploy
flyctl status
flyctl open
Opening http://ajcwebdev-fly.fly.dev/
Visit ajcwebdev-fly.fly.dev to see the site.