👩‍🚒 Firefighters API written in Gleam!
lustre gleam
at main 119 lines 3.4 kB view raw
1mod client 2mod server 3mod shared 4 5# ------------------------------------------------------------------------------ 6# CONFIG 7# ------------------------------------------------------------------------------ 8 9pod_name := "pod_sigo" 10 11# database 12pg_image := "docker.io/postgres:18-alpine" 13pg_env := "-e POSTGRES_USER -e POSTGRES_PASSWORD -e POSTGRES_DB" 14pg_volume := "-v ./sql/create:/docker-entrypoint-initdb.d" 15 16pg_health_cmd := "--health-cmd 'pg_isready -U ${POSTGRES_USER} -d ${POSTGRES_DB}'" 17pg_health_conf := "--health-interval 10s --health-retries 3 --health-timeout 5s" 18pg_health_start_period := "--health-start-period 30s" 19 20# server 21run_server_locally := env("RUN_SERVER_LOCALLY", "false") 22server_port := if run_server_locally == "false" { "-p 8000:8000" } else { "" } 23 24server_health_cmd := "--health-cmd 'wget -q --spider http://127.0.0.1:8000/api/health || exit 1'" 25server_health_conf := "--health-interval 30s --health-retries 3 --health-timeout 10s" 26server_health_start_period := "--health-start-period 10s" 27 28# List available recipes 29@_default: 30 just --list 31 32# ------------------------------------------------------------------------------ 33# DEV 34# ------------------------------------------------------------------------------ 35 36# 󰌢 Build Lustre runtime and start HTTP server 37[group("dev")] 38dev: 39 just client::build 40 just server::run 41 42#  Update project dependencies 43[group("dev")] 44deps-update: 45 just shared::deps-update 46 just client::deps-update 47 just server::deps-update 48 49#  Check for errors 50[group("dev")] 51lint: 52 just server::lint 53 just client::lint 54 just shared::lint 55 56# 󰙨 Run unit tests 57[group("dev")] 58test: 59 just server::test 60 61# ------------------------------------------------------------------------------ 62# CONTAINERS 63# ------------------------------------------------------------------------------ 64 65# 󰏖 Create pod 66# Behavior can be changed using the `run_server_locally` recipe variable 67[group("podman")] 68@create-pod: 69 podman pod exists {{ pod_name }} || \ 70 podman pod create \ 71 --name {{ pod_name }} \ 72 {{ server_port }} \ 73 -p 5432:5432 74 75# 󰏖 Build the server container image 76[group("podman")] 77build-server: 78 @podman build -t sigo-server . 79 80#  Starts the PostgreSQL database inside the pod 81[group("podman")] 82@init-database: create-pod 83 podman run -d \ 84 --pod {{ pod_name }} \ 85 --name db \ 86 {{ pg_env }} \ 87 {{ pg_health_cmd }} {{ pg_health_conf }} {{ pg_health_start_period }} \ 88 {{ pg_volume }} \ 89 {{ pg_image }} 90 91#  Starts the server 92[group("podman")] 93@init-server: create-pod build-server 94 podman run -d \ 95 --pod {{ pod_name }} \ 96 --name server \ 97 -e DATABASE_URL -e SECRET_KEY \ 98 {{ server_health_cmd }} \ 99 {{ server_health_conf }} \ 100 {{ server_health_start_period }} \ 101 sigo-server 102 103 104#  Starts the server and database 105[group("podman")] 106up: init-database init-server 107 @echo {{ GREEN }}"Listening on http://0.0.0.0:8000"{{ NORMAL }} 108 109#  Starts only the database 110[group("podman")] 111db-up: init-database 112 @echo {{ GREEN }}"PostgreSQL is ready on port 5432"{{ NORMAL }} 113 114#  Stop and remove the entire pod 115[group("podman")] 116down: 117 podman pod exists {{ pod_name }} || (echo "Pod does not exist" && exit 1) 118 podman pod stop {{ pod_name }} 119 podman pod rm {{ pod_name }}