Code Monkey home page Code Monkey logo

Comments (18)

ad-si avatar ad-si commented on May 24, 2024 1

Ahhh, the OverloadedLists was the crucial part. Must have missed it in your examples…
Thanks a lot!

from language-docker.

lorenzo avatar lorenzo commented on May 24, 2024

Yes, multistage images are the reason this project exists at all.

That said, it works much better when using multistage builds with ONBUILD instructions. That means, having each stage in a different file.

Do you need guidance in using this tool?

from language-docker.

ad-si avatar ad-si commented on May 24, 2024

If I recall correctly, this is not the same!

With builder images you can copy just a few things from one image to the next:

COPY --from=builder /var/app/node_modules node_modules

This is not possible with onbuild images.

from language-docker.

ad-si avatar ad-si commented on May 24, 2024

This is the documentation for it:
https://docs.docker.com/develop/develop-images/multistage-build/

from language-docker.

ad-si avatar ad-si commented on May 24, 2024

I guess I should have read it until the end πŸ˜…:

When using multi-stage builds, you are not limited to copying from stages you created earlier in your Dockerfile.

I'll try out if I can make it work this way…

from language-docker.

lorenzo avatar lorenzo commented on May 24, 2024

@ad-si Let me know if you need help!

from language-docker.

ad-si avatar ad-si commented on May 24, 2024

Thanks! Actually, I already have a question. How can I build this:

COPY --from=builder /var/app/node_modules node_modules

from language-docker.

lorenzo avatar lorenzo commented on May 24, 2024

@ad-si are you suing the DSL or using the quasi quoter?

Using the quasi quoter:

{-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE QuasiQuotes       #-}
import Language.Docker
main = putStr $ toDockerfileStr $ do
    [edockerfile|
    FROM node as builder
    FROM node
    COPY --from=builder /var/app/node_modules node_modules
    CMD node something.js
    |]

Using the DSL:

{-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE QuasiQuotes       #-}
import Language.Docker
import Language.Docker.Syntax as Syntax

main = putStr $ toDockerfileStr $ do
     from $ "node"  `aliased` "builder"
     from "node"
     copyFrom "builder" ["/var/app/node_modules"] "node_modules"
   where 
    copyFrom img sources dest = copyArgs sources dest Syntax.NoChown (Syntax.CopySource img)

I realise now that there should be a helper function in the DSL for this common case. I'll work on that soon. Let me know if this worked for you

from language-docker.

ad-si avatar ad-si commented on May 24, 2024

Thanks for the examples!

I don't use QuasiQuotes (when possible). Neither a fan of the Docker syntax, nor of Template Haskell.
Would be really could if you'd add first class support to the EDSL. 😁
We use this features basically in every Dockerfile nowadays.

from language-docker.

lorenzo avatar lorenzo commented on May 24, 2024

I'll give a stabat it this weekend... or maybe you want to help me with that? I can guide you if you are interested

from language-docker.

ad-si avatar ad-si commented on May 24, 2024

Uhm, my real GitHub account (@adius) is currently blocked (don't ask πŸ€¦β€β™‚οΈ). I don't want to use my current temporary account for contributions. When (if) it gets unlocked I could help out ...

from language-docker.

ad-si avatar ad-si commented on May 24, 2024

Stupid question: There must be an easier way, right? πŸ˜…

copy (NonEmpty.fromList [SourcePath "test.json"]) (TargetPath "test.json")

from language-docker.

lorenzo avatar lorenzo commented on May 24, 2024

@ad-si both SourcePath and TargetPath have as IsString instance. So if you add these two extensions:

{-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE OverloadedLists #-}

You should be able to write:

copy ["test.json"] "test.json"

from language-docker.

lorenzo avatar lorenzo commented on May 24, 2024

@ad-si I'm thinking of changing the DSL for copy. what do you think of this?

copy $ fromStage "builder" $ ["test.json"] `to` "/app/" 

from language-docker.

ad-si avatar ad-si commented on May 24, 2024

Mh, looks a little to involved for me. Sometime simpler is better. What's wrong with:

copyFromStage "builder" ["test.json"] "/app/"

There isn't even additional type safety, is there?

from language-docker.

lorenzo avatar lorenzo commented on May 24, 2024

I can for sure offer a simpler version once I get the completed cases sorted out. The complex case is having both from and chows as flags for copy.

The api I suggested a iced would support having both, either or none of the flags (and future flags) in the same syntax.

from language-docker.

ad-si avatar ad-si commented on May 24, 2024

Ah I see, sounds good.
But the to wouldn't be necessary, right?

from language-docker.

lorenzo avatar lorenzo commented on May 24, 2024

Yeah, it is somewhat necessary. I'll explore alternative designs that may also work

from language-docker.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    πŸ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. πŸ“ŠπŸ“ˆπŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❀️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.