@xf3l1x
f3l1x.io
29.04.2023

ย 

SUPER COOL 
APPLICATION
SUPER COOL 
APPLICATION
SUPER COOL 
APPLICATION

๐Ÿ’ฐโŒ๐Ÿ’ฐ

SUPER COOL 
APPLICATION

๐Ÿ’ฐโŒ๐Ÿ’ฐ

SUPER COOL 
APPLICATION
.
โ”œโ”€โ”€ app
โ”œโ”€โ”€ config
โ”œโ”€โ”€ var
โ”œโ”€โ”€ vendor
โ”œโ”€โ”€ www
โ”œโ”€โ”€ Dockerfile
โ”œโ”€โ”€ LICENSE
โ”œโ”€โ”€ Makefile
โ”œโ”€โ”€ README.md
โ”œโ”€โ”€ composer.json
โ”œโ”€โ”€ composer.lock
โ””โ”€โ”€ fly.toml

flyctl

curl -L https://fly.io/install.sh | sh

flyctl

โžœ flyctl

This is flyctl, the Fly.io command line interface.

Here is a few commands to get you started:
  fly launch      Launch a new application
  fly apps        Create and manage apps
  fly postgres    Create and manage Postgres databases
  fly redis       Create and manage Redis databases
  fly machines    Create and manage individual Fly.io machines

If you need help along the way:
  fly help            Display a complete list of commands
  fly help <command>  Display help for a specific command

Visit https://fly.io/docs for additional documentation & guides
โฏ flyctl launch

Creating app in /opt/code/oss/f00b4r/2023-04-nette-flyio
Scanning source code
Detected a Dockerfile app

? Choose an app name (leave blank to generate one):
? Select Organization: f00b4r (f00b4r)
? Choose a region for deployment: Amsterdam, Netherlands (ams)
App will use 'ams' region as primary
Created app 'lively-haze-3321' in organization 'f00b4r'
Admin URL: https://fly.io/apps/lively-haze-3321
Hostname: lively-haze-3321.fly.dev

Wrote config file fly.toml

? Would you like to deploy now? No
Validating /opt/code/oss/f00b4r/2023-04-nette-flyio/fly.toml
Platform: nomad

โœ“ Configuration is valid
Your app is ready! Deploy with `flyctl deploy`

flyctl launch

app = "nette"
primary_region = "fra"

[[services]]

  [[services.ports]]
    force_https = true
    handlers = ["http"]
    port = 80

  [[services.ports]]
    handlers = ["tls", "http"]
    port = 443

fly.toml

โžœ flyctl deploy

==> Verifying app config
Validating /opt/code/oss/f00b4r/2023-04-nette-flyio/fly.toml
Platform: nomad
โœ“ Configuration is valid
--> Verified app config
==> Building image
Remote builder fly-builder-broken-water-315 ready
The push refers to repository [registry.fly.io/nette]
--> Pushing image done
image: registry.fly.io/nette:deployment-01GZ64DGBB64Q1D45BH7456DE9
image size: 302 MB
Watch your app at https://fly.io/apps/nette/monitoring
==> Creating release
--> release v7 created
--> You can detach the terminal anytime without stopping the deployment
==> Monitoring deployment
Logs: https://fly.io/apps/nette/monitoring
 1 desired, 1 placed, 1 healthy, 0 unhealthy
--> v7 deployed successfully

Visit your newly deployed app at https://nette.fly.dev/

flyctl deploy

โžœ flyctl status

App
  Name     = nette
  Owner    = f00b4r
  Version  = 5
  Status   = running
  Hostname = nette.fly.dev
  Platform = nomad

Deployment Status
  ID          = b678f9cb-954e-5783-ec8b-6d3093bc02ba
  Version     = v5
  Status      = successful
  Description = Deployment completed successfully
  Instances   = 1 desired, 1 placed, 1 healthy, 0 unhealthy

Instances
ID      	PROCESS	VERSION	REGION	DESIRED	STATUS 	HEALTH CHECKS     	RESTARTS	CREATED
1bcd9eba	app    	5      	cdg   	run    	running	1 total, 1 passing	0       	5m30s ago

