Skip to content

Add output files#1528

Merged
aluzzardi merged 1 commit intodagger:mainfrom
helderco:outputs-files
Jan 31, 2022
Merged

Add output files#1528
aluzzardi merged 1 commit intodagger:mainfrom
helderco:outputs-files

Conversation

@helderco
Copy link
Copy Markdown
Contributor

Closes #1317

Signed-off-by: Helder Correia


Why

If you want to save a string into the local disk (e.g., writing a docker-compose.yaml file from CUE), currently you need to create a #FS via engine.#WriteFile and reference it in outputs: directories. This can be made simpler.

What

Added outputs: files to the plan to make it easier to write a string to a file, without having to go through engine.#WriteFile.

How

Here’s an example on writing a docker compose file from CUE:

package main

import (
    "encoding/yaml"
    "dagger.io/dagger"
)

dagger.#Plan & {
    actions: {
        app: {
            services: app: {
                build: "app"
                ports: ["8080:80"]
            }
        }
    }
    outputs: files: {
        compose: {
            dest: "docker-compose.yaml"
            contents: yaml.Marshal(actions.app)
        }
    }
}

You can change file permissions as well (default is 0644):

package main

import "dagger.io/dagger"

dagger.#Plan & {
    outputs: files: {
        [path=string]: dest: path
        "test.sh": {
            contents: """
                #!/bin/bash
                set -euo pipefail
                echo "Hello World!"

                """
            permissions: 0o750
        }
    }
}

Copy link
Copy Markdown
Contributor

@aluzzardi aluzzardi left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, thanks @helderco!

To me this is ready to go -- @shykes want to take a look at the DX?

Copy link
Copy Markdown
Contributor

@shykes shykes left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good overall:

  • See my comment below about optional field
  • Could you write a small docs article about using this feature? It can be very basic. NOTE: this can be in a follow-up PR.

Signed-off-by: Helder Correia <[email protected]>
@helderco
Copy link
Copy Markdown
Contributor Author

helderco commented Jan 31, 2022

  • Could you write a small docs article about using this feature? It can be very basic. NOTE: this can be in a follow-up PR.

Certainly. If you don't want to hold off on this feature until it's ready, I'll push another PR with it.

@netlify
Copy link
Copy Markdown

netlify bot commented Jan 31, 2022

@aluzzardi
Copy link
Copy Markdown
Contributor

Certainly. If you don't want to hold off on this feature until it's ready, I'll push another PR with it.

I'm in favor of merging this so it's included in 0.2.0.alpha.3 tomorrow and having the docs in a follow up

@aluzzardi aluzzardi merged commit 15bb3d9 into dagger:main Jan 31, 2022
@aluzzardi aluzzardi deleted the outputs-files branch January 31, 2022 23:43
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Europa: output files

3 participants