From 9440cb66a88425fb8614169a88768c7d03c84035 Mon Sep 17 00:00:00 2001 From: iko Date: Sun, 26 Sep 2021 19:36:10 +0300 Subject: [PATCH] Added the build git commit sha to ping endpoint (#110) * Added the build git commit sha to ping endpoint * Fixed CI --- default.nix | 18 +++++++++++++++++- octopod-api/src/Octopod/API.hs | 2 +- octopod-backend/app/Main.hs | 6 +++++- octopod-backend/octopod-backend.cabal | 2 ++ octopod-backend/src/Octopod/Server.hs | 13 +++++++++---- octopod-frontend/src/Frontend/API.hs | 7 +------ 6 files changed, 35 insertions(+), 13 deletions(-) diff --git a/default.nix b/default.nix index 6c6023e..5196dd2 100644 --- a/default.nix +++ b/default.nix @@ -32,7 +32,23 @@ let dontStrip = false; dontPatchELF = false; enableDeadCodeElimination = true; - packages.octopod-backend = addLocalOptions { src = ./octopod-backend; }; + packages.octopod-backend = addLocalOptions ( + if prod + then { + src = pkgs.runCommand "octopod-backend-src" { } + '' + mkdir -p $out + cp -r ${./octopod-backend}/* $out + cp -r ${builtins.path { path = ./.git; name = "dot-git"; }}/ $out/.git/ + ''; + components.exes.octopod-exe = { + build-tools = + pkgs.lib.mkForce [ pkgs.buildPackages.buildPackages.gitReallyMinimal ]; + extraSrcFiles = [ ".git/**/*" ]; + }; + } + else { src = ./octopod-backend; } + ); packages.octo-cli = addLocalOptions { src = ./octo-cli; }; packages.octopod-api = addLocalOptions { src = ./octopod-api; }; packages.octopod-frontend = addLocalOptions { src = ./octopod-frontend; }; diff --git a/octopod-api/src/Octopod/API.hs b/octopod-api/src/Octopod/API.hs index 2cab34e..fd4595b 100644 --- a/octopod-api/src/Octopod/API.hs +++ b/octopod-api/src/Octopod/API.hs @@ -42,7 +42,7 @@ type DefaultApplicationOverrides = :> ReqBody '[JSON] (Config 'DeploymentLevel) :> Post '[JSON] (DefaultConfig 'ApplicationLevel) -type PingEndpoint = "ping" :> GetNoContent +type PingEndpoint = "ping" :> Get '[PlainText] Text type ProjectNameEndpoint = "project_name" :> Get '[JSON] ProjectName diff --git a/octopod-backend/app/Main.hs b/octopod-backend/app/Main.hs index dede7a9..728b767 100644 --- a/octopod-backend/app/Main.hs +++ b/octopod-backend/app/Main.hs @@ -1,6 +1,10 @@ +{-# LANGUAGE TemplateHaskell #-} + module Main (main) where +import qualified Data.Text as T +import Development.GitRev import Octopod.Server main :: IO () -main = runOctopodServer +main = runOctopodServer (T.pack $gitHash) diff --git a/octopod-backend/octopod-backend.cabal b/octopod-backend/octopod-backend.cabal index 5600546..d970bc7 100644 --- a/octopod-backend/octopod-backend.cabal +++ b/octopod-backend/octopod-backend.cabal @@ -137,4 +137,6 @@ executable octopod-exe build-depends: base >=4.7 && <5 , octopod-backend + , gitrev + , text default-language: Haskell2010 diff --git a/octopod-backend/src/Octopod/Server.hs b/octopod-backend/src/Octopod/Server.hs index d55f576..c9fe7da 100644 --- a/octopod-backend/src/Octopod/Server.hs +++ b/octopod-backend/src/Octopod/Server.hs @@ -130,6 +130,7 @@ data AppState = AppState , depOverrideKeysCache :: CacheMap ServerError AppM' () [Text] , appOverridesCache :: CacheMap ServerError AppM' (Config 'DeploymentLevel) (DefaultConfig 'ApplicationLevel) , appOverrideKeysCache :: CacheMap ServerError AppM' (Config 'DeploymentLevel) [Text] + , gitSha :: Text } deriving stock (Generic) @@ -154,8 +155,11 @@ data FullInfoListType | FullInfoOnlyForOne DeploymentName deriving stock (Show) -runOctopodServer :: IO () -runOctopodServer = do +runOctopodServer :: + -- | The git SHA + Text -> + IO () +runOctopodServer sha = do logger' <- newLogger logInfo logger' "started" bgWorkersC <- newIORef 0 @@ -257,6 +261,7 @@ runOctopodServer = do , depOverrideKeysCache = depOverrideKeysCache' , appOverridesCache = appOverridesCache' , appOverrideKeysCache = appOverrideKeysCache' + , gitSha = sha } app' = app appSt @@ -885,10 +890,10 @@ getInfo dName = do } -- | Handles the 'ping' request. -pingH :: AppM NoContent +pingH :: AppM Text pingH = do _ <- runStatement $ select $ pure $ litExpr True - pure NoContent + asks gitSha -- | Handles the 'project_name' request. projectNameH :: AppM ProjectName diff --git a/octopod-frontend/src/Frontend/API.hs b/octopod-frontend/src/Frontend/API.hs index 342fa37..f112ad9 100644 --- a/octopod-frontend/src/Frontend/API.hs +++ b/octopod-frontend/src/Frontend/API.hs @@ -21,7 +21,6 @@ module Frontend.API fullInfoEndpoint, statusEndpoint, restoreEndpoint, - pingEndpoint, projectName, commandResponse, wsPath, @@ -127,10 +126,6 @@ restoreEndpoint :: Dynamic t (Either Text DeploymentName) -> Event t () -> m (Event t (ReqResult () CommandResponse)) -pingEndpoint :: - MonadWidget t m => - Event t () -> - m (Event t (ReqResult () NoContent)) projectName :: MonadWidget t m => Event t () -> @@ -148,7 +143,7 @@ deploymentOverrideKeys :<|> statusEndpoint :<|> restoreEndpoint ) - :<|> pingEndpoint + :<|> _pingEndpoint :<|> projectName = apiClients -- | Parser of kubectl command responses.