helm/chart-testing

failed linting and installing charts: failed identifying charts to process: must be in a git repository

Closed this issue · 3 comments

ffo9 commented

Is this a request for help?: Yes


Is this a BUG REPORT or FEATURE REQUEST? (choose one): n/a

Version of Helm and Kubernetes:

What happened:

Running ct as a docker container in Gitlab-ci fails due to git-related errors. I added some git commands at the start of the job to see git output. Can someone point out the problem

Running with gitlab-runner 17.5.1 (affd9e7d)
  on PM-Gitlab-Runner-for-Platform WpPD9BCJ, system ID: s_4b62ac538b86
Preparing the "shell" executor
00:00
Using Shell (bash) executor...
Preparing environment
00:00
Running on gitlab-runner-platform...
Getting source from Git repository
00:01
Fetching changes...
Initialized empty Git repository in /home/gitlab-runner/builds/WpPD9BCJ/0/sre/myproj-helm-chart/.git/
Created fresh repository.
Checking out 4b844538 as detached HEAD (ref is ffo/test-remote)...
Skipping Git submodules setup
Executing "step_script" stage of the job script
00:02
$ git rev-parse --is-inside-work-tree
true
$ # Run unit tests # collapsed multi-line command
Linting and installing charts...
>>> helm version --template {{ .Version }}
>>> git rev-parse --is-inside-work-tree
Error: failed linting and installing charts: failed identifying charts to process: must be in a git repository
------------------------------------------------------------------------------------------------------------------------
No chart changes detected.
------------------------------------------------------------------------------------------------------------------------
failed linting and installing charts: failed identifying charts to process: must be in a git repository
make: *** [Makefile:53: lint-install] Error 1
Cleaning up project directory and file based variables
00:00
ERROR: Job failed: exit status 1

What you expected to happen: Locally it runs successfully, but not gitlab ci.

How to reproduce it (as minimally and precisely as possible):

Gitlab-ci.yaml

test:
  stage: test
  before_script:
    - git rev-parse --is-inside-work-tree
  script:
    - |
      # Run unit tests
      # make unit-test
      
      # Run lint and install
      make lint-install

Makefile:

LINT_CMD ?= ct lint-and-install

.PHONY: lint-install
lint-install: requirements ## Run lint and test suite
	@sudo docker run --rm --network host --workdir=/data --volume $(KUBECONFIG):/root/.kube/config:ro --volume $(CURDIR):/data quay.io/helmpack/chart-testing:v3.7.1 $(LINT_CMD)

ct.yaml

# https://github.com/helm/chart-testing/blob/main/doc/ct_lint.md#ct-lint
chart-dirs:
  - ./
remote: origin
target-branch: main
debug: true
check-version-increment: true
validate-maintainers: false

Anything else we need to know:

ffo9 commented

Here's the code it fails on:

  • func (t *Testing) computeMergeBase() (string, error) {
    err := t.git.ValidateRepository()
    if err != nil {
    return "", errors.New("Must be in a git repository")
    }
    return t.git.MergeBase(fmt.Sprintf("%s/%s", t.config.Remote, t.config.TargetBranch), t.config.Since)
    }
  • func (g Git) ValidateRepository() error {
    _, err := g.exec.RunProcessAndCaptureOutput("git", "rev-parse", "--is-inside-work-tree")
    return err
    }

In my gitlab-ci before_script the statement succeeds however:

$ git rev-parse --is-inside-work-tree
true 
ffo9 commented

Okay, when you mount a git repository onto a docker container, this problem can occur. The fix for this was to change the command executed in the docker container:

LINT_CMD ?= /bin/bash -c 'git config --global --add safe.directory /data; ct lint-and-install;'

ffo9 commented

Not a bug