mirror of
https://github.com/Start9Labs/registry.git
synced 2026-03-31 04:03:40 +00:00
fix max eos version available logic; toggle migrations
This commit is contained in:
1
.gitignore
vendored
1
.gitignore
vendored
@@ -39,3 +39,4 @@ start9-registry.ps
|
|||||||
shell.nix
|
shell.nix
|
||||||
testdata/
|
testdata/
|
||||||
lbuild.sh
|
lbuild.sh
|
||||||
|
icon
|
||||||
@@ -37,6 +37,8 @@ static-bin-dir: "_env:STATIC_BIN:/usr/local/bin/"
|
|||||||
error-log-root: "_env:ERROR_LOG_ROOT:/var/log/registry/"
|
error-log-root: "_env:ERROR_LOG_ROOT:/var/log/registry/"
|
||||||
marketplace-name: "_env:MARKETPLACE_NAME:CHANGE ME"
|
marketplace-name: "_env:MARKETPLACE_NAME:CHANGE ME"
|
||||||
icon-path: "_env:ICON_PATH:/var/www/html/resources"
|
icon-path: "_env:ICON_PATH:/var/www/html/resources"
|
||||||
|
max-eos-version: "_env:MAX_VERSION:0.3.3.0"
|
||||||
|
run-migration: "_env:RUN_MIGRATION:false"
|
||||||
|
|
||||||
database:
|
database:
|
||||||
database: "_env:PG_DATABASE:start9_registry"
|
database: "_env:PG_DATABASE:start9_registry"
|
||||||
|
|||||||
@@ -254,11 +254,14 @@ makeFoundation appSettings = do
|
|||||||
flip runLoggingT logFunc $
|
flip runLoggingT logFunc $
|
||||||
createPostgresqlPool (pgConnStr $ appDatabaseConf appSettings) (pgPoolSize . appDatabaseConf $ appSettings)
|
createPostgresqlPool (pgConnStr $ appDatabaseConf appSettings) (pgPoolSize . appDatabaseConf $ appSettings)
|
||||||
|
|
||||||
runSqlPool
|
if (needsMigration appSettings)
|
||||||
(Database.Persist.Migration.Postgres.runMigration Database.Persist.Migration.defaultSettings manualMigration)
|
then
|
||||||
pool
|
runSqlPool
|
||||||
-- Preform database migration using application logging settings
|
(Database.Persist.Migration.Postgres.runMigration Database.Persist.Migration.defaultSettings manualMigration)
|
||||||
runLoggingT (runSqlPool (runMigration migrateAll) pool) logFunc
|
pool
|
||||||
|
else
|
||||||
|
-- Preform database migration using application logging settings
|
||||||
|
runLoggingT (runSqlPool (runMigration migrateAll) pool) logFunc
|
||||||
|
|
||||||
-- Return the foundation
|
-- Return the foundation
|
||||||
return $ mkFoundation pool
|
return $ mkFoundation pool
|
||||||
|
|||||||
@@ -1,4 +1,5 @@
|
|||||||
{-# LANGUAGE RecordWildCards #-}
|
{-# LANGUAGE RecordWildCards #-}
|
||||||
|
{-# LANGUAGE TemplateHaskell #-}
|
||||||
|
|
||||||
module Handler.Eos.V0.Latest where
|
module Handler.Eos.V0.Latest where
|
||||||
|
|
||||||
@@ -13,15 +14,18 @@ import Database.Esqueleto.Experimental (
|
|||||||
table,
|
table,
|
||||||
(^.),
|
(^.),
|
||||||
)
|
)
|
||||||
import Foundation (Handler)
|
import Foundation (Handler, RegistryCtx (appSettings))
|
||||||
import Handler.Package.V0.ReleaseNotes (ReleaseNotes (..))
|
import Handler.Package.V0.ReleaseNotes (ReleaseNotes (..))
|
||||||
import Handler.Util (queryParamAs, tickleMAU)
|
import Handler.Util (queryParamAs, tickleMAU)
|
||||||
import Lib.Types.Emver (Version, parseVersion)
|
import Lib.Types.Emver (Version, parseVersion)
|
||||||
import Model (EntityField (..), OsVersion (..))
|
import Model (EntityField (..), OsVersion (..))
|
||||||
import Orphans.Emver ()
|
import Orphans.Emver ()
|
||||||
import Startlude (Bool (..), Down (..), Eq, Generic, Maybe, Ord ((<)), Show, Text, const, filter, fst, head, maybe, pure, sortOn, ($), (&&&), (.), (<$>), (<&>))
|
import Startlude (Bool (..), Down (..), Eq, Generic, Maybe (..), Ord ((<)), Show, Text, const, filter, fst, head, maybe, pure, sortOn, ($), (&&&), (.), (<$>), (<&>), (<=))
|
||||||
import Yesod (ToContent (toContent), ToTypedContent (..), YesodPersist (runDB))
|
import Yesod (ToContent (toContent), ToTypedContent (..), YesodPersist (runDB), getsYesod, sendResponseStatus)
|
||||||
import Yesod.Core.Types (JSONResponse (..))
|
import Yesod.Core.Types (JSONResponse (..))
|
||||||
|
import Settings (AppSettings(maxEosVersion))
|
||||||
|
import Network.HTTP.Types (status400)
|
||||||
|
import Lib.Error (S9Error(InvalidParamsE))
|
||||||
|
|
||||||
|
|
||||||
data EosRes = EosRes
|
data EosRes = EosRes
|
||||||
@@ -41,26 +45,36 @@ instance ToTypedContent EosRes where
|
|||||||
|
|
||||||
getEosVersionR :: Handler (JSONResponse (Maybe EosRes))
|
getEosVersionR :: Handler (JSONResponse (Maybe EosRes))
|
||||||
getEosVersionR = do
|
getEosVersionR = do
|
||||||
eosVersion <- queryParamAs "eos-version" parseVersion
|
currentEosVersion <- queryParamAs "eos-version" parseVersion
|
||||||
allEosVersions <- runDB $
|
case currentEosVersion of
|
||||||
select $ do
|
Nothing -> sendResponseStatus status400 (InvalidParamsE "Param is required" "eos-version")
|
||||||
vers <- from $ table @OsVersion
|
Just currentEosVersion' -> do
|
||||||
orderBy [desc (vers ^. OsVersionCreatedAt)]
|
maxVersion <- getsYesod $ maxEosVersion . appSettings
|
||||||
pure vers
|
allEosVersions <- runDB $
|
||||||
let osV = entityVal <$> allEosVersions
|
select $ do
|
||||||
let mLatest = head osV
|
vers <- from $ table @OsVersion
|
||||||
let mappedVersions =
|
orderBy [desc (vers ^. OsVersionNumber)]
|
||||||
ReleaseNotes $
|
pure vers
|
||||||
HM.fromList $
|
let osV = determineMaxEosVersionAvailable maxVersion currentEosVersion' $ entityVal <$> allEosVersions
|
||||||
sortOn (Down . fst) $
|
let mLatest = head osV
|
||||||
filter (maybe (const True) (<) eosVersion . fst) $
|
let mappedVersions =
|
||||||
((osVersionNumber &&& osVersionReleaseNotes))
|
ReleaseNotes $
|
||||||
<$> osV
|
HM.fromList $
|
||||||
tickleMAU
|
sortOn (Down . fst) $
|
||||||
pure . JSONResponse $
|
filter (maybe (const True) (<) currentEosVersion . fst) $
|
||||||
mLatest <&> \latest ->
|
((osVersionNumber &&& osVersionReleaseNotes))
|
||||||
EosRes
|
<$> osV
|
||||||
{ eosResVersion = osVersionNumber latest
|
tickleMAU
|
||||||
, eosResHeadline = osVersionHeadline latest
|
pure . JSONResponse $
|
||||||
, eosResReleaseNotes = mappedVersions
|
mLatest <&> \latest ->
|
||||||
}
|
EosRes
|
||||||
|
{ eosResVersion = osVersionNumber latest
|
||||||
|
, eosResHeadline = osVersionHeadline latest
|
||||||
|
, eosResReleaseNotes = mappedVersions
|
||||||
|
}
|
||||||
|
|
||||||
|
determineMaxEosVersionAvailable :: Version -> Version -> [OsVersion] -> [OsVersion]
|
||||||
|
determineMaxEosVersionAvailable maxEosVersion currentEosVersion versions = do
|
||||||
|
if (currentEosVersion < maxEosVersion)
|
||||||
|
then sortOn (Down . osVersionNumber) $ filter (\v -> osVersionNumber v <= maxEosVersion) $ versions
|
||||||
|
else versions
|
||||||
@@ -76,9 +76,11 @@ data AppSettings = AppSettings
|
|||||||
, iconPath :: !FilePath
|
, iconPath :: !FilePath
|
||||||
, errorLogRoot :: !FilePath
|
, errorLogRoot :: !FilePath
|
||||||
, marketplaceName :: !Text
|
, marketplaceName :: !Text
|
||||||
|
, maxEosVersion :: !Version
|
||||||
, registryHostname :: !Text
|
, registryHostname :: !Text
|
||||||
, registryVersion :: !Version
|
, registryVersion :: !Version
|
||||||
, resourcesDir :: !FilePath
|
, resourcesDir :: !FilePath
|
||||||
|
, needsMigration :: !Bool
|
||||||
, sslAuto :: !Bool
|
, sslAuto :: !Bool
|
||||||
, sslCertLocation :: !FilePath
|
, sslCertLocation :: !FilePath
|
||||||
, sslCsrLocation :: !FilePath
|
, sslCsrLocation :: !FilePath
|
||||||
@@ -110,8 +112,10 @@ instance FromJSON AppSettings where
|
|||||||
errorLogRoot <- o .: "error-log-root"
|
errorLogRoot <- o .: "error-log-root"
|
||||||
iconPath <- o .: "icon-path"
|
iconPath <- o .: "icon-path"
|
||||||
marketplaceName <- o .: "marketplace-name"
|
marketplaceName <- o .: "marketplace-name"
|
||||||
|
maxEosVersion <- o .: "max-eos-version"
|
||||||
registryHostname <- o .: "registry-hostname"
|
registryHostname <- o .: "registry-hostname"
|
||||||
resourcesDir <- o .: "resources-path"
|
resourcesDir <- o .: "resources-path"
|
||||||
|
needsMigration <- o .: "run-migration"
|
||||||
sslAuto <- o .: "ssl-auto"
|
sslAuto <- o .: "ssl-auto"
|
||||||
sslPath <- o .: "ssl-path"
|
sslPath <- o .: "ssl-path"
|
||||||
staticBinDir <- o .: "static-bin-dir"
|
staticBinDir <- o .: "static-bin-dir"
|
||||||
|
|||||||
Reference in New Issue
Block a user