|
| 1 | +{-# LANGUAGE CPP, DeriveDataTypeable, RecordWildCards, TemplateHaskell #-} |
| 2 | + |
| 3 | +-- | Docker configuration |
| 4 | +module Stack.Config.ExecEnv where |
| 5 | + |
| 6 | +import Control.Exception.Lifted |
| 7 | +import Control.Monad |
| 8 | +import Control.Monad.Catch (throwM, MonadThrow) |
| 9 | +import Data.List (find) |
| 10 | +import Data.Maybe |
| 11 | +import qualified Data.Text as T |
| 12 | +import Data.Typeable (Typeable) |
| 13 | +import Path |
| 14 | +import Stack.Types |
| 15 | + |
| 16 | +-- | Interprets DockerOptsMonoid options. |
| 17 | +execEnvOptsFromMonoid |
| 18 | + :: MonadThrow m |
| 19 | + => Maybe Project -> Path Abs Dir -> ExecEnvOptsMonoid -> m ExecEnvOpts |
| 20 | +execEnvOptsFromMonoid mproject stackRoot ExecEnvOptsMonoid{..} = do |
| 21 | + let execEnvType = |
| 22 | + if fromMaybe execEnvMonoidDefaultEnable execEnvMonoidEnable |
| 23 | + then Just NixShellExecEnv |
| 24 | + else Nothing |
| 25 | + execEnvPackages = execEnvMonoidPackages |
| 26 | + {- dockerContainerName = emptyToNothing dockerMonoidContainerName |
| 27 | + dockerRunArgs = dockerMonoidRunArgs |
| 28 | + dockerMount = dockerMonoidMount |
| 29 | + dockerEnv = dockerMonoidEnv |
| 30 | + dockerDatabasePath <- |
| 31 | + case dockerMonoidDatabasePath of |
| 32 | + Nothing -> return $ stackRoot </> $(mkRelFile "docker.db") |
| 33 | + Just fp -> |
| 34 | + case parseAbsFile fp of |
| 35 | + Left e -> throwM (InvalidDatabasePathException e) |
| 36 | + Right p -> return p |
| 37 | + dockerStackExe <- |
| 38 | + case dockerMonoidStackExe of |
| 39 | + Just e -> liftM Just (parseDockerStackExe e) |
| 40 | + Nothing -> return Nothing -} |
| 41 | + return ExecEnvOpts{..} |
| 42 | + |
| 43 | +{- where emptyToNothing Nothing = Nothing |
| 44 | + emptyToNothing (Just s) | null s = Nothing |
| 45 | + | otherwise = Just s |
| 46 | +
|
| 47 | +-- | Exceptions thrown by Stack.Docker.Config. |
| 48 | +data StackNixConfigException |
| 49 | + = ResolverNotSupportedException String |
| 50 | + -- ^ Only LTS resolvers are supported for default image tag. |
| 51 | + | InvalidDatabasePathException SomeException |
| 52 | + -- ^ Invalid global database path. |
| 53 | + deriving (Typeable) |
| 54 | +
|
| 55 | +-- | Exception instance for StackDockerConfigException. |
| 56 | +instance Exception StackDockerConfigException |
| 57 | +
|
| 58 | +-- | Show instance for StackDockerConfigException. |
| 59 | +instance Show StackDockerConfigException where |
| 60 | + show (ResolverNotSupportedException resolver) = |
| 61 | + concat |
| 62 | + [ "Resolver not supported for Docker images:\n " |
| 63 | + , resolver |
| 64 | + , "\nUse an LTS resolver, or set the '" |
| 65 | + , T.unpack dockerImageArgName |
| 66 | + , "' explicitly, in your configuration file."] |
| 67 | + show (InvalidDatabasePathException ex) = |
| 68 | + concat ["Invalid database path: ", show ex] |
| 69 | +-} |
0 commit comments