From 8fe7d796777a7fdceadfde2188f757531b3a150d Mon Sep 17 00:00:00 2001 From: Jasper Van der Jeugt Date: Wed, 13 Dec 2023 15:15:15 +0100 Subject: [PATCH] make web run through hacky janitor --- cabal.project | 5 +++++ deploy/template.yaml | 6 +++--- lib/Zureg/Main/Web.hs | 1 + src/Janitor.hs | 17 +++++++++++++---- stack.yaml | 1 + stack.yaml.lock | 7 +++++++ zureg.cabal | 6 ++++-- 7 files changed, 34 insertions(+), 9 deletions(-) diff --git a/cabal.project b/cabal.project index 2a2c85e..5ba87ea 100644 --- a/cabal.project +++ b/cabal.project @@ -4,3 +4,8 @@ source-repository-package type: git location: https://github.com/jaspervdj/urlencoded.git tag: 79e31ed9279c820bb89e36824464fdfb4b7b968a + +source-repository-package + type: git + location: https://github.com/jaspervdj/wai-handler-hal.git + tag: 999114f42a7a36e1486c3f723377b50a2e88c11d diff --git a/deploy/template.yaml b/deploy/template.yaml index 9088736..a152a7b 100644 --- a/deploy/template.yaml +++ b/deploy/template.yaml @@ -95,9 +95,9 @@ Resources: Type: 'AWS::Lambda::Function' Properties: FunctionName: 'zureg-web' - Handler: 'main.web_handler' + Handler: 'web' Role: {'Fn::GetAtt': ['LambdaExecutionRole', 'Arn']} - Runtime: 'python3.9' + Runtime: 'provided' Timeout: 10 MemorySize: 512 # If not, requests to DDB time out... Code: @@ -195,7 +195,7 @@ Resources: Type: 'AWS::Lambda::Function' Properties: FunctionName: 'zureg-janitor' - Handler: 'NOT_USED' + Handler: 'janitor' Role: {'Fn::GetAtt': ['LambdaExecutionRole', 'Arn']} Runtime: 'provided' Timeout: 10 diff --git a/lib/Zureg/Main/Web.hs b/lib/Zureg/Main/Web.hs index 633325e..48ad728 100644 --- a/lib/Zureg/Main/Web.hs +++ b/lib/Zureg/Main/Web.hs @@ -4,6 +4,7 @@ {-# LANGUAGE TemplateHaskell #-} module Zureg.Main.Web ( main + , app ) where import Control.Applicative (liftA2) diff --git a/src/Janitor.hs b/src/Janitor.hs index e1e34ac..16d6192 100644 --- a/src/Janitor.hs +++ b/src/Janitor.hs @@ -1,9 +1,18 @@ {-# LANGUAGE ScopedTypeVariables #-} -import AWS.Lambda.Runtime (mRuntime) -import qualified Data.Aeson as A +import AWS.Lambda.Runtime (mRuntime) +import qualified Data.Aeson as A +import qualified Network.Wai.Handler.Hal as WaiHandler +import System.Environment (lookupEnv) import qualified Zureg.Hackathon import qualified Zureg.Main.Janitor +import qualified Zureg.Main.Web as Web main :: IO () -main = mRuntime $ \(_ :: A.Value) -> - Zureg.Hackathon.withHackathonFromEnv Zureg.Main.Janitor.main +main = do + handler <- lookupEnv "_HANDLER" + case handler of + Just "janitor" -> mRuntime $ \(_ :: A.Value) -> + Zureg.Hackathon.withHackathonFromEnv Zureg.Main.Janitor.main + _ -> do + app <- Zureg.Hackathon.withHackathonFromEnv Web.app + mRuntime $ WaiHandler.run app diff --git a/stack.yaml b/stack.yaml index 1d5eaaf..8c53226 100644 --- a/stack.yaml +++ b/stack.yaml @@ -9,6 +9,7 @@ extra-deps: - 'hal-1.0.0.1' - 'unliftio-core-0.1.2.0' - 'urlencoded-0.5.0.0' +- 'wai-handler-hal-0.2.0.0' nix: packages: - 'zlib' diff --git a/stack.yaml.lock b/stack.yaml.lock index 3c14bbb..ef52e9f 100644 --- a/stack.yaml.lock +++ b/stack.yaml.lock @@ -53,6 +53,13 @@ packages: sha256: dc94e84bac66430bca207639fc8a2f1a37a88834c8f6572a0345f70298d6d0d1 original: hackage: urlencoded-0.5.0.0 +- completed: + hackage: wai-handler-hal-0.2.0.0@sha256:ef98b78c3beb05eecc9239775dd010308ed7a75b76a0db8471d4466a76b450f8,2954 + pantry-tree: + size: 592 + sha256: e500f789cb7b0dab089768a512e7703ad93407a73635a3cf1aa1081233c04ba5 + original: + hackage: wai-handler-hal-0.2.0.0 snapshots: - completed: size: 586286 diff --git a/zureg.cabal b/zureg.cabal index 85a3e89..8adeb95 100644 --- a/zureg.cabal +++ b/zureg.cabal @@ -93,7 +93,6 @@ Library eventful-dynamodb >= 0.2 && < 0.3, file-embed >= 0.0 && < 0.1, filepath >= 1.4 && < 1.5, - hal >= 1.0 && < 1.1, http-client >= 0.5 && < 0.7, http-client-tls >= 0.3 && < 0.4, http-types >= 0.12 && < 0.13, @@ -148,4 +147,7 @@ Executable zureg-badges Executable zureg-janitor-lambda Import: exe Main-is: Janitor.hs - Build-depends: aeson, hal + Build-depends: + aeson >= 1.3 && < 1.6, + hal >= 1.0 && < 1.1, + wai-handler-hal >= 0.2 && < 0.3