Skip to content

Instantly share code, notes, and snippets.

@domenkozar
Last active March 8, 2023 07:16
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save domenkozar/e06a457f4b44439e5657fdaf51c0bef3 to your computer and use it in GitHub Desktop.
Save domenkozar/e06a457f4b44439e5657fdaf51c0bef3 to your computer and use it in GitHub Desktop.
Sample flask using devenv.sh and fly.io for deployments

Sample flask using devenv.sh and fly.io for deployments

Development

$ devenv up

Deployment

$ deploy

Setup

Login:

flyctl auth login

Create an app:

flyctl apps create myproject

Allocate ipv4:

flyctl ips allocate-v4

Copy the container to fly.io registry:

devenv container processes --copy 

Create a volume for devenv state:

fly volumes create devenv_state --region ams --size 1 -a myproject

Deploy your app:

flyctl deploy
{ config, pkgs, lib, ... }:
let
debug = lib.optionalString (!config.container.isBuilding) "--debug";
in {
enterShell = ''
pip install -r requirements.txt
'';
languages.python.enable = true;
languages.python.venv.enable = true;
packages = [] ++ lib.optionals (!config.container.isBuilding) [ pkgs.flyctl ];
processes."serve".exec = "flask ${debug} --app serve run --host 0.0.0.0";
scripts.deploy.exec = ''
devenv container processes --copy
flyctl deploy
'';
containers."processes" = {
name = "myproject";
registry = "docker://registry.fly.io/";
defaultCopyArgs = [
"--dest-creds"
"x:\"$(${pkgs.flyctl}/bin/flyctl auth token)\""
];
};
}
inputs:
nix2container:
url: github:nlewo/nix2container
inputs:
nixpkgs:
follows: nixpkgs
mk-shell-bin:
url: github:rrbutani/nix-mk-shell-bin
app = "myproject"
[build]
image = "registry.fly.io/myproject:latest"
[[services]]
internal_port = 5000
protocol = "tcp"
[[services.ports]]
handlers = ["tls", "http"]
port = "443"
[mounts]
source="devenv_state"
destination="/.devenv/state"
from flask import Flask, request
app = Flask(__name__)
@app.route("/")
def serve():
return {}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment