Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Don't drop .stack-work in the current dir during stack image container #2007

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 23 additions & 11 deletions src/Stack/Image.hs
Original file line number Diff line number Diff line change
Expand Up @@ -40,14 +40,14 @@ type Assemble e m = (HasConfig e, HasTerminal e, MonadBaseControl IO m, MonadIO
-- directory under '.stack-work'
stageContainerImageArtifacts
:: Build e m
=> m ()
stageContainerImageArtifacts = do
=> Maybe (Path Abs Dir) -> m ()
stageContainerImageArtifacts mProjectRoot = do
config <- asks getConfig
workingDir <- getCurrentDir
forM_
(zip [0 ..] (imgDockers $ configImage config))
(\(idx,opts) ->
do imageDir <- imageStagingDir workingDir idx
do imageDir <-
imageStagingDir (fromMaybeProjectRoot mProjectRoot) idx
ignoringAbsence (removeDirRecur imageDir)
ensureDir imageDir
stageExesInDir opts imageDir
Expand All @@ -59,18 +59,18 @@ stageContainerImageArtifacts = do
-- in the config file.
createContainerImageFromStage
:: Assemble e m
=> [Text] -> m ()
createContainerImageFromStage imageNames = do
=> Maybe (Path Abs Dir) -> [Text] -> m ()
createContainerImageFromStage mProjectRoot imageNames = do
config <- asks getConfig
workingDir <- getCurrentDir
forM_
(zip
[0 ..]
(filterImages
(map T.unpack imageNames)
(imgDockers $ configImage config)))
(\(idx,opts) ->
do imageDir <- imageStagingDir workingDir idx
do imageDir <-
imageStagingDir (fromMaybeProjectRoot mProjectRoot) idx
createDockerImage opts imageDir
extendDockerImageWithEntrypoint opts imageDir)
where
Expand Down Expand Up @@ -180,6 +180,11 @@ extendDockerImageWithEntrypoint dockerConfig dir = do
, dockerImageName ++ "-" ++ ep
, toFilePathNoTrailingSep dir]))

-- | Fail with friendly error if project root not set.
fromMaybeProjectRoot :: Maybe (Path Abs Dir) -> Path Abs Dir
fromMaybeProjectRoot =
fromMaybe (throw StackImageCannotDetermineProjectRootException)

-- | The command name for dealing with images.
imgCmdName
:: String
Expand All @@ -199,12 +204,19 @@ imgOptsFromMonoid ImageOptsMonoid{..} =
}

-- | Stack image exceptions.
data StackImageException =
StackImageDockerBaseUnspecifiedException
deriving ((Typeable))
data StackImageException
= StackImageDockerBaseUnspecifiedException -- ^ Unspecified parent docker
-- container makes building
-- impossible
| StackImageCannotDetermineProjectRootException -- ^ Can't determine the
-- project root (where to
-- put image sandbox).
deriving (Typeable)

instance Exception StackImageException

instance Show StackImageException where
show StackImageDockerBaseUnspecifiedException =
"You must specify a base docker image on which to place your haskell executables."
show StackImageCannotDetermineProjectRootException =
"Stack was unable to determine the project root in order to build a container."
7 changes: 4 additions & 3 deletions src/main/Main.hs
Original file line number Diff line number Diff line change
Expand Up @@ -1144,7 +1144,8 @@ cfgSetCmd co go@GlobalOpts{..} =
env)

imgDockerCmd :: (Bool, [Text]) -> GlobalOpts -> IO ()
imgDockerCmd (rebuild,images) go@GlobalOpts{..} =
imgDockerCmd (rebuild,images) go@GlobalOpts{..} = do
mProjectRoot <- lcProjectRoot . snd <$> loadConfigWithOpts go
withBuildConfigExt
go
Nothing
Expand All @@ -1154,8 +1155,8 @@ imgDockerCmd (rebuild,images) go@GlobalOpts{..} =
(const (return ()))
lk
defaultBuildOptsCLI
Image.stageContainerImageArtifacts)
(Just $ Image.createContainerImageFromStage images)
Image.stageContainerImageArtifacts mProjectRoot)
(Just $ Image.createContainerImageFromStage mProjectRoot images)

sigSignSdistCmd :: (String, String) -> GlobalOpts -> IO ()
sigSignSdistCmd (url,path) go =
Expand Down