Compare commits
No commits in common. "5946f9d96a75e1dc0c9ba3f28137e2aebdc1f5bc" and "96341b8367196b9426b0972a97a3772bbccaa518" have entirely different histories.
5946f9d96a
...
96341b8367
5 changed files with 10 additions and 66 deletions
3
.gitignore
vendored
3
.gitignore
vendored
|
@ -2,5 +2,4 @@
|
||||||
*.ez
|
*.ez
|
||||||
/build
|
/build
|
||||||
erl_crash.dump
|
erl_crash.dump
|
||||||
/priv
|
/priv
|
||||||
**/geofeed.csv
|
|
49
Dockerfile
49
Dockerfile
|
@ -1,49 +0,0 @@
|
||||||
# Build args
|
|
||||||
ARG PORT=8080
|
|
||||||
ARG GLEAM_VERSION=v1.11.1
|
|
||||||
|
|
||||||
# Build stage - compile the application
|
|
||||||
FROM ghcr.io/gleam-lang/gleam:${GLEAM_VERSION}-erlang-alpine AS builder
|
|
||||||
|
|
||||||
# Add project code
|
|
||||||
COPY ./common /build/common
|
|
||||||
COPY ./client /build/client
|
|
||||||
COPY ./server /build/server
|
|
||||||
|
|
||||||
# Install dependencies for all projects
|
|
||||||
RUN cd /build/common && gleam deps download
|
|
||||||
RUN cd /build/client && gleam deps download
|
|
||||||
RUN cd /build/server && gleam deps download
|
|
||||||
|
|
||||||
# Compile the client code and output to server's static directory
|
|
||||||
RUN cd /build/client \
|
|
||||||
&& gleam add --dev lustre_dev_tools \
|
|
||||||
&& gleam run -m lustre/dev build app --minify --outdir=/build/server/priv/static
|
|
||||||
|
|
||||||
# Compile the server code
|
|
||||||
RUN cd /build/server \
|
|
||||||
&& gleam export erlang-shipment
|
|
||||||
|
|
||||||
# Runtime stage - slim image with only what's needed to run
|
|
||||||
FROM ghcr.io/gleam-lang/gleam:${GLEAM_VERSION}-erlang-alpine
|
|
||||||
|
|
||||||
# Copy the compiled server code from the builder stage
|
|
||||||
COPY --from=builder /build/server/build/erlang-shipment /app
|
|
||||||
|
|
||||||
# Set up the entrypoint
|
|
||||||
WORKDIR /app
|
|
||||||
RUN echo '#!/bin/sh\nexec ./entrypoint.sh "$@"' > /app/start.sh \
|
|
||||||
&& chmod +x /app/start.sh
|
|
||||||
|
|
||||||
# Add volume for accessing geofeed from host
|
|
||||||
VOLUME /data
|
|
||||||
|
|
||||||
# Set environment variables
|
|
||||||
ENV GEOFEED_PATH=/data/geofeed.csv
|
|
||||||
ENV PORT=${PORT}
|
|
||||||
|
|
||||||
# Expose the port the server will run on
|
|
||||||
EXPOSE ${PORT}
|
|
||||||
|
|
||||||
# Run the server
|
|
||||||
CMD ["/app/start.sh", "run"]
|
|
|
@ -12,7 +12,7 @@ wisp = ">= 1.8.0 and < 2.0.0"
|
||||||
mist = ">= 5.0.2 and < 6.0.0"
|
mist = ">= 5.0.2 and < 6.0.0"
|
||||||
lustre = ">= 5.2.1 and < 6.0.0"
|
lustre = ">= 5.2.1 and < 6.0.0"
|
||||||
simplifile = ">= 2.3.0 and < 3.0.0"
|
simplifile = ">= 2.3.0 and < 3.0.0"
|
||||||
envoy = ">= 1.0.2 and < 2.0.0"
|
argv = ">= 1.0.2 and < 2.0.0"
|
||||||
|
|
||||||
[dev-dependencies]
|
[dev-dependencies]
|
||||||
gleeunit = ">= 1.0.0 and < 2.0.0"
|
gleeunit = ">= 1.0.0 and < 2.0.0"
|
||||||
|
|
|
@ -2,6 +2,7 @@
|
||||||
# You typically do not need to edit this file
|
# You typically do not need to edit this file
|
||||||
|
|
||||||
packages = [
|
packages = [
|
||||||
|
{ name = "argv", version = "1.0.2", build_tools = ["gleam"], requirements = [], otp_app = "argv", source = "hex", outer_checksum = "BA1FF0929525DEBA1CE67256E5ADF77A7CDDFE729E3E3F57A5BDCAA031DED09D" },
|
||||||
{ name = "directories", version = "1.2.0", build_tools = ["gleam"], requirements = ["envoy", "gleam_stdlib", "platform", "simplifile"], otp_app = "directories", source = "hex", outer_checksum = "D13090CFCDF6759B87217E8DDD73A75903A700148A82C1D33799F333E249BF9E" },
|
{ name = "directories", version = "1.2.0", build_tools = ["gleam"], requirements = ["envoy", "gleam_stdlib", "platform", "simplifile"], otp_app = "directories", source = "hex", outer_checksum = "D13090CFCDF6759B87217E8DDD73A75903A700148A82C1D33799F333E249BF9E" },
|
||||||
{ name = "envoy", version = "1.0.2", build_tools = ["gleam"], requirements = ["gleam_stdlib"], otp_app = "envoy", source = "hex", outer_checksum = "95FD059345AA982E89A0B6E2A3BF1CF43E17A7048DCD85B5B65D3B9E4E39D359" },
|
{ name = "envoy", version = "1.0.2", build_tools = ["gleam"], requirements = ["gleam_stdlib"], otp_app = "envoy", source = "hex", outer_checksum = "95FD059345AA982E89A0B6E2A3BF1CF43E17A7048DCD85B5B65D3B9E4E39D359" },
|
||||||
{ name = "exception", version = "2.1.0", build_tools = ["gleam"], requirements = ["gleam_stdlib"], otp_app = "exception", source = "hex", outer_checksum = "329D269D5C2A314F7364BD2711372B6F2C58FA6F39981572E5CA68624D291F8C" },
|
{ name = "exception", version = "2.1.0", build_tools = ["gleam"], requirements = ["gleam_stdlib"], otp_app = "exception", source = "hex", outer_checksum = "329D269D5C2A314F7364BD2711372B6F2C58FA6F39981572E5CA68624D291F8C" },
|
||||||
|
@ -30,7 +31,7 @@ packages = [
|
||||||
]
|
]
|
||||||
|
|
||||||
[requirements]
|
[requirements]
|
||||||
envoy = { version = ">= 1.0.2 and < 2.0.0" }
|
argv = { version = ">= 1.0.2 and < 2.0.0" }
|
||||||
gleam_erlang = { version = ">= 1.2.0 and < 2.0.0" }
|
gleam_erlang = { version = ">= 1.2.0 and < 2.0.0" }
|
||||||
gleam_http = { version = ">= 4.1.0 and < 5.0.0" }
|
gleam_http = { version = ">= 4.1.0 and < 5.0.0" }
|
||||||
gleam_json = { version = ">= 3.0.2 and < 4.0.0" }
|
gleam_json = { version = ">= 3.0.2 and < 4.0.0" }
|
||||||
|
|
|
@ -1,10 +1,9 @@
|
||||||
import envoy
|
import argv
|
||||||
import gleam/dynamic/decode
|
import gleam/dynamic/decode
|
||||||
import gleam/erlang/process
|
import gleam/erlang/process
|
||||||
import gleam/http.{Get, Post}
|
import gleam/http.{Get, Post}
|
||||||
import gleam/int
|
import gleam/int
|
||||||
import gleam/json
|
import gleam/json
|
||||||
import gleam/result
|
|
||||||
import lustre/attribute
|
import lustre/attribute
|
||||||
import lustre/element
|
import lustre/element
|
||||||
import lustre/element/html
|
import lustre/element/html
|
||||||
|
@ -17,21 +16,15 @@ import wisp/wisp_mist
|
||||||
|
|
||||||
pub fn main() {
|
pub fn main() {
|
||||||
wisp.configure_logger()
|
wisp.configure_logger()
|
||||||
|
let secret_key_base = wisp.random_string(64)
|
||||||
let assert Ok(priv_directory) = wisp.priv_directory("server")
|
let assert Ok(priv_directory) = wisp.priv_directory("server")
|
||||||
let static_directory = priv_directory <> "/static"
|
let static_directory = priv_directory <> "/static"
|
||||||
let geofeed_path = envoy.get("GEOFEED_PATH") |> result.unwrap("geofeed.csv")
|
let assert [port_str, geofeed_path, ..] = argv.load().arguments
|
||||||
let secret_key_base =
|
let assert Ok(port) = int.parse(port_str)
|
||||||
envoy.get("SECRET_KEY") |> result.unwrap(wisp.random_string(64))
|
|
||||||
let bind_address = envoy.get("BIND_ADDRESS") |> result.unwrap("0.0.0.0")
|
|
||||||
let port =
|
|
||||||
envoy.get("PORT")
|
|
||||||
|> result.try(int.parse)
|
|
||||||
|> result.unwrap(8080)
|
|
||||||
let assert Ok(_) =
|
let assert Ok(_) =
|
||||||
handle_request(_, static_directory, geofeed_path)
|
handle_request(static_directory, geofeed_path, _)
|
||||||
|> wisp_mist.handler(secret_key_base)
|
|> wisp_mist.handler(secret_key_base)
|
||||||
|> mist.new
|
|> mist.new
|
||||||
|> mist.bind(bind_address)
|
|
||||||
|> mist.port(port)
|
|> mist.port(port)
|
||||||
|> mist.start
|
|> mist.start
|
||||||
process.sleep_forever()
|
process.sleep_forever()
|
||||||
|
@ -51,9 +44,9 @@ fn app_middleware(
|
||||||
}
|
}
|
||||||
|
|
||||||
fn handle_request(
|
fn handle_request(
|
||||||
req: Request,
|
|
||||||
static_directory: String,
|
static_directory: String,
|
||||||
geofeed_path: String,
|
geofeed_path: String,
|
||||||
|
req: Request,
|
||||||
) -> Response {
|
) -> Response {
|
||||||
use req <- app_middleware(req, static_directory)
|
use req <- app_middleware(req, static_directory)
|
||||||
case req.method, wisp.path_segments(req) {
|
case req.method, wisp.path_segments(req) {
|
||||||
|
|
Loading…
Reference in a new issue