#Secret Var not working

1 messages ยท Page 1 of 1 (latest)

tough grove
#

Im trying to make a git clone with a auth token but i cant get it to work with the secret var. It is not populated or some how mis formated I think because the command fails with the error invalid password

code:

      const ghSecret = client.setSecret("ghApiToken", token);     

      const container = client
        .container()
        .from(BASE_IMAGE)
        .withWorkdir(workDir)
        // .withExec(["apt-get", "install", "-y", "git"])
        .withSecretVariable("GITHUB_TOKEN", ghSecret)
        .withExec(
          cloneCommand({ token: "$GITHUB_TOKEN", git: git, branch: branch })
        )
        .withExec(["npm", "i"])
        .withEntrypoint(["npm", "start"]);

cloneCommand:

export default function cloneCommand({
  token,
  git,
  branch,
}: {
  token: string;
  git: string;
  branch: string;
}) {
  const command = [
    "git",
    "clone",
    `https://x-access-token:${token}@github.com/${git}.git`,
    "-b",
    branch,
    ".",
  ];

  console.log(command.join(" "));

  return command;
}

What am I missing? Or how can I debug this?

Thx for your help ๐Ÿ˜„

sage marsh
#

Hey ๐Ÿ‘‹ One guess as to what's happening: the command needs to run in a shell to expand the variable. Can you try modifying the cloneCommand to return ["sh", "-c", command.join(" ")] and see if that fixes it?

tough grove
#

Hey Kyle, WOW this solved it thx for the very fast response!

sage marsh
#

Awesome, glad I could help ๐Ÿ™‚

tough grove
#

Now an other Problem arised ๐Ÿ™‚ It only works one time after that tha command is not beeing executed (As far as I can tell from the logs) dose this have something todo with cache? do you have a idea how I could fixe this?

candid temple
#

that way you'd only clone the repositroy each time the commit changes

#

otherwise it'll use the cached version

tough grove
#

Is there a parameter that allows that in the git cli?

candid temple
#

you can do a git clone and then git checkout

#

or you can use the native Dagger git operation for that

#

so basically:

connect(
  async (client) => {
    // get repository at specified branch
    const project = client
      .git("https://github.com/dagger/dagger")
      .commit("$SHA")
      .tree()
tough grove