flyctl status

โžœ fly open

flyctl gui

โžœ fly dashboard
โžœ flyctl ssh console
Connecting to fdaa:2:158a:a7b:ae02:1f83:2511:2... complete

# ls -la /srv
drwxr-xr-x  9 root root  4096 Apr 29 10:51 .
drwxr-xr-x 22 root root  4096 Apr 29 10:51 ..
drwxr-xr-x  3 1001  123  4096 Apr 29 10:50 app
drwxr-xr-x  2 1001  123  4096 Apr 29 10:50 config
drwxr-xr-x  4 root root  4096 Apr 29 10:51 var
drwxr-xr-x  8 root root  4096 Apr 29 10:38 vendor
drwxr-xr-x  2 1001  123  4096 Apr 29 10:50 www
-rwxr-xr-x  1 1001  123  1448 Apr 29 10:50 Makefile
-rwxr-xr-x  1 1001  123   263 Apr 29 10:50 composer.json
-rwxr-xr-x  1 1001  123 61221 Apr 29 10:50 composer.lock
-rw-r--r--  1 1001  123   237 Apr 29 10:50 fly.toml

flyctl ssh

โžœ flyctl certs add fly.f00b4r.dev
Your certificate for fly.f00b4r.dev is being issued. 
Status is Awaiting certificates. 



โžœ flyctl certs list
Host Name                 Added                Status
fly.f00b4r.dev            32 seconds ago       Ready

flyctl certs

f00b4r.dev
โžœ flyctl secrets set NETTE__GREETINGS=posobota

Release v13 created
==> Monitoring deployment
Logs: https://fly.io/apps/nette/monitoring

 1 desired, 1 placed, 1 healthy, 0 unhealthy
--> v13 deployed successfully

flyctl secrets

โžœ flyctl logs

