on master help sign in
Provide options for v2 uploads
commit923d655e0900dfc642a7a4b588f52339e6a42e4e authorMichael Snoyman <michael@snoyman.com> dateMon 16 Mar 2015, 17:17 (12 years ago) parent43639bd
5 files changed+94−41
ChangeLog.md+1−1 Stackage/CompleteBuild.hs+52−37 Stackage/Upload.hs+3 app/stackage.hs+34−2 stackage.cabal+4−1
ChangeLog.md+1−1
@@ -1,4 +1,4 @@
1−## Unreleased
1+## 0.6.0
22
33* Upload bundle V2 stuff
44
Stackage/CompleteBuild.hs+52−37
@@ -8,6 +8,7 @@ module Stackage.CompleteBuild
88 , completeBuild
99 , justCheck
1010 , justUploadNightly
11+ , getStackageAuthToken
1112 ) where
1213
1314import Control.Concurrent (threadDelay)
@@ -39,6 +40,7 @@ data BuildFlags = BuildFlags
3940 , bfEnableExecDyn :: !Bool
4041 , bfVerbose :: !Bool
4142 , bfSkipCheck :: !Bool
43+ , bfUploadV2 :: !Bool
4244 } deriving (Show)
4345
4446data BuildType = Nightly | LTS BumpType
@@ -251,7 +253,7 @@ completeBuild buildType buildFlags = withManager tlsManagerSettings $ \man -> do
251253 }
252254
253255 when (bfDoUpload buildFlags) $
254− finallyUpload settings man
256+ finallyUpload (bfUploadV2 buildFlags) settings man
255257
256258justUploadNightly
257259 :: Text -- ^ nightly date
@@ -259,40 +261,62 @@ justUploadNightly
259261justUploadNightly day = do
260262 plan <- decodeFileEither (fpToString $ nightlyPlanFile day)
261263 >>= either throwM return
262− withManager tlsManagerSettings $ finallyUpload $ nightlySettings day plan
264+ withManager tlsManagerSettings $ finallyUpload False $ nightlySettings day plan
265+
266+getStackageAuthToken :: IO Text
267+getStackageAuthToken = do
268+ mtoken <- lookupEnv "STACKAGE_AUTH_TOKEN"
269+ case mtoken of
270+ Nothing -> decodeUtf8 <$> readFile "/auth-token"
271+ Just token -> return $ pack token
263272
264273-- | The final part of the complete build process: uploading a bundle,
265274-- docs and a distro to hackage.
266−finallyUpload :: Settings -> Manager -> IO ()
267−finallyUpload settings@Settings{..} man = do
275+finallyUpload :: Bool -- ^ use v2 upload
276+ -> Settings -> Manager -> IO ()
277+finallyUpload useV2 settings@Settings{..} man = do
268278 putStrLn "Uploading bundle to Stackage Server"
269279
270− mtoken <- lookupEnv "STACKAGE_AUTH_TOKEN"
271− token <-
272− case mtoken of
273− Nothing -> decodeUtf8 <$> readFile "/auth-token"
274− Just token -> return $ pack token
275−
276− now <- epochTime
277− let ghcVer = display $ siGhcVersion $ bpSystemInfo plan
278− (ident, mloc) <- flip uploadBundle man $ setArgs ghcVer def
279− { ubContents = serverBundle now (title ghcVer) slug plan
280− , ubAuthToken = token
281− }
282− putStrLn $ "New ident: " ++ unSnapshotIdent ident
283− forM_ mloc $ \loc ->
284− putStrLn $ "Track progress at: " ++ loc
280+ token <- getStackageAuthToken
285281
286− postBuild `catchAny` print
282+ if useV2
283+ then do
284+ res <- flip uploadBundleV2 man UploadBundleV2
285+ { ub2Server = def
286+ , ub2AuthToken = token
287+ , ub2Bundle = bundleDest
288+ }
289+ putStrLn $ "New snapshot available at: " ++ res
290+ else do
291+ now <- epochTime
292+ let ghcVer = display $ siGhcVersion $ bpSystemInfo plan
293+ (ident, mloc) <- flip uploadBundle man $ setArgs ghcVer def
294+ { ubContents = serverBundle now (title ghcVer) slug plan
295+ , ubAuthToken = token
296+ }
297+ putStrLn $ "New ident: " ++ unSnapshotIdent ident
298+ forM_ mloc $ \loc ->
299+ putStrLn $ "Track progress at: " ++ loc
300+
301+ putStrLn "Uploading docs to Stackage Server"
302+ res1 <- tryAny $ uploadDocs UploadDocs
303+ { udServer = def
304+ , udAuthToken = token
305+ , udDocs = pbDocDir pb
306+ , udSnapshot = ident
307+ } man
308+ putStrLn $ "Doc upload response: " ++ tshow res1
309+
310+ putStrLn "Uploading doc map"
311+ tryAny (uploadDocMap UploadDocMap
312+ { udmServer = def
313+ , udmAuthToken = token
314+ , udmSnapshot = ident
315+ , udmDocDir = pbDocDir pb
316+ , udmPlan = plan
317+ } man) >>= print
287318
288− putStrLn "Uploading docs to Stackage Server"
289− res1 <- uploadDocs UploadDocs
290− { udServer = def
291− , udAuthToken = token
292− , udDocs = pbDocDir pb
293− , udSnapshot = ident
294− } man
295− putStrLn $ "Doc upload response: " ++ tshow res1
319+ postBuild `catchAny` print
296320
297321 ecreds <- tryIO $ readFile "/hackage-creds"
298322 case map encodeUtf8 $ words $ decodeUtf8 $ either (const "") id ecreds of
@@ -301,14 +325,5 @@ finallyUpload settings@Settings{..} man = do
301325 res2 <- uploadHackageDistroNamed distroName plan username password man
302326 putStrLn $ "Distro upload response: " ++ tshow res2
303327 _ -> putStrLn "No creds found, skipping Hackage distro upload"
304−
305− putStrLn "Uploading doc map"
306− uploadDocMap UploadDocMap
307− { udmServer = def
308− , udmAuthToken = token
309− , udmSnapshot = ident
310− , udmDocDir = pbDocDir pb
311− , udmPlan = plan
312− } man >>= print
313328 where
314329 pb = getPerformBuild (error "finallyUpload.buildFlags") settings
Stackage/Upload.hs+3
@@ -16,6 +16,8 @@ module Stackage.Upload
1616 , uploadDocMap
1717 , uploadBundleV2
1818 , UploadBundleV2 (..)
19+ , def
20+ , unStackageServer
1921 ) where
2022
2123import Control.Monad.Writer.Strict (execWriter, tell)
@@ -224,6 +226,7 @@ data UploadBundleV2 = UploadBundleV2
224226uploadBundleV2 :: UploadBundleV2 -> Manager -> IO Text
225227uploadBundleV2 UploadBundleV2 {..} man = IO.withBinaryFile (fpToString ub2Bundle) IO.ReadMode $ \h -> do
226228 size <- IO.hFileSize h
229+ putStrLn $ "Bundle size: " ++ tshow size
227230 req1 <- parseUrl $ unpack $ unStackageServer ub2Server ++ "/upload2"
228231 let req2 = req1
229232 { method = "PUT"
app/stackage.hs+34−2
@@ -10,7 +10,11 @@ import Options.Applicative
1010import Filesystem.Path.CurrentOS (decodeString)
1111import Paths_stackage (version)
1212import Stackage.CompleteBuild
13+import Stackage.Upload
1314import Stackage.InstallBuild
15+import Network.HTTP.Client (withManager)
16+import Network.HTTP.Client.TLS (tlsManagerSettings)
17+import qualified Data.Text as T
1418
1519main :: IO ()
1620main =
@@ -62,7 +66,13 @@ main =
6266 installBuild
6367 installFlags
6468 "install"
65− "Install a snapshot from an existing build plan"]
69+ "Install a snapshot from an existing build plan"
70+ , cmnd
71+ uploadv2
72+ uploadv2Flags
73+ "upload2"
74+ "Upload a pre-existing v2 bundle"
75+ ]
6676
6777 cmnd exec parse name desc =
6878 command name $
@@ -98,7 +108,10 @@ main =
98108 help "Output verbose detail about the build steps") <*>
99109 switch
100110 (long "skip-check" <>
101− help "Skip the check phase, and pass --allow-newer to cabal configure")
111+ help "Skip the check phase, and pass --allow-newer to cabal configure") <*>
112+ switch
113+ (long "upload-v2" <>
114+ help "Use the V2 upload code")
102115
103116 nightlyUploadFlags = fromString <$> strArgument
104117 (metavar "DATE" <>
@@ -161,3 +174,22 @@ main =
161174 switch
162175 (long "skip-check" <>
163176 help "Skip the check phase, and pass --allow-newer to cabal configure")
177+
178+ uploadv2 (path, url) = withManager tlsManagerSettings $ \man -> do
179+ token <- getStackageAuthToken
180+ res <- flip uploadBundleV2 man UploadBundleV2
181+ { ub2AuthToken = token
182+ , ub2Server = fromString url
183+ , ub2Bundle = decodeString path
184+ }
185+ putStrLn $ "New URL: " ++ T.unpack res
186+
187+ uploadv2Flags = (,)
188+ <$> (strArgument
189+ (metavar "BUNDLE-PATH" <>
190+ help "Bundle path"))
191+ <*> strOption
192+ (long "server-url" <>
193+ metavar "SERVER-URL" <>
194+ showDefault <> value (T.unpack $ unStackageServer def) <>
195+ help "Server to upload bundle to")
stackage.cabal+4−1
@@ -1,5 +1,5 @@
11name: stackage
2−version: 0.5.2
2+version: 0.6.0
33synopsis: "Stable Hackage," tools for creating a vetted set of packages from Hackage.
44description: Please see <http://www.stackage.org/package/stackage> for a description and documentation.
55homepage: https://github.com/fpco/stackage
@@ -75,6 +75,9 @@ executable stackage
7575 , stackage
7676 , optparse-applicative >= 0.11
7777 , system-filepath
78+ , http-client
79+ , http-client-tls
80+ , text
7881 ghc-options: -rtsopts -threaded -with-rtsopts=-N
7982
8083test-suite spec