Skip to content

Commit

Permalink
Adding information for testing with deployex and capturing port from …
Browse files Browse the repository at this point in the history
…env var
  • Loading branch information
thiagoesteves committed Oct 20, 2024
1 parent a16f36e commit 89689db
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 2 deletions.
1 change: 1 addition & 0 deletions .tool-versions
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
erlang 26.1.2
10 changes: 10 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,16 @@ To get precompiled erlang suitable for deployment:
gleam export erlang-shipment
```

After exporting files for release and preparing the package version for [DeployEx](https://github.com/thiagoesteves/deployex), run the following commands if testing locally:
```sh
export app_name=cochito
export release_path=erlang-shipment
cd build
tar -czvf ${release_path}/${app_name}-0.1.0.tar.gz ${release_path}
cp ${release_path}/${app_name}-0.1.0.tar.gz /tmp/${app_name}/dist/${app_name}
echo "{\"version\":\"0.1.0\",\"pre_commands\": [],\"hash\":\"local\"}" | jq > /tmp/${app_name}/versions/${app_name}/local/current.json
```

## Architecture

Currently the whole server just sits as a single file at `src/cochito.gleam`, these are the main libraries being used:
Expand Down
1 change: 1 addition & 0 deletions gleam.toml
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ gleam_otp = ">= 0.12.1 and < 1.0.0"
mist = ">= 3.0.0 and < 4.0.0"
gleam_http = ">= 3.7.0 and < 4.0.0"
nakai = ">= 1.0.0 and < 2.0.0"
envoy = ">= 1.0.1 and < 2.0.0"

[dev-dependencies]
gleeunit = ">= 1.0.0 and < 2.0.0"
2 changes: 2 additions & 0 deletions manifest.toml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

packages = [
{ name = "birl", version = "1.7.1", build_tools = ["gleam"], requirements = ["gleam_stdlib", "ranger"], otp_app = "birl", source = "hex", outer_checksum = "5C66647D62BCB11FE327E7A6024907C4A17954EF22865FE0940B54A852446D01" },
{ name = "envoy", version = "1.0.1", build_tools = ["gleam"], requirements = ["gleam_stdlib"], otp_app = "envoy", source = "hex", outer_checksum = "CFAACCCFC47654F7E8B75E614746ED924C65BD08B1DE21101548AC314A8B6A41" },
{ name = "gleam_crypto", version = "1.4.0", build_tools = ["gleam"], requirements = ["gleam_stdlib"], otp_app = "gleam_crypto", source = "hex", outer_checksum = "8AE56026B3E05EBB1F076778478A762E9EB62B31AEEB4285755452F397029D22" },
{ name = "gleam_erlang", version = "0.27.0", build_tools = ["gleam"], requirements = ["gleam_stdlib"], otp_app = "gleam_erlang", source = "hex", outer_checksum = "DE468F676D71B313C6C8C5334425CFCF827837333F8AB47B64D8A6D7AA40185D" },
{ name = "gleam_http", version = "3.7.0", build_tools = ["gleam"], requirements = ["gleam_stdlib"], otp_app = "gleam_http", source = "hex", outer_checksum = "EA66440C2269F7CED0F6845E5BD0DB68095775D627FA709A841CA78A398D6D56" },
Expand All @@ -20,6 +21,7 @@ packages = [
]

[requirements]
envoy = { version = ">= 1.0.1 and < 2.0.0" }
gleam_erlang = { version = ">= 0.27.0 and < 1.0.0" }
gleam_http = { version = ">= 3.7.0 and < 4.0.0" }
gleam_otp = { version = ">= 0.12.1 and < 1.0.0" }
Expand Down
7 changes: 5 additions & 2 deletions src/cochito.gleam
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
import envoy
import gleam/bytes_builder
import gleam/erlang/process
import gleam/http/request.{type Request}
import gleam/http/response.{type Response}
import gleam/int
import gleam/io
import gleam/otp/actor
import gleam/otp/supervisor
Expand All @@ -13,8 +15,6 @@ import nakai/html

// ------ App startup ------ //

const port = 8088

pub fn main() {
io.println("Starting up cochito app...")
let assert Ok(_) = supervisor()
Expand Down Expand Up @@ -46,6 +46,9 @@ fn server_childspec() {
// ------ Server logic and middleware ------ //

fn start_server() {
let assert Ok(port) =
envoy.get("PORT") |> result.unwrap("8088") |> int.parse()

let middleware = fn(request: Request(Connection)) -> Response(ResponseData) {
request
|> router()
Expand Down

0 comments on commit 89689db

Please sign in to comment.