2023-04-29T10:51:11Z app[7fb3e3c1] cdg [info]make project
2023-04-29T10:51:11Z app[7fb3e3c1] cdg [info]make[1]: Entering directory '/srv'
2023-04-29T10:51:11Z app[7fb3e3c1] cdg [info]mkdir -p var/tmp var/log
2023-04-29T10:51:11Z app[7fb3e3c1] cdg [info]chmod 0777 var/tmp var/log
2023-04-29T10:51:11Z app[7fb3e3c1] cdg [info]make[1]: Leaving directory '/srv'
2023-04-29T10:51:11Z app[7fb3e3c1] cdg [info]make clean
2023-04-29T10:51:11Z app[7fb3e3c1] cdg [info]make[1]: Entering directory '/srv'
2023-04-29T10:51:11Z app[7fb3e3c1] cdg [info]find var/tmp -mindepth 1 ! -name '.gitignore' -type f,d -exec rm -rf {} +
2023-04-29T10:51:11Z app[7fb3e3c1] cdg [info]find var/log -mindepth 1 ! -name '.gitignore' -type f,d -exec rm -rf {} +
2023-04-29T10:51:11Z app[7fb3e3c1] cdg [info]make[1]: Leaving directory '/srv'
2023-04-29T10:51:11Z app[7fb3e3c1] cdg [info][29-Apr-2023 10:51:11] NOTICE: fpm is running, pid 535
2023-04-29T10:51:11Z app[7fb3e3c1] cdg [info][29-Apr-2023 10:51:11] NOTICE: ready to handle connections
2023-04-29T10:51:11Z app[7fb3e3c1] cdg [info][29-Apr-2023 10:51:11] NOTICE: systemd monitor interval set to 10000ms
2023-04-29T10:51:11Z app[7fb3e3c1] cdg [info]{"level":"info","ts":1682765471.9413621,"msg":"using provided configuration","config_file":"/etc/Caddyfile","config_adapter":""}
2023-04-29T10:51:11Z app[7fb3e3c1] cdg [info]{"level":"info","ts":1682765471.9442778,"logger":"admin","msg":"admin endpoint started","address":"localhost:2019","enforce_origin":false,"origins":["//localhost:2019","//[::1]:2019","//127.0.0.1:2019"]}
2023-04-29T10:51:11Z app[7fb3e3c1] cdg [info]{"level":"info","ts":1682765471.9456158,"logger":"http.log","msg":"server running","name":"srv0","protocols":["h1","h2","h3"]}
2023-04-29T10:51:11Z app[7fb3e3c1] cdg [info]{"level":"info","ts":1682765471.9462397,"msg":"autosaved config (load with --resume flag)","file":"/root/.config/caddy/autosave.json"}
2023-04-29T10:51:11Z app[7fb3e3c1] cdg [info]{"level":"info","ts":1682765471.946276,"msg":"serving initial configuration"}
2023-04-29T10:51:11Z app[7fb3e3c1] cdg [info]{"level":"info","ts":1682765471.9467387,"logger":"tls.cache.maintenance","msg":"started background certificate maintenance","cache":"0xc0001d6d20"}
2023-04-29T10:51:11Z app[7fb3e3c1] cdg [info]{"level":"info","ts":1682765471.946896,"logger":"tls","msg":"cleaning storage unit","description":"FileStorage:/root/.local/share/caddy"}
2023-04-29T10:51:11Z app[7fb3e3c1] cdg [info]{"level":"info","ts":1682765471.9469159,"logger":"tls","msg":"finished cleaning storage units"}
2023-04-29T10:51:17Z app[fb6dd651] cdg [info]- -  29/Apr/2023:10:51:17 +0000 "GET /index.php" 200
2023-04-29T10:51:17Z app[fb6dd651] cdg [info]{"level":"info","ts":1682765477.9164765,"logger":"http.log.access","msg":"handled request","request":{"remote_ip":"172.16.75.106","remote_port":"63184","proto":"HTTP/1.1","method":"GET","host":"fly.f00b4r.dev","uri":"/","headers":{"Sec-Ch-Ua-Mobile":["?0"],"X-Request-Start":["t=1682765477883107"],"Accept":["text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.7"],"Cookie":[],"User-Agent":["Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/112.0.0.0 Safari/537.36"],"Sec-Fetch-Site":["none"],"Cache-Control":["max-age=0"],"Accept-Encoding":["gzip, deflate, br"],"Fly-Forwarded-Ssl":["on"],"Fly-Forwarded-Port":["443"],"Fly-Tracestate":[""],"Sec-Fetch-User":["?1"],"Sec-Fetch-Dest":["document"],"Fly-Region":["fra"],"Via":["2 fly.io"],"Fly-Traceparent":["00-1c94476fc6a866c208069df100b55364-cd8f289fa1c8015c-00"],"Fly-Forwarded-Proto":["https"],"X-Forwarded-Proto":["https"],"X-Forwarded-Ssl":["on"],"Sec-Ch-Ua-Platform":["\"macOS\""],"X-Forwarded-For":["78.80.24.168, 66.241.125.175"],"Sec-Fetch-Mode":["navigate"],"Fly-Client-Ip":["78.80.24.168"],"Sec-Ch-Ua":["\"Chromium\";v=\"112\", \"Google Chrome\";v=\"112\", \"Not:A-Brand\";v=\"99\""],"Accept-Language":["cs-CZ,cs;q=0.9,en;q=0.8"],"X-Forwarded-Port":["443"],"Fly-Request-Id":["01GZ6A6XZVJPMVP6WB2JY0T2ME-fra"]}},"user_id":"","duration":0.01596398,"size":13138,"status":200,"resp_headers":{"X-Xss-Protection":["1; mode=block"],"X-Frame-Options":["SAMEORIGIN"],"Vary":["X-Requested-With","Accept-Encoding"],"Content-Encoding":["gzip"],"Server":["Caddy"],"Set-Cookie":[],"X-Powered-By":["contributte"],"Content-Type":["text/html; charset=utf-8"]}}
2023-04-29T10:51:19Z app[fb6dd651] cdg [info]- -  29/Apr/2023:10:51:19 +0000 "GET /index.php" 500
2023-04-29T10:51:19Z app[fb6dd651] cdg [info]{"level":"error","ts":1682765479.0441666,"logger":"http.log.access","msg":"handled request","request":{"remote_ip":"172.16.75.106","remote_port":"63332","proto":"HTTP/1.1","method":"GET","host":"fly.f00b4r.dev","uri":"/favicon.ico","headers":{"Sec-Ch-Ua":["\"Chromium\";v=\"112\", \"Google Chrome\";v=\"112\", \"Not:A-Brand\";v=\"99\""],"User-Agent":["Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/112.0.0.0 Safari/537.36"],"Sec-Fetch-Site":["same-origin"],"X-Forwarded-Ssl":["on"],"Cookie":[],"Sec-Ch-Ua-Platform":["\"macOS\""],"X-Forwarded-Proto":["https"],"Sec-Fetch-Mode":["no-cors"],"Sec-Fetch-Dest":["image"],"Fly-Client-Ip":["78.80.24.168"],"Fly-Region":["fra"],"X-Request-Start":["t=1682765479008362"],"X-Forwarded-Port":["443"],"Fly-Request-Id":["01GZ6A6Z30RRQ8CSCQD8793SE6-fra"],"Fly-Tracestate":[""],"Sec-Ch-Ua-Mobile":["?0"],"Accept":["image/avif,image/webp,image/apng,image/svg+xml,image/*,*/*;q=0.8"],"Referer":["https://fly.f00b4r.dev/"],"Accept-Language":["cs-CZ,cs;q=0.9,en;q=0.8"],"X-Forwarded-For":["78.80.24.168, 66.241.125.175"],"Fly-Traceparent":["00-eab6a11a2e2c022e3a69bdc91ccaa12d-56269e132bfed359-00"],"Accept-Encoding":["gzip, deflate, br"],"Fly-Forwarded-Proto":["https"],"Fly-Forwarded-Ssl":["on"],"Fly-Forwarded-Port":["443"],"Via":["2 fly.io"]}},"user_id":"","duration":0.028744799,"size":32109,"status":500,"resp_headers":{"X-Powered-By":["contributte"],"Vary":["Accept-Encoding"],"X-Xss-Protection":["1; mode=block"],"X-Frame-Options":["SAMEORIGIN"],"Set-Cookie":[],"Content-Encoding":["gzip"],"Server":["Caddy"],"Content-Type":["text/html; charset=UTF-8"],"Status":["500 Internal Server Error"]}}
2023-04-29T10:51:37Z runner[fb6dd651] cdg [info]Shutting down virtual machine
2023-04-29T10:51:37Z app[fb6dd651] cdg [info]Sending signal SIGINT to main child process w/ PID 520
2023-04-29T10:51:38Z app[fb6dd651] cdg [info]Starting clean up.

