Skip to content

engine.#Build: missing spec fields #1277

Closed

Description

@aluzzardi

A bunch of fields were lost in translation from op.#DockerBuild. I added them to the implementation and flagging as needs review:

  • auth: This was not in #DockerBuild but is needed because of the lack of #DockerLogin
  • platforms / target: These we need to review generally speaking for multi-platform support, I don't believe they're right (/cc @TomChv)
  • buildArg / label / hosts: These are generic dockerfile frontend options

Activity

  1. added this to the milestone on Dec 21, 2021
  2. linked a pull request that will close this issueengine.#Build support #1276on Dec 21, 2021
  3. shykes commented on Jan 4, 2022

    @shykes
    Contributor

    @aluzzardi this is marked as closed by PR #1276, but it’s not clear what the status of platforms and target is.

    • Is review still needed? If so, is there an issue or should I create one?
    • Are these fields currently in or out?
  4. aluzzardi commented on Jan 5, 2022

    @aluzzardi
    ContributorAuthor

    @shykes Issue was auto-closed by mistake by GitHub because I mentioned it in the PR, re-opened.

    • Review still needed
    • The fields are currently in. It's the same code from op.#DockerBuild, ported to engine.#Build which supports them
    • platforms and target: I honestly have no idea. They are passed verbatim to the dockerfile.v0 buildkit frontend. I believe multi-platform support will change this, I don't know how yet
    • auth we do need like in #Push and #Pull (e.g. FROM private.registry)
    • buildArg / label / hosts: Were added for @dubo-dubon-duponey in op.#DockerBuild
  5. shykes commented on Jan 5, 2022

    @shykes
    Contributor

    OK, makes sense. It looks like everything is a direct mapping of the actual underlying API for dockerfile frontend. That’s pretty reasonable IMO.

  6. shykes commented on Jan 5, 2022

    @shykes
    Contributor

    @aluzzardi does this look correct to you? Note the red question marks where I am least sure :)

    Assuming everything is a direct pass-through to dockerfile.v0, then I think we should keep it (and consider renaming engine.#Build to perhaps engine.#Dockerfile :). If it’s not, then I’ll open an issue to discuss those.

    Field Rationale Status Pending decisions
    auth Authenticate nested push / pull operations Merged None
    platforms Pass verbatim to dockerfile buildkit frontend Merged Confirm that we want it
    target Pass verbatim to dockerfile buildkit frontend Merged Confirm that we want it
    buildArg Pass verbatim to dockerfile buildkit frontend Merged Confirm that we want it
    label Pass verbatim to dockerfile buildkit frontend Merged Confirm that we want it
    hosts Pass verbatim to dockerfile buildkit frontend Merged Confirm that we want it

    EDIT: removed question marks per @aluzzardi answers.

  7. aluzzardi commented on Jan 5, 2022

    @aluzzardi
    ContributorAuthor

    Yes to all red questions.

    There's slight transformation for some fields:

    • hosts (string array) is actually a add-host comma separated string in the frontend
    • platforms (string array) is actually a platform comma separated string in the frontend
  8. TomChv commented on Jan 6, 2022

    @TomChv
    Member

    I want to clarify a point about #Build

    According to the following definition :

    #Build: {
    	$dagger: task: _name: "Build"
    
    	// Source directory to build
    	source: #FS
    	{
    		frontend:   "dockerfile"
    		dockerfile: {
    			path: string | *"Dockerfile"
    		} | {
    			contents: string
    		}
    
    		// Authentication
    		auth: [...{
    			target:   string
    			username: string
    			secret:   string | #Secret
    		}]
    
    		// FIXME: options ported from op.#DockerBuild
    		platforms?: [...string]
    		target?: string
    		buildArg?: [string]: string
    		label?: [string]:    string
    		hosts?: [string]:    string
    	}
    
    	// Root filesystem produced by build
    	output: #FS
    
    	// Container image config produced by build
    	config: #ImageConfig
    }

    And your comments, platforms can contains several values. For example ["linux/amd64", "linux/arm64"] (or comma separated).

    If we do this, then we need to supports multiple output.

    When you build something in multi-platform with buildkit, it will creates a reference for each platform so we will have
    one output for each platform.

    In old version of Dagger, we didn't supported multiple output: #437

    So, if we keep that logic, should we add a new field in case of multi platform to retrieves those outputs?

    For example

    outputs: [arch=string]: #FS

    This way, if build something in 2 platforms, we can retrieves it using the platform.

    Example

    // Plan config...
    
    actions: {
        build: #Build & {
             input: // Whatever
             platforms: ["linux/amd64", "linux/arm64"]
        }
    
        foo: #Exec & {
            input: build.outputs["linux/amd64"]
        }
    
       bar: #Exec & {
            input: build.outputs["linux/arm64"]
       }
    }

    I don't know if it's a good solution but it could go beyond issues I've met with #up when I was working on the multi-platform build & push.

  9. modified the milestones: , next on Jan 7, 2022
  10. helderco commented on Jan 7, 2022

    @helderco
    Contributor

    I've had to fork #Build to add target. If using a Dockerfile build, I have use for target and buildArgs.

  11. aluzzardi commented on Jan 7, 2022

    @aluzzardi
    ContributorAuthor

    @helderco Can you share how you're using target so we can incorporate?

  12. helderco commented on Jan 7, 2022

    @helderco
    Contributor

    If you have a multi-stage Dockerfile, you can make an image out of any stage, instead of having to create separate Dockerfiles.

    # Pull the latest version of the image,
    # in order to populate the build cache
    docker pull $BUILD || true
    docker pull $REPO || true
    
    # Build the compile stage
    docker build --target python-build \
        --build-arg PY_VERSION=$PY_VERSION \
        --secret id=pypi-pass,src=$PYPI_PASS \
        --cache-from=$BUILD \
        --tag $BUILD .
    
    rm -f $PYPI_PASS
    
    # Build the runtime stage, using cached compile stage
    docker build --target python-runtime \
        --build-arg PY_VERSION=$PY_VERSION \
        --cache-from=$BUILD \
        --cache-from=$REPO \
        --tag $REPO .
    
    # Security scan
    # https://pythonspeed.com/articles/docker-python-security-scan/
    trivy --exit-code 1 --ignore-unfixed --light $REPO
    trivy --exit-code 1 --ignore-unfixed --light $BUILD
    
    # Push the new versions
    docker push $BUILD
    docker push $REPO
  13. helderco commented on Jan 7, 2022

    @helderco
    Contributor

    Here's an example of a ported bash script to dagger (partial).

    package main
    
    import (
        "alpha.dagger.io/docker"
        "morfose.net/morfose"
    )
    
    stages: [stage=string]: ctr: morfose.#Build & {
        source: context.import.src.contents
        args: BASE_IMAGE: config.base.image
        target: stage
        auths: [_registryAuth]
    }
    
    stages: {
        build: push: docker.#Push & {
            source: stages.build.ctr
            auth: _simpleAuth
            target: "\(config.target.image)-build"
        }
        run: push: docker.#Push & {
            source: stages.run.ctr
            auth: _simpleAuth
            target: config.target.image
        }
    }
  14. aluzzardi commented on Jan 7, 2022

    @aluzzardi
    ContributorAuthor

    @helderco Oh, I see: it targets a specific named stage in Dockerfile (e.g. FROM foo AS target -> docker build --target "target"). Is that so?

  15. helderco commented on Jan 7, 2022

    @helderco
    Contributor

    @aluzzardi, yes it is 👍

  16. aluzzardi commented on Jan 7, 2022

    @aluzzardi
    ContributorAuthor

    Okay, perfect. So engine.#Build supports this in the way that works for you, correct?

  17. helderco commented on Jan 8, 2022

    @helderco
    Contributor

    Yes

  18. shykes commented on Jan 10, 2022

    @shykes
    Contributor

    Wrapping up. It looks like all items here are resolved. There is an outstanding question on platforms (how do we use the output?), which is to be addressed as part of #1371 .

    @aluzzardi here’s what I suggest:

    1. Let’s close this
    2. For platforms, either A) remove it for now, or B) leave it in with the understanding that it might change once Multi-platform containers #1371 is settled (same as the top-level platform field).

    I’m fine either way so up to you.

  19. assigned and unassigned on Jan 11, 2022
  20. aluzzardi commented on Jan 25, 2022

    @aluzzardi
    ContributorAuthor

    @aluzzardi here’s what I suggest:

    1. Let’s close this

    👍

    1. For platforms, either A) remove it for now, or B) leave it in with the understanding that it might change once Multi-platform in Europa Multi-platform containers #1371 is settled (same as the top-level platform field).

    👍

    @TomChv Is it much work to remove platforms (at least from the CUE spec), until we flush out #1371 ?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions