From c1fbd561bb8eb7833bdf421527bb37f81c6bcbe3 Mon Sep 17 00:00:00 2001 From: Tine Date: Sun, 11 Feb 2024 10:15:00 +0100 Subject: [PATCH] feat: deploy to flyio --- .github/workflows/deploy.yaml | 14 ++++++++++++++ README.md | 1 + cmd/server/main.go | 10 ++++++++-- devbox.json | 3 ++- devbox.lock | 20 ++++++++++++++++++++ fly.toml | 27 +++++++++++++++++++++++++++ justfile | 4 ++++ 7 files changed, 76 insertions(+), 3 deletions(-) create mode 100644 .github/workflows/deploy.yaml create mode 100644 fly.toml diff --git a/.github/workflows/deploy.yaml b/.github/workflows/deploy.yaml new file mode 100644 index 0000000..92bce79 --- /dev/null +++ b/.github/workflows/deploy.yaml @@ -0,0 +1,14 @@ +name: Deploy +on: [push] +branch: main + +jobs: + deploy: + runs-on: ubuntu-latest + steps: + - name: Checkout + uses: actions/checkout@v2 + - uses: superfly/flyctl-actions/setup-flyctl@v1.5 + - run: flyctl deploy --remote-only + env: + FLY_API_TOKEN: ${{ secrets.FLY_API_TOKEN }} diff --git a/README.md b/README.md index ae64232..380280a 100644 --- a/README.md +++ b/README.md @@ -11,6 +11,7 @@ Mostly just a project to test [temporal.io](https://temporal.io/). - [ ] Some nice UI to try out [htmx](https://htmx.org/). ![Screenshot](docs/screenshot.png) +Demo is available at https://zdravko.fly.io. # Development diff --git a/cmd/server/main.go b/cmd/server/main.go index 591f522..dd2a8e4 100644 --- a/cmd/server/main.go +++ b/cmd/server/main.go @@ -3,6 +3,7 @@ package main import ( "log" "net/http" + "os" "github.com/gorilla/mux" @@ -11,6 +12,11 @@ import ( ) func main() { + port := os.Getenv("PORT") + if port == "" { + port = "8000" + } + r := mux.NewRouter() // Server static files @@ -19,6 +25,6 @@ func main() { r.HandleFunc("/", pages.Index).Methods("GET") r.HandleFunc("/settings", pages.Settings).Methods("GET") - log.Println("Server started on :8000") - log.Fatal(http.ListenAndServe(":8000", r)) + log.Println("Server started on", port) + log.Fatal(http.ListenAndServe(":"+port, r)) } diff --git a/devbox.json b/devbox.json index 0ec3fa5..070c687 100644 --- a/devbox.json +++ b/devbox.json @@ -3,6 +3,7 @@ "go@1.21", "temporal-cli@latest", "watchexec@latest", - "tailwindcss@latest" + "tailwindcss@latest", + "flyctl@latest" ] } diff --git a/devbox.lock b/devbox.lock index 3c9427f..e9955c7 100644 --- a/devbox.lock +++ b/devbox.lock @@ -1,6 +1,26 @@ { "lockfile_version": "1", "packages": { + "flyctl@latest": { + "last_modified": "2024-02-05T02:15:44Z", + "resolved": "github:NixOS/nixpkgs/0a254180b4cad6be45aa46dce896bdb8db5d2930#flyctl", + "source": "devbox-search", + "version": "0.1.147", + "systems": { + "aarch64-darwin": { + "store_path": "/nix/store/r2nqhmbcmijhcc1saz41hcxz8rr4b41x-flyctl-0.1.147" + }, + "aarch64-linux": { + "store_path": "/nix/store/04xazp0avkk26zyf50prl1mskflfpb86-flyctl-0.1.147" + }, + "x86_64-darwin": { + "store_path": "/nix/store/4zbndlj7m4wy834qppl2rir9fcwrzji4-flyctl-0.1.147" + }, + "x86_64-linux": { + "store_path": "/nix/store/8cfzmq9dka6vaah9j2lpdpbkpm4q0i4m-flyctl-0.1.147" + } + } + }, "go@1.21": { "last_modified": "2024-01-27T14:55:31Z", "resolved": "github:NixOS/nixpkgs/160b762eda6d139ac10ae081f8f78d640dd523eb#go", diff --git a/fly.toml b/fly.toml new file mode 100644 index 0000000..be08db7 --- /dev/null +++ b/fly.toml @@ -0,0 +1,27 @@ +# See https://fly.io/docs/reference/configuration/ for information about how to use this file. + +app = 'zdravko' +primary_region = 'waw' + +[build] + builder = 'paketobuildpacks/builder:base' + buildpacks = ['gcr.io/paketo-buildpacks/go'] + +[env] + PORT = '8080' + +[processes] + server = "server" + #worker = "worker" + +[http_service] + processes = ["server"] + internal_port = 8080 + force_https = true + auto_stop_machines = true + auto_start_machines = true + +[[vm]] + cpu_kind = 'shared' + cpus = 1 + memory_mb = 256 diff --git a/justfile b/justfile index e82b7f5..ae6dbee 100644 --- a/justfile +++ b/justfile @@ -38,3 +38,7 @@ run-worker: # Run full development environment run: devbox services up + +# Deploy the application to fly.io +deploy: + fly deploy