diff --git a/config/settings.yml b/config/settings.yml index 7392b35..d81150e 100644 --- a/config/settings.yml +++ b/config/settings.yml @@ -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:" diff --git a/src/Database/Queries.hs b/src/Database/Queries.hs index 8243d87..b0e83ec 100644 --- a/src/Database/Queries.hs +++ b/src/Database/Queries.hs @@ -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 diff --git a/src/Handler/Eos/V0/Latest.hs b/src/Handler/Eos/V0/Latest.hs index 3ad5480..6543355 100644 --- a/src/Handler/Eos/V0/Latest.hs +++ b/src/Handler/Eos/V0/Latest.hs @@ -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 - else versions \ No newline at end of file +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 \ No newline at end of file diff --git a/src/Handler/Package/V0/Latest.hs b/src/Handler/Package/V0/Latest.hs index 06ff4fd..83068a1 100644 --- a/src/Handler/Package/V0/Latest.hs +++ b/src/Handler/Package/V0/Latest.hs @@ -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" "") @@ -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 diff --git a/src/Handler/Package/V1/Index.hs b/src/Handler/Package/V1/Index.hs index 3fa413d..317488c 100644 --- a/src/Handler/Package/V1/Index.hs +++ b/src/Handler/Package/V1/Index.hs @@ -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 diff --git a/src/Handler/Util.hs b/src/Handler/Util.hs index 4559c2d..4708c4c 100644 --- a/src/Handler/Util.hs +++ b/src/Handler/Util.hs @@ -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 \ No newline at end of file diff --git a/src/Lib/Types/Core.hs b/src/Lib/Types/Core.hs index 519729c..9bb2271 100644 --- a/src/Lib/Types/Core.hs +++ b/src/Lib/Types/Core.hs @@ -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 diff --git a/src/Settings.hs b/src/Settings.hs index 1921be0..5c94d1a 100644 --- a/src/Settings.hs +++ b/src/Settings.hs @@ -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"