mirror of
https://github.com/Start9Labs/registry.git
synced 2026-03-26 02:11:53 +00:00
code logic for version checkpoints instead of env vars for more optionality (#135)
This commit is contained in:
@@ -36,8 +36,7 @@ tor-port: "_env:TOR_PORT:447"
|
||||
static-bin-dir: "_env:STATIC_BIN:/usr/local/bin/"
|
||||
error-log-root: "_env:ERROR_LOG_ROOT:/var/log/registry/"
|
||||
marketplace-name: "_env:MARKETPLACE_NAME:CHANGE ME"
|
||||
max-eos-version: "_env:MAX_VERSION:0.3.4.0"
|
||||
min-eos-version: "_env:MIN_VERSION:0.3.4.0"
|
||||
community-version: "_env:COMMUNITY_VERSION:0.3.3.0"
|
||||
run-migration: "_env:RUN_MIGRATION:false"
|
||||
whitelist: "_env:WHITELIST:"
|
||||
|
||||
|
||||
@@ -11,7 +11,7 @@ import Database.Persist.Sql (
|
||||
SqlBackend,
|
||||
)
|
||||
import Lib.Types.Core (
|
||||
PkgId, OsArch (X86_64, AARCH64),
|
||||
PkgId, OsArch (X86_64, AARCH64_NONFREE),
|
||||
)
|
||||
import Lib.Types.Emver (Version)
|
||||
import Model (
|
||||
@@ -330,7 +330,7 @@ upsertPackageVersionPlatform :: (MonadUnliftIO m) => PackageManifest -> ReaderT
|
||||
upsertPackageVersionPlatform PackageManifest{..} = do
|
||||
now <- liftIO getCurrentTime
|
||||
let pkgId = PkgRecordKey packageManifestId
|
||||
let arches = [X86_64, AARCH64]
|
||||
let arches = [X86_64 .. AARCH64_NONFREE]
|
||||
let records = createVersionPlatformRecord now pkgId packageManifestVersion <$> arches
|
||||
repsertMany records
|
||||
where
|
||||
|
||||
@@ -17,18 +17,18 @@ import Database.Esqueleto.Experimental (
|
||||
(^.),
|
||||
(==.)
|
||||
)
|
||||
import Foundation (Handler, RegistryCtx (appSettings))
|
||||
import Foundation (Handler)
|
||||
import Handler.Package.V0.ReleaseNotes (ReleaseNotes (..))
|
||||
import Handler.Util (queryParamAs, getArchQuery)
|
||||
import Lib.Types.Emver (Version (unVersion), Version(Version), parseVersion)
|
||||
import Model (EntityField (..), OsVersion (..))
|
||||
import Orphans.Emver ()
|
||||
import Startlude (Down (..), Eq, Generic, Maybe (..), Ord ((<)), Show, Text, filter, fst, head, pure, sortOn, ($), (&&&), (.), (<$>), (<&>), (<=))
|
||||
import Yesod (ToContent (toContent), ToTypedContent (..), YesodPersist (runDB), getsYesod)
|
||||
import Startlude (Down (..), Eq, Generic, Maybe (..), Ord ((<)), Text, filter, fst, head, pure, sortOn, ($), (&&&), (.), (<$>), (<&>), (<=))
|
||||
import Yesod (ToContent (toContent), ToTypedContent (..), YesodPersist (runDB))
|
||||
import Yesod.Core.Types (JSONResponse (..))
|
||||
import Settings (AppSettings(maxOsVersion))
|
||||
import Lib.Types.Core (OsArch(RASPBERRYPI))
|
||||
import Data.Maybe (fromMaybe)
|
||||
import GHC.Show
|
||||
|
||||
|
||||
data EosRes = EosRes
|
||||
@@ -49,15 +49,15 @@ instance ToTypedContent EosRes where
|
||||
getEosVersionR :: Handler (JSONResponse (Maybe EosRes))
|
||||
getEosVersionR = do
|
||||
currentEosVersion <- fromMaybe Version { unVersion = (0,3,0,0) } <$> queryParamAs "eos-version" parseVersion
|
||||
-- defaults to raspberrypi for those on OS versions where we did not send this param yet
|
||||
arch <- fromMaybe RASPBERRYPI <$> getArchQuery
|
||||
maxVersion <- getsYesod $ maxOsVersion . appSettings
|
||||
allEosVersions <- runDB $
|
||||
select $ do
|
||||
vers <- from $ table @OsVersion
|
||||
where_ (vers ^. OsVersionArch ==. val (Just arch))
|
||||
orderBy [desc (vers ^. OsVersionNumber)]
|
||||
pure vers
|
||||
let osV = determineMaxEosVersionAvailable maxVersion currentEosVersion $ entityVal <$> allEosVersions
|
||||
let osV = determineMaxOsVersionAvailable currentEosVersion $ entityVal <$> allEosVersions
|
||||
let mLatest = head osV
|
||||
let mappedVersions =
|
||||
ReleaseNotes $
|
||||
@@ -74,8 +74,10 @@ getEosVersionR = do
|
||||
, 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
|
||||
determineMaxOsVersionAvailable :: Version -> [OsVersion] -> [OsVersion]
|
||||
determineMaxOsVersionAvailable currentEosVersion versions = do
|
||||
if (currentEosVersion < Version (0,3,2,1))
|
||||
then sortOn (Down . osVersionNumber) $ filter (\v -> osVersionNumber v <= Version(0,3,2,1)) $ versions
|
||||
else if (currentEosVersion < Version(0,3,4,0))
|
||||
then sortOn (Down . osVersionNumber) $ filter (\v -> osVersionNumber v <= Version(0,3,4,0)) $ versions
|
||||
else versions
|
||||
@@ -20,7 +20,7 @@ import Startlude (Bool (True), Down (Down), Either (..), Generic, Maybe (..), No
|
||||
import Yesod (ToContent (..), ToTypedContent (..), YesodPersist (runDB), YesodRequest (reqGetParams), getRequest, sendResponseStatus)
|
||||
import Handler.Util (getArchQuery, filterDeprecatedVersions)
|
||||
import Yesod.Core (getsYesod)
|
||||
import Settings (AppSettings(minOsVersion))
|
||||
import Settings (AppSettings(communityVersion))
|
||||
|
||||
|
||||
newtype VersionLatestRes = VersionLatestRes (HashMap PkgId (Maybe Version))
|
||||
@@ -40,7 +40,7 @@ getVersionLatestR = do
|
||||
Nothing -> const True
|
||||
Just v -> flip satisfies v
|
||||
osArch <- getArchQuery
|
||||
minOsVersion <- getsYesod $ minOsVersion . appSettings
|
||||
communityServiceDeprecationVersion <- getsYesod $ communityVersion . appSettings
|
||||
do
|
||||
case lookup "ids" getParameters of
|
||||
Nothing -> sendResponseStatus status400 (InvalidParamsE "get:ids" "<MISSING>")
|
||||
@@ -57,8 +57,8 @@ getVersionLatestR = do
|
||||
.| collateVersions
|
||||
-- filter out versions of apps that are incompatible with the OS predicate
|
||||
.| mapC (second (filter (osPredicate' . versionRecordOsVersion)))
|
||||
-- filter out deprecated service versions after a min os version
|
||||
.| mapC (second (filterDeprecatedVersions minOsVersion osPredicate'))
|
||||
-- filter out deprecated service versions after community registry release
|
||||
.| mapC (second (filterDeprecatedVersions communityServiceDeprecationVersion osPredicate'))
|
||||
-- prune empty version sets
|
||||
.| concatMapC (\(pkgId, vs) -> (pkgId,) <$> nonEmpty vs)
|
||||
-- grab the latest matching version if it exists
|
||||
|
||||
@@ -34,7 +34,7 @@ import Lib.Types.Core (PkgId)
|
||||
import Lib.Types.Emver (Version, VersionRange (..), parseRange, satisfies, (<||))
|
||||
import Model (Category (..), Key (..), PkgDependency (..), VersionRecord (..), PkgRecord (pkgRecordHidden))
|
||||
import Protolude.Unsafe (unsafeFromJust)
|
||||
import Settings (AppSettings (minOsVersion))
|
||||
import Settings (AppSettings (communityVersion))
|
||||
import Startlude (
|
||||
Applicative ((*>)),
|
||||
Bifunctor (..),
|
||||
@@ -119,7 +119,7 @@ getPackageIndexR = do
|
||||
Nothing -> const True
|
||||
Just v -> flip satisfies v
|
||||
osArch <- getArchQuery
|
||||
minOsVersion <- getsYesod $ minOsVersion . appSettings
|
||||
communityVersion <- getsYesod $ communityVersion . appSettings
|
||||
do
|
||||
pkgIds <- getPkgIdsQuery
|
||||
category <- getCategoryQuery
|
||||
@@ -140,8 +140,8 @@ getPackageIndexR = do
|
||||
.| collateVersions
|
||||
-- filter out versions of apps that are incompatible with the OS predicate
|
||||
.| mapC (second (filter (osPredicate . versionRecordOsVersion)))
|
||||
-- filter out deprecated service versions after a min os version
|
||||
.| mapC (second (filterDeprecatedVersions minOsVersion osPredicate))
|
||||
-- filter out deprecated service versions after community registry release
|
||||
.| mapC (second (filterDeprecatedVersions communityVersion osPredicate))
|
||||
-- prune empty version sets
|
||||
.| concatMapC (\(pkgId, vs) -> (pkgId,) <$> nonEmpty vs)
|
||||
-- grab the latest matching version if it exists
|
||||
|
||||
@@ -178,7 +178,7 @@ getArchQuery :: Handler (Maybe OsArch)
|
||||
getArchQuery = parseQueryParam "arch" ((flip $ note . mappend "Invalid 'arch': ") =<< readMaybe)
|
||||
|
||||
filterDeprecatedVersions :: Version -> (Version -> Bool) -> [VersionRecord] -> [VersionRecord]
|
||||
filterDeprecatedVersions minOsVersion osPredicate vrs = do
|
||||
if (osPredicate minOsVersion)
|
||||
filterDeprecatedVersions communityVersion osPredicate vrs = do
|
||||
if (osPredicate communityVersion)
|
||||
then filter (\v -> not $ isJust $ versionRecordDeprecatedAt v) $ vrs
|
||||
else vrs
|
||||
@@ -27,7 +27,7 @@ import Startlude (
|
||||
show,
|
||||
symbolVal,
|
||||
($),
|
||||
(.),
|
||||
(.), Enum,
|
||||
)
|
||||
|
||||
import Data.Aeson (
|
||||
@@ -89,17 +89,21 @@ instance PathPiece PkgId where
|
||||
fromPathPiece = fmap PkgId . fromPathPiece
|
||||
toPathPiece = unPkgId
|
||||
|
||||
data OsArch = X86_64 | AARCH64 | RASPBERRYPI
|
||||
deriving (Eq, Ord)
|
||||
data OsArch = X86_64 | AARCH64 | RASPBERRYPI | X86_64_NONFREE | AARCH64_NONFREE
|
||||
deriving (Eq, Ord, Enum)
|
||||
instance Show OsArch where
|
||||
show X86_64 = "x86_64"
|
||||
show AARCH64 = "aarch64"
|
||||
show RASPBERRYPI = "raspberrypi"
|
||||
show X86_64_NONFREE = "x86_64-nonfree"
|
||||
show AARCH64_NONFREE = "aarch64-nonfree"
|
||||
instance Read OsArch where
|
||||
readsPrec _ "x86_64" = [(X86_64, "")]
|
||||
readsPrec _ "aarch64" = [(AARCH64, "")]
|
||||
readsPrec _ "raspberrypi" = [(RASPBERRYPI, "")]
|
||||
readsPrec _ "rasberrypi" = [(RASPBERRYPI, "")]
|
||||
readsPrec _ "x86_64-nonfree" = [(X86_64_NONFREE, "")]
|
||||
readsPrec _ "aarch64-nonfree" = [(AARCH64_NONFREE, "")]
|
||||
readsPrec _ _ = []
|
||||
instance PersistField OsArch where
|
||||
toPersistValue = PersistText . show
|
||||
|
||||
@@ -80,8 +80,7 @@ data AppSettings = AppSettings
|
||||
-- ^ Should all log messages be displayed?
|
||||
, errorLogRoot :: !FilePath
|
||||
, marketplaceName :: !Text
|
||||
, maxOsVersion :: !Version
|
||||
, minOsVersion :: !Version
|
||||
, communityVersion :: !Version
|
||||
, registryHostname :: !Text
|
||||
, registryVersion :: !Version
|
||||
, resourcesDir :: !FilePath
|
||||
@@ -117,8 +116,7 @@ instance FromJSON AppSettings where
|
||||
appShouldLogAll <- o .:? "should-log-all" .!= False
|
||||
errorLogRoot <- o .: "error-log-root"
|
||||
marketplaceName <- o .: "marketplace-name"
|
||||
maxOsVersion <- o .: "max-eos-version"
|
||||
minOsVersion <- o .: "min-eos-version"
|
||||
communityVersion <- o .: "community-version"
|
||||
registryHostname <- o .: "registry-hostname"
|
||||
resourcesDir <- o .: "resources-path"
|
||||
needsMigration <- o .: "run-migration"
|
||||
|
||||
Reference in New Issue
Block a user