on master help sign in
ob deploy mobile: more robust mobile branching
commitc1e0cc0230c3c7bf6afaed2f4ab98ecce2b2a126 authorLuigy Leon <luichi.19@gmail.com> dateMon 19 Nov 2018, 18:01 (8 years ago) parent96fe60e
2 files changed+55−44
lib/command/src/Obelisk/Command.hs+4−8 lib/command/src/Obelisk/Command/Deploy.hs+51−36
lib/command/src/Obelisk/Command.hs+4−8
@@ -142,8 +142,8 @@ deployCommand cfg = hsubparser $ mconcat
142142 ]
143143 where
144144 platformP = hsubparser $ mconcat
145− [ command "android" $ info (pure Android) mempty
146− , command "ios" $ info (pure IOS <*> strArgument (metavar "TEAMID" <> help "Your Team ID - found in the Apple developer portal")) mempty
145+ [ command "android" $ info (pure (Android, [])) mempty
146+ , command "ios" $ info ((,) <$> pure IOS <*> (fmap pure $ strArgument (metavar "TEAMID" <> help "Your Team ID - found in the Apple developer portal"))) mempty
147147 ]
148148
149149 remoteBuilderParser :: Parser (Maybe RemoteBuilder)
@@ -173,16 +173,13 @@ deployInitOpts = DeployInitOpts
173173 <*> flag True False (long "disable-https" <> help "Disable automatic https configuration for the backend")
174174
175175type TeamID = String
176−data PlatformDeployment = Android | IOS TeamID
177− deriving (Show)
178−
179176data RemoteBuilder = RemoteBuilder_ObeliskVM
180177 deriving (Eq, Show)
181178
182179data DeployCommand
183180 = DeployCommand_Init DeployInitOpts
184181 | DeployCommand_Push (Maybe RemoteBuilder)
185− | DeployCommand_Test PlatformDeployment
182+ | DeployCommand_Test (PlatformDeployment, [String])
186183 | DeployCommand_Update
187184 deriving Show
188185
@@ -341,8 +338,7 @@ ob = \case
341338 Nothing -> pure []
342339 Just RemoteBuilder_ObeliskVM -> (:[]) <$> VmBuilder.getNixBuildersArg
343340 DeployCommand_Update -> deployUpdate "."
344− DeployCommand_Test Android -> deployMobile "android" []
345− DeployCommand_Test (IOS teamID) -> deployMobile "ios" [teamID]
341+ DeployCommand_Test (platform, extraArgs) -> deployMobile platform extraArgs
346342 ObCommand_Run -> inNixShell' $ static run
347343 -- inNixShell ($(mkClosure 'ghcidAction) ())
348344 ObCommand_Thunk tc -> case tc of
lib/command/src/Obelisk/Command/Deploy.hs+51−36
@@ -174,49 +174,64 @@ keytoolToAndroidConfig conf = runIdentity $ do
174174 , ("keyPassword", keypass)
175175 ]
176176
177−deployMobile :: MonadObelisk m => String -> [String] -> m ()
177+data PlatformDeployment = Android | IOS
178+ deriving (Show, Eq)
179+
180+renderPlatformDeployment :: PlatformDeployment -> String
181+renderPlatformDeployment = \case
182+ Android -> "android"
183+ IOS -> "ios"
184+
185+deployMobile :: MonadObelisk m => PlatformDeployment -> [String] -> m ()
178186deployMobile platform mobileArgs = withProjectRoot "." $ \root -> do
179187 let srcDir = root </> "src"
180188 exists <- liftIO $ doesDirectoryExist srcDir
181189 unless exists $ failWith "ob test should be run inside of a deploy directory"
182− when (platform == "android") $ do
183− let keystorePath = root </> "android_keystore.jks"
184− keytoolConfPath = root </> "android_keytool_config.json"
185− hasKeystore <- liftIO $ doesFileExist keystorePath
186− when (not hasKeystore) $ do
187− -- TODO log instructions for how to modify the keystore
188− putLog Notice $ "Creating keystore: " <> T.pack keystorePath
189− putLog Notice "Enter a keystore password: "
190− keyStorePassword <- liftIO $ withEcho False getLine
191− putLog Notice "Re-enter the keystore password: "
192− keyStorePassword' <- liftIO $ withEcho False getLine
193− unless (keyStorePassword' == keyStorePassword) $ failWith "passwords do not match"
194− let keyToolConf = KeytoolConfig
195− { _keytoolConfig_keystore = keystorePath
196− , _keytoolConfig_alias = "obelisk"
197− , _keytoolConfig_storepass = keyStorePassword
198− , _keytoolConfig_keypass = keyStorePassword
199− }
200− createKeystore root $ keyToolConf
201− liftIO $ BSL.writeFile keytoolConfPath $ encode keyToolConf
202− checkKeytoolConfExist <- liftIO $ doesFileExist keytoolConfPath
203− unless checkKeytoolConfExist $ failWith "Missing android KeytoolConfig"
204− keytoolConfContents <- liftIO $ BSL.readFile keytoolConfPath
205− liftIO $ putStrLn $ show keytoolConfContents
206− releaseKey <- case eitherDecode keytoolConfContents of
207− Left err -> failWith $ T.pack err
208− Right conf -> do
209− let nvset = toValue @(HM.HashMap Text (NValueNF Identity)) @Identity @(NValueNF Identity) $ keytoolToAndroidConfig conf
210− return $ printNix $ runIdentity nvset
211− result <- nixCmd $ NixCmd_Build $ def
212− & nixBuildConfig_outLink .~ OutLink_None
213− & nixCmdConfig_target .~ Target
190+ nixBuildTarget <- case platform of
191+ Android -> do
192+ let keystorePath = root </> "android_keystore.jks"
193+ keytoolConfPath = root </> "android_keytool_config.json"
194+ hasKeystore <- liftIO $ doesFileExist keystorePath
195+ when (not hasKeystore) $ do
196+ -- TODO log instructions for how to modify the keystore
197+ putLog Notice $ "Creating keystore: " <> T.pack keystorePath
198+ putLog Notice "Enter a keystore password: "
199+ keyStorePassword <- liftIO $ withEcho False getLine
200+ putLog Notice "Re-enter the keystore password: "
201+ keyStorePassword' <- liftIO $ withEcho False getLine
202+ unless (keyStorePassword' == keyStorePassword) $ failWith "passwords do not match"
203+ let keyToolConf = KeytoolConfig
204+ { _keytoolConfig_keystore = keystorePath
205+ , _keytoolConfig_alias = "obelisk"
206+ , _keytoolConfig_storepass = keyStorePassword
207+ , _keytoolConfig_keypass = keyStorePassword
208+ }
209+ createKeystore root $ keyToolConf
210+ liftIO $ BSL.writeFile keytoolConfPath $ encode keyToolConf
211+ checkKeytoolConfExist <- liftIO $ doesFileExist keytoolConfPath
212+ unless checkKeytoolConfExist $ failWith "Missing android KeytoolConfig"
213+ keytoolConfContents <- liftIO $ BSL.readFile keytoolConfPath
214+ liftIO $ putStrLn $ show keytoolConfContents
215+ releaseKey <- case eitherDecode keytoolConfContents of
216+ Left err -> failWith $ T.pack err
217+ Right conf -> do
218+ let nvset = toValue @(HM.HashMap Text (NValueNF Identity)) @Identity @(NValueNF Identity) $ keytoolToAndroidConfig conf
219+ return $ printNix $ runIdentity nvset
220+ return $ Target
214221 { _target_path = Nothing
215222 , _target_attr = Nothing
216− , _target_expr = Just $ "with (import " <> srcDir <> " {}); " <> platform <> ".frontend.override (drv: { releaseKey = (if builtins.isNull drv.releaseKey then {} else drv.releaseKey) // " <> releaseKey <> "; })"
223+ , _target_expr = Just $ "with (import " <> srcDir <> " {}); " <> renderPlatformDeployment platform <> ".frontend.override (drv: { releaseKey = (if builtins.isNull drv.releaseKey then {} else drv.releaseKey) // " <> releaseKey <> "; })"
217224 }
218− putLog Notice $ T.pack $ "Your recently built android apk can be found at the following path: " <> (show result)
219− callProcessAndLogOutput (Notice, Error) $ proc (result </> "bin" </> "deploy") mobileArgs
225+ IOS -> return $ Target
226+ { _target_path = Nothing
227+ , _target_attr = Just "ios.frontend"
228+ , _target_expr = Nothing
229+ }
230+ result <- nixCmd $ NixCmd_Build $ def
231+ & nixBuildConfig_outLink .~ OutLink_None
232+ & nixCmdConfig_target .~ nixBuildTarget
233+ putLog Notice $ T.pack $ "Your recently built android apk can be found at the following path: " <> (show result)
234+ callProcessAndLogOutput (Notice, Error) $ proc (result </> "bin" </> "deploy") mobileArgs
220235 where
221236 withEcho showEcho f = do
222237 prevEcho <- hGetEcho stdin