#Use directories with dagger...

1 messages · Page 1 of 1 (latest)

elfin grove
#

Hi,
im really struggling with using directories..
I dont know if I am stupid or I dont read enough docs.

export async function cdk8sDevRelease(props: cdk8sDevReleaseProps) {
  const { application } = props
  console.log(`Received application parameter: ${application}`)
  return await dag.container()
    .from("node:22")
    .withMountedDirectory("/kubernetes", dag.directory().withNewDirectory(path.join(process.cwd(), "../kubernetes")))
    .withWorkdir("kubernetes")
    .withExec(["ls", "-lah"])
    .sync()
}

this method is called via index.ts

@func()
  async test(application: string) {
    return await cdk8sDevRelease(
      {
        application: application,
      }
    )
  }

the pipeline looks like the following:

steps:
  - script: curl -fsSL https://dl.dagger.io/dagger/install.sh | BIN_DIR=$HOME/.local/bin sh
    displayName: 'Install Dagger CLI'

  - script: |
      export PATH=$HOME/.local/bin:$PATH
      dagger version
    displayName: 'Verify Dagger Installation'

  - script: |
      export PATH=$HOME/.local/bin:$PATH
      cd dagger-pipelines
      dagger call test --application ${{ parameters.application }}
    displayName: 'Run Local Dagger Module'

I am really struggeling with mounting the ../kubernetes direcoty which is part of the project and contains cdk8s stuff.
My goal is to run npm runcommands.

Can someone help me please?
Thank you in advance!

shell sigil
elfin grove
#

I tried the dag.host() method but when i run the dagger function local or in azure pipeline it always said, dag.host() is not a function...

shell sigil
#

Dagger is pretty sandboxed, so you have to explicitly pass a directory in when calling the function OR you can access the "context directory" aka the directory tree of your daggerized project (e.g. in an existing project repo you ran dagger init --sdk typescript and got a .dagger directory in there).

#

You can specify a default directory within the context dir in code as well.

#

You just can't escape that directory to protect you from a rogue module pulling files from your machine.

elfin grove
#

I see, right now i used dagger initin a directory "under" root folder.

shell sigil
#

So, not inside an existing project, right?
Sounds like you started a standalone module that you'd like to make reusable across many projects?

elfin grove
#

It is inside a existing project, I got a kubernetes dir, terraform dir and on the same level a dagger-pipelines directory where I cd´ed in and ran dagger init

#

so what you would suggest is running dagger init on root directory to make the kubernetes and terraform available in the container?

#

thank you, will give it a try. But the code above seems to be right for now?
I will remove the directory and it will be automatically inside once its in the root?

#

Sorry for all the questions kind a tried my best by now and feel quite noobish.

shell sigil
#

It is possible to assign a default path for a Directory or File argument in a Dagger Function. Dagger will automatically use this default path when no value is specified for the argument. The Directory or File loaded in this manner is not merely a string, but the actual filesystem state of the directory or file.