-
Notifications
You must be signed in to change notification settings - Fork 845
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Download or override location of stack executable to re-run in Docker…
… container #974
- Loading branch information
Showing
13 changed files
with
393 additions
and
146 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,95 @@ | ||
{-# LANGUAGE CPP, RecordWildCards, TemplateHaskell #-} | ||
|
||
-- | Docker configuration | ||
module Stack.Config.Docker where | ||
|
||
import Control.Exception.Lifted | ||
import Control.Monad.Catch (throwM, MonadThrow) | ||
import Data.List (find) | ||
import Data.Maybe | ||
import qualified Data.Text as T | ||
import Path | ||
import Stack.Types | ||
|
||
-- | Interprets DockerOptsMonoid options. | ||
dockerOptsFromMonoid | ||
:: MonadThrow m | ||
=> Maybe Project -> Path Abs Dir -> DockerOptsMonoid -> m DockerOpts | ||
dockerOptsFromMonoid mproject stackRoot DockerOptsMonoid{..} = do | ||
let dockerEnable = | ||
fromMaybe (fromMaybe False dockerMonoidExists) dockerMonoidEnable | ||
dockerImage = | ||
let defaultTag = | ||
case mproject of | ||
Nothing -> "" | ||
Just proj -> | ||
case projectResolver proj of | ||
ResolverSnapshot n@(LTS _ _) -> | ||
":" ++ T.unpack (renderSnapName n) | ||
_ -> | ||
throwM | ||
(ResolverNotSupportedException $ | ||
show $ projectResolver proj) | ||
in case dockerMonoidRepoOrImage of | ||
Nothing -> "fpco/stack-build" ++ defaultTag | ||
Just (DockerMonoidImage image) -> image | ||
Just (DockerMonoidRepo repo) -> | ||
case find (`elem` (":@" :: String)) repo of | ||
Just _ -- Repo already specified a tag or digest, so don't append default | ||
-> | ||
repo | ||
Nothing -> repo ++ defaultTag | ||
dockerRegistryLogin = | ||
fromMaybe | ||
(isJust (emptyToNothing dockerMonoidRegistryUsername)) | ||
dockerMonoidRegistryLogin | ||
dockerRegistryUsername = emptyToNothing dockerMonoidRegistryUsername | ||
dockerRegistryPassword = emptyToNothing dockerMonoidRegistryPassword | ||
dockerAutoPull = fromMaybe False dockerMonoidAutoPull | ||
dockerDetach = fromMaybe False dockerMonoidDetach | ||
dockerPersist = fromMaybe False dockerMonoidPersist | ||
dockerContainerName = emptyToNothing dockerMonoidContainerName | ||
dockerRunArgs = dockerMonoidRunArgs | ||
dockerMount = dockerMonoidMount | ||
dockerEnv = dockerMonoidEnv | ||
dockerDatabasePath <- | ||
case dockerMonoidDatabasePath of | ||
Nothing -> return $ stackRoot </> $(mkRelFile "docker.db") | ||
Just fp -> | ||
case parseAbsFile fp of | ||
Left e -> throwM (InvalidDatabasePathException e) | ||
Right p -> return p | ||
dockerStackExe <- | ||
case dockerMonoidStackExe of | ||
Just e -> parseDockerStackExe e | ||
#ifdef MOUNT_IN_DOCKER | ||
Nothing -> return DockerStackExeHost | ||
#else | ||
Nothing -> return DockerStackExeDownload | ||
#endif | ||
return DockerOpts{..} | ||
where emptyToNothing Nothing = Nothing | ||
emptyToNothing (Just s) | null s = Nothing | ||
| otherwise = Just s | ||
|
||
-- | Exceptions thrown by Stack.Docker.Config. | ||
data StackDockerConfigException | ||
= ResolverNotSupportedException String | ||
-- ^ Only LTS resolvers are supported for default image tag. | ||
| InvalidDatabasePathException SomeException | ||
-- ^ Invalid global database path. | ||
|
||
-- | Exception instance for StackDockerConfigException. | ||
instance Exception StackDockerConfigException | ||
|
||
-- | Show instance for StackDockerConfigException. | ||
instance Show StackDockerConfigException where | ||
show (ResolverNotSupportedException resolver) = | ||
concat | ||
[ "Resolver not supported for Docker images:\n " | ||
, resolver | ||
, "\nUse an LTS resolver, or set the '" | ||
, T.unpack dockerImageArgName | ||
, "' explicitly, in your configuration file."] | ||
show (InvalidDatabasePathException ex) = | ||
concat ["Invalid database path: ", show ex] |
Oops, something went wrong.
8f35021
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This gets us a bit closer to supporting Docker integration on non-Linux 64-bit platforms (#194) as well.