flyctl logs

โžœ flyctl postgres create

? Choose an app name (leave blank to generate one): nette-db
? Select Organization: f00b4r (f00b4r)
? Select region: Amsterdam, Netherlands (ams)
? Select configuration: Development - Single node, 1x shared CPU, 256MB RAM, 1GB disk
? Scale single node pg to zero after one hour? No
Creating postgres cluster in organization f00b4r
Creating app...

Postgres cluster nette-db created
  Username:    postgres
  Password:    topsecret
  Hostname:    nette-db.internal
  Flycast:     fdaa:2:158a:0:1::3
  Proxy port:  5432
  Postgres port:  5433
  Connection string: postgres://postgres:topsecret@nette-db.flycast:5432

flyctl postgres

โžœ flyctl proxy -a nette-db 5432:5432

Proxying local port 5432 to remote [nette-db.internal]:5432

flyctl proxy

NOMAD

hashicorp

nomad agent -dev

NOMAD

hashicorp

job "example" {
  datacenters = ["dc1"]

  group "example" {
    network {
      port "http" {
        to = "80"
      }
    }
    task "server" {
      driver = "docker"

      config {
        image = "nginxdemos/hello"
        ports = ["http"]
      }
    }
  }
}
nomad job run hello.nomad

Fly.ioย & Features

  • remote console
  • monitoring & logs
  • database tooling
  • proxy (local -> remote)
  • persistent volumes
  • awesome DX
  • free plan
  • simple configuration
  • Docker/Buildpacks

Time to selfie ๐Ÿ“ท

Thank you!

@xf3l1x
f3l1x.io