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 support for Git LFS enabled repositories (fixes #1853) #1941

Merged
merged 19 commits into from
Jul 18, 2019

Conversation

jannfis
Copy link
Member

@jannfis jannfis commented Jul 15, 2019

This PR enables LFS (Large File Support) for repositories and fixes #1853

For this, a new switch --enable-lfs is introduced to repo add command. LFS must be enabled on a per repository basis, and it should be used carefully (because LFS can reference really large files).

For declarative setup, the property name is enableLfs and of type bool.

As a bonus, while I was at the code, I fixed upsert mechanism for the insecure-ignore-host-key and insecure-skip-server-validation setting of repositories as well.

@@ -361,9 +395,8 @@ func (m *nativeGitClient) runCredentialedCmd(command string, args ...string) (st
func (m *nativeGitClient) runCmdOutput(cmd *exec.Cmd) (string, error) {
cmd.Dir = m.root
cmd.Env = append(cmd.Env, os.Environ()...)
cmd.Env = append(cmd.Env, "HOME=/dev/null")
cmd.Env = append(cmd.Env, "GIT_CONFIG_NOSYSTEM=true")
cmd.Env = append(cmd.Env, "GIT_CONFIG_NOGLOBAL=true")
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have removed these environment variables, since I was assuming these were set to not fiddle with Git configuration when the argocd CLI still tested repository access from the client it was executed. This behaviour was removed with PR #1807, and the git is not called on the client anymore.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this is right assumption and we don't need these variables anymore. @jessesuen can you confirm please?

Copy link
Collaborator

@alexmt alexmt left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM. @jessesuen can you take a look too? Looking for confirmation about GIT_CONFIG_NOSYSTEM, GIT_CONFIG_NOGLOBAL env variables

@jannfis
Copy link
Member Author

jannfis commented Jul 17, 2019

I just added tests for the PR that references a LFS enabled mock repository in my GitHub account from https://github.com/jannfis/argocd-testrepo-lfs - if you want, you can clone that repository to argocd GitHub account and I will change the reference in the code.

@alexmt
Copy link
Collaborator

alexmt commented Jul 17, 2019

Forked test repo to https://github.com/argoproj-labs/argocd-testrepo-lfs

@jannfis
Copy link
Member Author

jannfis commented Jul 17, 2019

Hm, I can't seem to get the LFS plugin for Git into the image run during CircleCI workflow. I updated base image in Dockerfile, but that does not seem to work. Does it work differently for CircleCI? Do I have to perform additional steps?

@alexmt
Copy link
Collaborator

alexmt commented Jul 17, 2019

Ah, right. I need to update builder image and push it. Doing it right now. Can you please change image to argoproj/argo-cd-ci-builder:v1.0.1 here https://github.com/argoproj/argo-cd/blob/master/test/fixture/testrepos/start-git.sh#L5-L5 ?

@@ -41,14 +41,15 @@ type Client interface {
Checkout(revision string) error
LsRemote(revision string) (string, error)
LsFiles(path string) ([]string, error)
LsLargeFiles() ([]string, error)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There is one more struct which supposed to implement git client interface: https://github.com/argoproj/argo-cd/blob/master/reposerver/metrics/gitwrapper.go#L1-L1

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, one little change, so much butterfly effect. Should have compiled all components before pushing that commit :|

@jannfis
Copy link
Member Author

jannfis commented Jul 17, 2019

I missed some additional changes in Git Client interface which I introduced for the tests with commit
e94726b, which broke the e2e tests (and the reposerver, d'oh). Will fix that tomorrow. Meanwhile, can't figure out why the build is still failing.

@@ -139,6 +140,37 @@ func TestLsRemote(t *testing.T) {
}
}

// Running this test requires git-lfs to be installed on your machine.
func TestLFSClient(t *testing.T) {
tempDir, err := ioutil.TempDir("", "git-client-lfs-test-")
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks like we will need to install git-lfs in circle ci config:

https://discuss.circleci.com/t/is-git-lfs-supported-by-circleci-2-0/11283/7

          name: Install Git LFS
          command: |
            curl -s https://packagecloud.io/install/repositories/github/git-lfs/script.deb.sh | bash
            apt-get update
            apt-get install -y git-lfs openssh-client

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks a lot @alexmt - I got CircleCI to install & use the Git LFS plugin now. Unfortunately, this led to another error, which I believe is CircleCI specific. The LFS test fails with:

Error Trace:    git_test.go:162
Error:          Received unexpected error:
                `git lfs fetch --all` failed exit status 2: batch request: Invalid deploy key for argoproj-labs/argocd-testrepo-lfs: exit status 1
                error: failed to fetch some objects from 'https://github.com/argoproj-labs/argocd-testrepo-lfs.git/info/lfs'
Test:           TestLFSClient

I changed test repositories, but to no avail A quick search on Google revealed not much to this specific error, and all I found seems to be CircleCI related. The LFS works from multiple machines I tested on, just not in the CircleCI build. I will look through their support base for possible solutions, or write to their support.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We are going to dockerize tests since it's been pretty painful to configure Circle CI same as real production environment. I would suggest moving your test to test/e2e directory and skip it during CI run using test.LocalOnly(t) (example)

After dockerizing the tests we will enable this test in CI

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have found the reason and could fix it. CircleCI injects a SSH key to the user's $HOME/.ssh, which is reason for LFS failing (doesn't like deploy keys). Actually, I guess that was one of the reasons why HOME was set to /dev/null in Git client implementation -- and I removed that with one of the previous commits. It's back in place now, LFS now also works in the CI environment.

@jannfis
Copy link
Member Author

jannfis commented Jul 18, 2019

Ah, right. I need to update builder image and push it. Doing it right now. Can you please change image to argoproj/argo-cd-ci-builder:v1.0.1 here https://github.com/argoproj/argo-cd/blob/master/test/fixture/testrepos/start-git.sh#L5-L5 ?

I had to switch back to v1.0.0 because the v1.0.1 seems broken - it apperently has no goreman included. Output from make start-e2e:

18:39:53  git-server | bash: goreman: command not found
18:39:53  git-server | Terminating git-server

@jannfis
Copy link
Member Author

jannfis commented Jul 18, 2019

Following E2E test is failing: TestCRDs - e2e - ran fine two cycles ago, also runs fine locally. I suspect hiccup/timeout.

From my point of view, this PR is ready for merge at your discretion.

Thanks a lot for your help and shared experience, @alexmt !

@alexmt
Copy link
Collaborator

alexmt commented Jul 18, 2019

Awesome! Thank you, @jannfis. You are right about e2e test failure. We've just found it is due to a real bug: #1940

LGTM

@alexmt alexmt merged commit 8f3a604 into argoproj:master Jul 18, 2019
@alexec alexec added this to the v1.2 milestone Jul 24, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

ArgoCD Does Not Support LFS
3 participants