coder / modules

A collection of Terraform Modules to extend Coder templates.
https://registry.coder.com
Apache License 2.0
33 stars 32 forks source link

rfc(git-clone) update repo and post pull script #332

Open djarbz opened 3 weeks ago

djarbz commented 3 weeks ago

Looking for thoughts on these two items, I'm willing to submit a PR if we like it.

  1. If the repo already exists, we should fetch updates and perform a ff merge on an opt-in basis. Something like below, I just added this to my dotfiles. Might need to rework the merge logic to select the correct branch.

    if [ -v PROJECT_DIRECTORY ]; then
    echo "Checking for project updates"
    current_branch=$(git rev-parse --abbrev-ref HEAD)
    # Sync remote changes
    git -C "${PROJECT_DIRECTORY}" fetch origin
    # Apply updates if no conflicts
    git -C "${PROJECT_DIRECTORY}" merge "origin/${current_branch}" --ff-only
    fi
  2. After successfully cloning, or performing a ff merge, we should run a "setup script" if found to perform repo specific setup. This is currently what I have in my dotfiles, doesn't matter if the script is executable or not.

    # Prep cloned workspace via any found `coder.bootstrap` executable files in the project directory.
    if [ -v PROJECT_DIRECTORY ]; then
    echo "Prepping Project Workspace..."
    find "${PROJECT_DIRECTORY}" -name coder.bootstrap -type f -print -exec bash {} \;
    fi
matifali commented 2 weeks ago

I agree with the proposal if we also add a switch to retain the previous behaviour of the git-clone module. @johnstcn what do you think?

johnstcn commented 2 weeks ago

Re: 1) I think this is fine on an opt-in basis

Re: 2) This could be done as a separate step; there may be cases where this requires specific dependencies that are not yet available inside the workspace?

matifali commented 2 weeks ago

For me, 2) is out of scope for git-clone.