#How do I copy a file from outside of my dagger working directory into my dagger working directory?

1 messages · Page 1 of 1 (latest)

celest cedar
#

Let's say my dagger project is in ~/Workspace/dagger-project but I would like to copy a file from ~/.foobar/profile.yaml into this dagger project directory. How would I do that using dagger-cue?

desert acorn
#

The example shows a path of "." aka pwd, but you can put your path outside of the pwd/working directory on your host.

#

you'd prob copy ~/.foobar/profile.yaml into a directory on a container and then export it out.

celest cedar
#

Can I have multiple paths? Is there an full example I can look at?

#

Here is my cue file ```package dbt

import (
"dagger.io/dagger"
"universe.dagger.io/bash" // import this package to execute bash commands inside a docker container
"universe.dagger.io/docker" // import this package to set up docker
)

dagger.#Plan & {
// configure the client so that dagger takes only the files it needs
client: filesystem: ".": read: contents: dagger.#FS

actions: {

    // copy contents of repo  
    deps: docker.#Dockerfile & {
        source: client.filesystem.".".read.contents
        dockerfile: path: "Dockerfile"
    }

    // print python version 
    version: bash.#Run & {
        input:   deps.output
        workdir: "/app"
        script: contents: """
            python --version
            """
    }


    // run dbt test
    dbt_test: bash.#Run & {
        input:   deps.output
        workdir: "/app/dbt"
        script: contents: """
            dbt debug --profiles-dir ./secrets && dbt deps --profiles-dir ./secrets && dbt test --profiles-dir ./secrets
            """
    }
}

}

desert acorn
#

Your deps action builds an image from a Dockerfile. Do you then want to copy ~/.foobar/profile.yaml into the image's root filesystem somewhere?

desert acorn
#

docker.#Build is helpful to do a set of build steps where the output of one step feeds in as the input of the next. You could continue adding more directories with filtered sets of files with more docker.#Copy steps 🙂
This guide has lots of details on the docker package: https://docs.dagger.io/sdk/cue/966156/docker#dockerbuild

package main

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

dagger.#Plan & {
  // configure the client so that dagger takes only the files it needs
  client: filesystem: {
    ".": read: contents: dagger.#FS
    "~/.foobar": read: {
      contents: dagger.#FS
      include: ["profile.yaml"]
    }
  }

  actions: {
    deps: {
      docker.#Build & {
        steps: [
          docker.#Dockerfile & {
            source: client.filesystem.".".read.contents
          },
          docker.#Copy & {
            contents: client.filesystem."~/.foobar".read.contents
            dest:     "/app/.foobar"
          },
        ]
      }
    }

    print: bash.#Run & {
      input:   deps.output
      workdir: "/app"
      script: contents: """
        ls -al .
        ls -al .foobar   
        cat .foobar/profile.yaml
        """
      always: true
    }
  }
}

The universe.dagger.io module is meant to provide higher level abstractions on top of core actions. Of these, the universe.dagger.io/docker package provides a general base for building and running docker images.

#
copy2 ➤ ls
Dockerfile cue.mod    main.cue
copy2 ➤ cat Dockerfile
FROM ubuntu:latest
copy2 ➤ cat ~/.foobar/profile.yaml
Hello from Dagger!
copy2 ➤ dagger-cue do print --log-format plain
10:24PM INFO  actions.print.script._write | computing
10:24PM INFO  client.filesystem.".".read | computing
10:24PM INFO  client.filesystem."~/.foobar".read | computing
10:24PM INFO  actions.print.script._write | completed    duration=0s
10:24PM INFO  client.filesystem."~/.foobar".read | completed    duration=0s
10:24PM INFO  client.filesystem.".".read | completed    duration=100ms
10:24PM INFO  actions.deps._dag."0"._build | computing
10:24PM INFO  actions.deps._dag."0"._build | completed    duration=1.2s
10:24PM INFO  actions.deps._dag."1"._copy | computing
10:24PM INFO  actions.deps._dag."1"._copy | completed    duration=0s
10:24PM INFO  actions.print._exec | computing
10:24PM INFO  actions.print._exec | completed    duration=100ms
10:24PM INFO  actions.print._exec | #9 0.102 total 12
10:24PM INFO  actions.print._exec | #9 0.102 drwxr-xr-x 3 root root 4096 Nov  2 05:18 .
10:24PM INFO  actions.print._exec | #9 0.102 drwxr-xr-x 1 root root 4096 Nov  2 05:24 ..
10:24PM INFO  actions.print._exec | #9 0.102 drwxr-xr-x 2 root root 4096 Nov  2 05:18 .foobar
10:24PM INFO  actions.print._exec | #9 0.104 total 12
10:24PM INFO  actions.print._exec | #9 0.104 drwxr-xr-x 2 root root 4096 Nov  2 05:18 .
10:24PM INFO  actions.print._exec | #9 0.104 drwxr-xr-x 3 root root 4096 Nov  2 05:18 ..
10:24PM INFO  actions.print._exec | #9 0.104 -rw-r--r-- 1 root root   19 Nov  2 01:31 profile.yaml
10:24PM INFO  actions.print._exec | #9 0.105 Hello from Dagger!