From a07a7592b4126a5b5ee470e0edb30b630c265bf7 Mon Sep 17 00:00:00 2001 From: George Spanos Date: Thu, 7 Mar 2024 02:23:16 +0200 Subject: [PATCH] ci: restore deployments to flyio --- docker-compose.yml | 6 +++--- src/calc-odds-api/deno.lock | 3 +++ src/calc-odds-api/fly.toml | 28 ++++++++++++++++------------ src/calc-odds-api/main.ts | 13 +++++++++---- src/ui/fly.toml | 10 ++++++---- src/web-api/fly.toml | 16 ++++++++++++---- 6 files changed, 49 insertions(+), 27 deletions(-) diff --git a/docker-compose.yml b/docker-compose.yml index 723de4fa..0546f171 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -43,8 +43,8 @@ services: context: src/calc-odds-api secrets: - npmrc - env_file: - - src/calc-odds-api/.env + environment: + - ITERATIONS=50000 ports: - 7071:7071 depends_on: @@ -71,4 +71,4 @@ volumes: external: true secrets: npmrc: - file: .npmrc \ No newline at end of file + file: .npmrc diff --git a/src/calc-odds-api/deno.lock b/src/calc-odds-api/deno.lock index 192544ed..a52892e9 100644 --- a/src/calc-odds-api/deno.lock +++ b/src/calc-odds-api/deno.lock @@ -114,6 +114,9 @@ "https://deno.land/std@0.217.0/path/windows/resolve.ts": "8dae1dadfed9d46ff46cc337c9525c0c7d959fb400a6308f34595c45bdca1972", "https://deno.land/std@0.217.0/path/windows/to_file_url.ts": "40e560ee4854fe5a3d4d12976cef2f4e8914125c81b11f1108e127934ced502e", "https://deno.land/std@0.217.0/path/windows/to_namespaced_path.ts": "4ffa4fb6fae321448d5fe810b3ca741d84df4d7897e61ee29be961a6aac89a4c", + "https://deno.land/std@0.218.0/dotenv/mod.ts": "0180eaeedaaf88647318811cdaa418cc64dc51fb08354f91f5f480d0a1309f7d", + "https://deno.land/std@0.218.0/dotenv/parse.ts": "a49ed243bd62ec26f38614042cda4e5e3a47b18337c93b0f9f8556a5c918884b", + "https://deno.land/std@0.218.0/dotenv/stringify.ts": "0047ad7068289735d08964046aea267a750c141b494ca0e38831b89be6c020c2", "https://deno.land/x/oak@v14.0.0/application.ts": "3854415b8230717f227ec50932d66a09f2e77f44334abc3f2d32c3a67ef632dc", "https://deno.land/x/oak@v14.0.0/body.ts": "596bbdac22270f5a024e172043b27fcf1c794a5575424dbcb502fc58b60434a8", "https://deno.land/x/oak@v14.0.0/content_disposition.ts": "8b8c3cb2fba7138cd5b7f82fc3b5ea39b33db924a824b28261659db7e164621e", diff --git a/src/calc-odds-api/fly.toml b/src/calc-odds-api/fly.toml index 905766a7..d3534402 100644 --- a/src/calc-odds-api/fly.toml +++ b/src/calc-odds-api/fly.toml @@ -1,13 +1,13 @@ -# fly.toml app configuration file generated for ppo-calc-odds on 2023-12-31T19:49:23+02:00 +# fly.toml app configuration file generated for ppo-calc-odds on 2024-03-07T00:49:22+02:00 # # See https://fly.io/docs/reference/configuration/ for information about how to use this file. # -app = "ppo-calc-odds" -primary_region = "ams" +app = 'ppo-calc-odds' +primary_region = 'ams' [build] -dockerfile = "Dockerfile" +dockerfile = 'Dockerfile' [http_service] internal_port = 7071 @@ -15,15 +15,19 @@ force_https = true auto_stop_machines = true auto_start_machines = true min_machines_running = 0 -processes = ["app"] -[[services.http_checks]] -grace_period = 10 -interval = 30 -timeout = 5 -path = "/liveness" +processes = ['app'] + [env] ITERATIONS = "50000" + +[[http_service.checks]] +grace_period = "10s" +interval = "30s" +method = "GET" +timeout = "5s" +path = "/liveness" + [[vm]] -cpu_kind = "shared" +memory = '512mb' +cpu_kind = 'shared' cpus = 1 -memory_mb = 1024 diff --git a/src/calc-odds-api/main.ts b/src/calc-odds-api/main.ts index 75e46058..5a1ba6a7 100644 --- a/src/calc-odds-api/main.ts +++ b/src/calc-odds-api/main.ts @@ -1,6 +1,7 @@ import { calculateOdds } from "@poker-core/calculate-odds/calculate-odds.ts"; import { validateRound, Round } from "@poker-core/round/round.ts"; import { Application, Context, Next, Router } from "https://deno.land/x/oak@v14.0.0/mod.ts"; + const port = Number(Deno.env.get('PORT') || '7071'); let iterations = Number(Deno.env.get('ITERATIONS')); @@ -13,19 +14,23 @@ if (!iterations || iterations <= 0) { const apiKey = Deno.env.get('APIKEY'); const router = new Router(); -router.post('/api/calcOdds', async (ctx) => { - const body: { estimate: number, round: Round; } = await ctx.request.body.json(); +router.post('/api/calcOdds', validateClient, async (ctx) => { + let body: { estimate: number, round: Round; }; + try { + body = await ctx.request.body.json(); + } catch { + return ctx.throw(400, 'failed to parse body'); + } if (!validateRound(body.round)) { return ctx.throw(400, 'invalid round payload'); } const odds = calculateOdds(body.round, iterations); ctx.response.body = { odds }; }); -router.get('/api/liveness', (ctx) => { +router.get('/liveness', (ctx) => { ctx.response.body = 'Liveness Check Passed'; }); const app = new Application(); -app.use(validateClient); app.use(router.routes()); app.use(router.allowedMethods()); diff --git a/src/ui/fly.toml b/src/ui/fly.toml index 5bc7538b..75805873 100644 --- a/src/ui/fly.toml +++ b/src/ui/fly.toml @@ -16,11 +16,13 @@ primary_region = "ams" auto_start_machines = true min_machines_running = 0 processes = ["app"] -[[services.http_checks]] -grace_period = 10 -interval = 30 -timeout = 5 + +[[http_service.checks]] +grace_period = "10s" +interval = "30s" +timeout = "5s" path = "/" + [[vm]] cpu_kind = "shared" cpus = 1 diff --git a/src/web-api/fly.toml b/src/web-api/fly.toml index 923419c4..d469eb77 100644 --- a/src/web-api/fly.toml +++ b/src/web-api/fly.toml @@ -16,13 +16,21 @@ auto_stop_machines = true auto_start_machines = true min_machines_running = 0 processes = ["app"] -[[services.http_checks]] -grace_period = 10 -interval = 30 -timeout = 5 + +[[services.ports]] +handlers = ["http"] +port = 80 +force_https = true # + +[[http_service.checks]] +grace_period = '10s' +interval = '30s' +timeout = '5s' path = "/health/liveness" + [env] LEADERBOARD_MIN_GAMES = "2" + [[vm]] cpu_kind = "shared" cpus = 1