Upload snapshots.json to S3 (commercialhaskell/stack#380)

This commit is contained in:
Michael Snoyman 2015-06-23 11:01:28 +03:00
parent b71e551737
commit 8f20a226fe
3 changed files with 35 additions and 20 deletions

View File

@ -41,25 +41,7 @@ getDownloadSnapshotsJsonR :: Handler Value
getDownloadSnapshotsJsonR = getDownloadLtsSnapshotsJsonR getDownloadSnapshotsJsonR = getDownloadLtsSnapshotsJsonR
getDownloadLtsSnapshotsJsonR :: Handler Value getDownloadLtsSnapshotsJsonR :: Handler Value
getDownloadLtsSnapshotsJsonR = do getDownloadLtsSnapshotsJsonR = snapshotsJSON
mlatestNightly <- newestNightly
ltses <- ltsMajorVersions
let lts = case ltses of
[] -> []
majorVersions@(latest:_) ->
("lts" .= printLts latest)
: map toObj majorVersions
nightly = case mlatestNightly of
Nothing -> id
Just n -> (("nightly" .= printNightly n):)
return $ object $ nightly lts
where
toObj lts@(major, _) =
pack ("lts-" ++ show major) .= printLts lts
printLts (major, minor) =
"lts-" ++ show major ++ "." ++ show minor
printNightly day = "nightly-" ++ tshow day
-- Print the ghc major version for the given snapshot. -- Print the ghc major version for the given snapshot.
ghcMajorVersionText :: Snapshot -> Text ghcMajorVersionText :: Snapshot -> Text

View File

@ -31,6 +31,7 @@ module Stackage.Database
, getSnapshots , getSnapshots
, currentSchema , currentSchema
, last5Lts5Nightly , last5Lts5Nightly
, snapshotsJSON
) where ) where
import Database.Sqlite (SqliteException) import Database.Sqlite (SqliteException)
@ -61,6 +62,7 @@ import Control.Monad.Logger
import System.IO.Temp import System.IO.Temp
import qualified Database.Esqueleto as E import qualified Database.Esqueleto as E
import Data.Yaml (decode) import Data.Yaml (decode)
import qualified Data.Aeson as A
currentSchema :: Int currentSchema :: Int
currentSchema = 1 currentSchema = 1
@ -652,3 +654,24 @@ last5Lts5Nightly = run $ do
where where
l (Entity _ x) = SNLts (ltsMajor x) (ltsMinor x) l (Entity _ x) = SNLts (ltsMajor x) (ltsMinor x)
n (Entity _ x) = SNNightly (nightlyDay x) n (Entity _ x) = SNNightly (nightlyDay x)
snapshotsJSON :: GetStackageDatabase m => m A.Value
snapshotsJSON = do
mlatestNightly <- newestNightly
ltses <- ltsMajorVersions
let lts = case ltses of
[] -> []
majorVersions@(latest:_) ->
("lts" A..= printLts latest)
: map toObj majorVersions
nightly = case mlatestNightly of
Nothing -> id
Just n -> (("nightly" A..= printNightly n):)
return $ A.object $ nightly lts
where
toObj lts@(major, _) =
pack ("lts-" ++ show major) A..= printLts lts
printLts (major, minor) =
"lts-" ++ show major ++ "." ++ show minor
printNightly day = "nightly-" ++ tshow day

View File

@ -31,6 +31,9 @@ import qualified Data.Conduit.Binary as CB
import Data.Conduit.Zlib (WindowBits (WindowBits), import Data.Conduit.Zlib (WindowBits (WindowBits),
compress, ungzip) compress, ungzip)
import qualified Hoogle import qualified Hoogle
import System.IO.Temp (withSystemTempFile)
import qualified Data.Aeson as A
import qualified Data.ByteString.Lazy as L
filename' :: Text filename' :: Text
filename' = concat filename' = concat
@ -163,6 +166,13 @@ stackageServerCron = do
upload dbfp keyName upload dbfp keyName
db <- openStackageDatabase dbfp db <- openStackageDatabase dbfp
snapshots <- runReaderT snapshotsJSON db
withSystemTempFile "snapshots.json" $ \fp h -> do
L.hPut h $ A.encode snapshots
hClose h
upload (fpFromString fp) "snapshots.json"
names <- runReaderT last5Lts5Nightly db names <- runReaderT last5Lts5Nightly db
let manager = view envManager env let manager = view envManager env
forM_ names $ \name -> do forM_ names $ \name -> do