Skip to content

Commit

Permalink
Adding a couple helper functions to work with file sources
Browse files Browse the repository at this point in the history
  • Loading branch information
lorenzo committed Mar 11, 2018
1 parent 7eb24de commit 7d4f872
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 7 deletions.
8 changes: 5 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -110,15 +110,17 @@ import Language.Docker
import qualified System.Directory as Directory
import qualified System.FilePath as FilePath
import qualified System.FilePath.Glob as Glob
import Data.String (fromString)
import Data.List.NonEmpty (fromList)

main = do
str <- toDockerfileStrIO $ do
fs <- liftIO $ do
cwd <- Directory.getCurrentDirectory
fs <- Glob.glob "./test/*.hs"
return (map (FilePath.makeRelative cwd) fs)
let relativeFiles = map (FilePath.makeRelative cwd) fs
return (fromList relativeFiles)
from "ubuntu"
mapM_ (\f -> add [fromString f] (fromString $ "/app/" ++ takeFileName f)) fs
copy $ (toSources fs) `to` "/app/"
putStr str
```

Expand Down
2 changes: 2 additions & 0 deletions src/Language/Docker.hs
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@ module Language.Docker
, Language.Docker.EDSL.to
, Language.Docker.EDSL.fromStage
, Language.Docker.EDSL.ownedBy
, Language.Docker.EDSL.toSources
, Language.Docker.EDSL.toTarget
, Language.Docker.EDSL.run
, Language.Docker.EDSL.runArgs
, Language.Docker.EDSL.cmd
Expand Down
14 changes: 10 additions & 4 deletions src/Language/Docker/EDSL.hs
Original file line number Diff line number Diff line change
Expand Up @@ -105,11 +105,11 @@ toDockerfileStr = PrettyPrint.prettyPrint . toDockerfile
untagged :: String -> EBaseImage
untagged = flip EUntaggedImage Nothing . fromString

tagged :: String -> String -> EBaseImage
tagged imageName tag = ETaggedImage (fromString imageName) tag Nothing
tagged :: Syntax.Image -> String -> EBaseImage
tagged imageName tag = ETaggedImage imageName tag Nothing

digested :: String -> ByteString -> EBaseImage
digested imageName hash = EDigestedImage (fromString imageName) hash Nothing
digested :: Syntax.Image -> ByteString -> EBaseImage
digested imageName hash = EDigestedImage imageName hash Nothing

aliased :: EBaseImage -> String -> EBaseImage
aliased image alias =
Expand Down Expand Up @@ -156,6 +156,12 @@ copyFromStage stage source dest = copy $ Syntax.CopyArgs source dest Syntax.NoCh
add :: MonadFree EInstruction m => NonEmpty Syntax.SourcePath -> Syntax.TargetPath -> m ()
add sources dest = addArgs sources dest Syntax.NoChown

toSources :: NonEmpty String -> NonEmpty Syntax.SourcePath
toSources = fmap Syntax.SourcePath

toTarget :: String -> Syntax.TargetPath
toTarget = Syntax.TargetPath

fromStage :: Syntax.CopyArgs -> Syntax.CopySource -> Syntax.CopyArgs
fromStage args src = args {Syntax.sourceFlag = src}

Expand Down

0 comments on commit 7d4f872

Please sign in to comment.