Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Git LFS support #872

Merged
merged 4 commits into from
Mar 27, 2020
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion docker-base/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ RUN addgroup atlantis && \
# Install dumb-init and gosu.
ENV DUMB_INIT_VERSION=1.2.2
ENV GOSU_VERSION=1.11
RUN apk add --no-cache ca-certificates gnupg curl git unzip bash openssh libcap openssl && \
RUN apk add --no-cache ca-certificates gnupg curl git git-lfs unzip bash openssh libcap openssl && \
curl -L -s --output /bin/dumb-init "https://github.com/Yelp/dumb-init/releases/download/v${DUMB_INIT_VERSION}/dumb-init_${DUMB_INIT_VERSION}_amd64" && \
chmod +x /bin/dumb-init && \
mkdir -p /tmp/build && \
Expand Down
26 changes: 21 additions & 5 deletions server/events/working_dir.go
Original file line number Diff line number Diff line change
Expand Up @@ -215,15 +215,17 @@ func (w *FileWorkspace) forceClone(log *logging.SimpleLogger,
}
}

env := append(os.Environ(), []string{
"EMAIL=atlantis@runatlants.io",
"GIT_AUTHOR_NAME=atlantis",
"GIT_COMMITTER_NAME=atlantis",
}...)

for _, args := range cmds {
cmd := exec.Command(args[0], args[1:]...) // nolint: gosec
cmd.Dir = cloneDir
// The git merge command requires these env vars are set.
cmd.Env = append(os.Environ(), []string{
"EMAIL=atlantis@runatlants.io",
"GIT_AUTHOR_NAME=atlantis",
"GIT_COMMITTER_NAME=atlantis",
}...)
cmd.Env = env

cmdStr := w.sanitizeGitCredentials(strings.Join(cmd.Args, " "), p.BaseRepo, headRepo)
output, err := cmd.CombinedOutput()
Expand All @@ -234,6 +236,20 @@ func (w *FileWorkspace) forceClone(log *logging.SimpleLogger,
}
log.Debug("ran: %s. Output: %s", cmdStr, strings.TrimSuffix(sanitizedOutput, "\n"))
}

cmd := exec.Command("git", "lfs", "pull")
cmd.Dir = cloneDir
cmd.Env = env

output, err := cmd.CombinedOutput()
sanitizedOutput := w.sanitizeGitCredentials(string(output), p.BaseRepo, headRepo)
// Git LFS may not be enabled on this repository or may not have been
// installed by the user.
if err != nil && err.(*exec.ExitError).ExitCode() != 1 {
sanitizedErrMsg := w.sanitizeGitCredentials(err.Error(), p.BaseRepo, headRepo)
return fmt.Errorf("running git lfs pull: %s: %s", sanitizedOutput, sanitizedErrMsg)
}
log.Debug("ran: git lfs pull. Output: %s", strings.TrimSuffix(sanitizedOutput, "\n"))
return nil
}

Expand Down