#are there any strategies for working

1 messages · Page 1 of 1 (latest)

hollow sandal
#

Here's one simple example that uses Dagger's bash package. Though of course you could be doing anything in Dagger that you like:

dagger do --with "actions:workdir:\"$PWD\"" --with "actions:outdir:\"/tmp/foobar\"" generate
#
package generate

import (
  "dagger.io/dagger"
  "universe.dagger.io/bash"
  "universe.dagger.io/alpine"
  "universe.dagger.io/docker"

)

dagger.#Plan & {
  client: filesystem: {
    (actions.workdir): read: contents: dagger.#FS
    (actions.outdir): write: contents: actions.generate.output
  }

  actions: {
    // the local directory with stuff you want to work on
    workdir: string
    // the local directory where you want to put the results
    outdir: string

    // image with whatever tools you need
    _alpine: alpine.#Build & {
      packages: bash: _
      packages: curl: _
      packages: jq:   _
    }
    // load up the workdir contents
    _image: docker.#Copy & {
      input:    _alpine.output
      contents: client.filesystem[actions.workdir].read.contents
      dest:     "/src"
    }
    // do the work! package results in an output directory
    generate: {
      run: bash.#Run & {
        input:   _image.output
        workdir: "/src"
        script: contents: """
            mkdir /tmp/output
            ls . | jq -R -s -c 'split("\n")[:-1]' > /tmp/output/directory.json  
          """
        always: true
        export: directories: "/tmp/output": dagger.#FS
      }
      output: run.export.directories."/tmp/output"
    }
  }
}
dense pilot
#

ah yes. client.filesystem has a write field. Thats nice. Does it work when you want to produce a single file into the current project?

#

Seems like you would override the whole directory.

slender storm
#

@dense pilot If contents: string | #Secret, path will be written as a file. If it's an #FS, it'll be written as a directory.

hollow sandal
dense pilot
#

ok cool. Thank you 🙂 Will experiment with that and see if I can get rid of my make files.

#

although I kinda like makefiles