Hello, how can I have a task that clones a GitHub ...
# ask-community
s
Hello, how can I have a task that clones a GitHub repository? I can't find it in the GiHub tasks. I want to run dbt project in ECSRun and I need to clone the latest project code before running dbt commands.
s
The Github tasks are for interacting with the Github API, not
git
. I've done this by using
ShellTasks
that run
git clone
and other such
git
commands as needed. You'll have to handle the authentication (username/pass or ssh key in a
Secret
). I used ssh authentication by extending
ShellTask
to take a
private_ssh_key
which writes it to a local file before using it in the
git
command by setting the
GIT_SSH_COMMAND
environment variable for the
ShellTask.run
Something like:
Copy code
class CloneTask(ShellTask):
  ...

  def run(self, repo=None, private_ssh_key=None, **kwargs):
    command = f"git clone {repo}"
    
    if private_ssh_key:
      with tempfile.NamedTemporaryFile('w') as k:
        k.write(private_ssh_key)
        k.flush()

        env = kwargs.pop("env", {})
        env["GIT_SSH_COMMAND"] = f"ssh -i {k.name}"

        return super().run(command=command, env=env, **kwargs)

    return super().run(command=command, **kwargs)
👍 1
k
Hi @Sumit Kumar Rai, check this blog post by Slate on how to clone the dbt repo and run the Models. I think this is what you’re looking for.