helm / chart-testing

CLI tool for linting and testing Helm charts
Apache License 2.0
1.37k stars 217 forks source link

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

Closed ffo9 closed 1 month ago

ffo9 commented 1 month ago

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 1 month ago

Here's the code it fails on:

In my gitlab-ci before_script the statement succeeds however:

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

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 1 month ago

Not a bug