From 068af736e649eface4757aa74ec9eec67f6ca211 Mon Sep 17 00:00:00 2001 From: Josh Date: Tue, 7 Oct 2025 23:49:05 +1000 Subject: [PATCH] Docker --- .../AirportAlphabetGame.fsproj | 4 +++ AirportAlphabetGame/Controller.fs | 13 +++++++-- AirportAlphabetGame/Program.fs | 9 ++++-- AirportAlphabetGame/dockerfile | 29 +++++++++++++++++++ 4 files changed, 51 insertions(+), 4 deletions(-) create mode 100644 AirportAlphabetGame/dockerfile diff --git a/AirportAlphabetGame/AirportAlphabetGame.fsproj b/AirportAlphabetGame/AirportAlphabetGame.fsproj index 5b7ae77..b6ad434 100644 --- a/AirportAlphabetGame/AirportAlphabetGame.fsproj +++ b/AirportAlphabetGame/AirportAlphabetGame.fsproj @@ -16,6 +16,7 @@ + @@ -27,6 +28,9 @@ Always + + Always + Always diff --git a/AirportAlphabetGame/Controller.fs b/AirportAlphabetGame/Controller.fs index 547b2fa..8112d45 100644 --- a/AirportAlphabetGame/Controller.fs +++ b/AirportAlphabetGame/Controller.fs @@ -3,12 +3,13 @@ module Controller open System open System.Net.Http open System.Text.RegularExpressions +open Giraffe open Giraffe.ViewEngine.HtmlElements open Types open System.Text +open System.Net open Thoth.Json.Net - let parseUsername (username: string) = let pattern = @"https?://(?:www\.)?my\.flightradar24\.com/([^/?#]+)" let matches = Regex.Match(username, pattern) @@ -24,12 +25,19 @@ let getJsonResult result = let makePostRequest<'x> (url: string) payload = async { - use httpClient = new HttpClient() + use handler = new HttpClientHandler() + handler.AutomaticDecompression <- DecompressionMethods.GZip ||| DecompressionMethods.Deflate + use httpClient = new HttpClient(handler) + let content = new StringContent(payload, Encoding.UTF8, "application/x-www-form-urlencoded") let request = new HttpRequestMessage(HttpMethod.Post, url) request.Content <- content + request.Headers.Add("User-Agent", "Mozilla/5.0") // mimic browser + request.Headers.Add("Accept", "application/json") + let! response = httpClient.SendAsync(request) |> Async.AwaitTask let! responseContent = response.Content.ReadAsStringAsync() |> Async.AwaitTask + return responseContent } |> Async.RunSynchronously @@ -106,6 +114,7 @@ let processAirports (alphabet: char[]) (allAirports: Airport[]) = let RenderAirportList (user: usernameQuery) = let username = parseUsername user.fr24user let alphabet = [|'A'..'Z'|] + let airports = $"username={username}&listType={user.searchType}&order=no&limit=0" |> makePostRequest "https://my.flightradar24.com/public-scripts/profileToplist" diff --git a/AirportAlphabetGame/Program.fs b/AirportAlphabetGame/Program.fs index dc59928..39fcd71 100644 --- a/AirportAlphabetGame/Program.fs +++ b/AirportAlphabetGame/Program.fs @@ -2,10 +2,14 @@ open Microsoft.AspNetCore.Http open Microsoft.Extensions.DependencyInjection open Saturn open Giraffe -open Types +open Types +open Thoth.Json.Giraffe +open System open System.Net open System.Net.Sockets +open System.IO + module Program = @@ -23,6 +27,7 @@ module Program = let ServiceConfig (services: IServiceCollection) = // Get the server IP address + services.AddSingleton(ThothSerializer()) |> ignore let serverIpAddress = match Dns.GetHostEntry(Dns.GetHostName()).AddressList |> Array.tryFind(fun ip -> ip.AddressFamily = AddressFamily.InterNetwork) with | Some ip -> ip.ToString() @@ -40,8 +45,8 @@ module Program = let app = application { use_mime_types [(".woff", "application/font-woff")] - use_static "wwwroot" use_router router + use_static (Path.Combine(AppContext.BaseDirectory, "wwwroot")) use_developer_exceptions service_config ServiceConfig url "http://0.0.0.0:5001" diff --git a/AirportAlphabetGame/dockerfile b/AirportAlphabetGame/dockerfile new file mode 100644 index 0000000..72049d4 --- /dev/null +++ b/AirportAlphabetGame/dockerfile @@ -0,0 +1,29 @@ +# Use a full Ubuntu image +FROM ubuntu:24.04 AS base + +# Set working directory +WORKDIR /app + +# Install dependencies: ICU, CA certs, curl (optional for debugging) +RUN apt-get update && \ + apt-get install -y --no-install-recommends \ + libicu-dev \ + ca-certificates \ + curl \ + unzip \ + wget \ + git \ + tzdata && \ + rm -rf /var/lib/apt/lists/* + +# Copy published .NET app +COPY bin/Release/net8.0/linux-x64/publish/ ./ + +# Expose port +EXPOSE 5001 + +# Set timezone (optional, avoids TZ issues) +ENV TZ=Australia/Brisbane + +# Set entrypoint +ENTRYPOINT ["./AirportAlphabetGame"]