Skip to content

Commit

Permalink
Docker: mount ~/.ssh in container (#1358)
Browse files Browse the repository at this point in the history
  • Loading branch information
borsboom committed Jan 30, 2016
1 parent cea6e03 commit 5bbe880
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 8 deletions.
3 changes: 2 additions & 1 deletion ChangeLog.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,8 @@ Major changes:

Other enhancements:

* Docker: pass SSH auth socket into container
* Docker: pass ~/.ssh and SSH auth socket into container, so that git repos
work [#1358](https://github.com/commercialhaskell/stack/issues/1358)

Bug fixes:

Expand Down
21 changes: 14 additions & 7 deletions src/Stack/Docker.hs
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ import Stack.Docker.GlobalDB
import Stack.Types
import Stack.Types.Internal
import Stack.Setup (ensureDockerStackExe)
import System.Directory (canonicalizePath,getModificationTime)
import System.Directory (canonicalizePath,getModificationTime,getAppUserDataDirectory)
import System.Environment (getEnv,getEnvironment,getProgName,getArgs,getExecutablePath
,lookupEnv)
import System.Exit (exitSuccess, exitWith)
Expand Down Expand Up @@ -257,21 +257,23 @@ runContainerAndExit getCmdArgs
let docker = configDocker config
envOverride <- getEnvOverride (configPlatform config)
checkDockerVersion envOverride docker
env <- liftIO getEnvironment
(env,isStdinTerminal,isStderrTerminal) <- liftIO $
(,,)
<$> getEnvironment
<*> hIsTerminalDevice stdin
<*> hIsTerminalDevice stderr
isStdoutTerminal <- asks getTerminal
esshDir <- liftIO $ tryJust (guard . isDoesNotExistError) (getAppUserDataDirectory "ssh")
let dockerHost = lookup "DOCKER_HOST" env
dockerCertPath = lookup "DOCKER_CERT_PATH" env
bamboo = lookup "bamboo_buildKey" env
jenkins = lookup "JENKINS_HOME" env
msshAuthSock = lookup "SSH_AUTH_SOCK" env
isRemoteDocker = maybe False (isPrefixOf "tcp://") dockerHost
isStdoutTerminal <- asks getTerminal
(isStdinTerminal,isStderrTerminal) <-
liftIO ((,) <$> hIsTerminalDevice stdin
<*> hIsTerminalDevice stderr)
image = dockerImage docker
when (isRemoteDocker &&
maybe False (isInfixOf "boot2docker") dockerCertPath)
($logWarn "Warning: Using boot2docker is NOT supported, and not likely to perform well.")
let image = dockerImage docker
maybeImageInfo <- inspect envOverride image
imageInfo@Inspect{..} <- case maybeImageInfo of
Just ii -> return ii
Expand Down Expand Up @@ -322,6 +324,11 @@ runContainerAndExit getCmdArgs
,"-v",toFilePathNoTrailingSep projectRoot ++ ":" ++ toFilePathNoTrailingSep projectRoot
,"-v",toFilePathNoTrailingSep sandboxHomeDir ++ ":" ++ toFilePathNoTrailingSep sandboxHomeDir
,"-w",toFilePathNoTrailingSep pwd]
,case esshDir of
Left _ -> []
Right sshDir ->
["-v"
,sshDir ++ ":" ++ toFilePathNoTrailingSep (sandboxHomeDir </> $(mkRelDir ".ssh/"))]
,case msshAuthSock of
Nothing -> []
Just sshAuthSock ->
Expand Down

0 comments on commit 5bbe880

Please sign in to comment.