fix: ensure setting /github/workdir as Git safe directory works always (#6242)
Some checks are pending
Publish Images / Build and Test (push) Waiting to run
Publish Images / Release (push) Blocked by required conditions
Build and Test / Set build metadata (push) Waiting to run
Build and Test / Build and Test (push) Blocked by required conditions
Build and Test / Test the Super-linter GitHub Action (push) Blocked by required conditions
Build and Test / Build test suite matrix (push) Waiting to run
Build and Test / Run test cases (push) Blocked by required conditions
Build and Test / Check if all the tests passed (push) Blocked by required conditions
Build and Test / preview-release-notes (push) Waiting to run
Lint commit / commitlint (push) Waiting to run

When running super-linter on in a self hosted runner based on Action
Runner Controller in K8s container mode the /github/home directory is
not neccesarily mounted. But since we expect this directory to exist
super-linter fails to set /github/workspace as a Git safe directory:

    2024-10-04 17:58:37 [INFO]   Successfully validated GITHUB_WORKSPACE: /github/workspace
    2024-10-04 17:58:37 [DEBUG]   Configuring Git safe directories
    2024-10-04 17:58:37 [DEBUG]   Set /github/workspace as a Git safe directory
    error: could not lock config file /github/home/.gitconfig: No such file or directory
    2024-10-04 17:58:37 [FATAL]   Cannot configure /github/workspace as a Git safe directory.

Making sure this directory exists in container image ensures that under
no circumstances we can fail - if the action runner provides
/github/home it will be mounted over, and if not we provide a directory
where git can actually create the new .gitconfig.

This also defaults the HOME environment variable to /github/home as it
is the default in most places. So if somebody decides to override HOME
they are also expected to ensure that this directory exists (or is a
volume mount)
This commit is contained in:
Andre Klärner 2024-12-12 16:44:28 +01:00 committed by GitHub
parent 24a53df7ba
commit ec05515e93
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 10 additions and 0 deletions

View file

@ -434,6 +434,11 @@ ENV RENOVATE_X_IGNORE_RE2="true"
ENV VERSION_FILE="/action/linterVersions.txt" ENV VERSION_FILE="/action/linterVersions.txt"
RUN mkdir /action RUN mkdir /action
# create the homedir, so that in case it is not present (like on action-runner-controller based selfhosted runners)
# we do not fail at setting /github/workspace as a safe git directory
ENV HOME="/github/home"
RUN mkdir -p "${HOME}"
ENTRYPOINT ["/action/lib/linter.sh"] ENTRYPOINT ["/action/lib/linter.sh"]
FROM base_image AS slim FROM base_image AS slim

View file

@ -18,6 +18,10 @@ control "super-linter-environment-variables" do
its("content") { should match(/^(standard|slim)$/) } its("content") { should match(/^(standard|slim)$/) }
end end
describe os_env("HOME") do
its("content") { should eq "/github/home" }
end
describe os_env("RENOVATE_X_IGNORE_RE2") do describe os_env("RENOVATE_X_IGNORE_RE2") do
its("content") { should eq "true" } its("content") { should eq "true" }
end end
@ -437,6 +441,7 @@ control "super-linter-validate-directories" do
desc "Check that directories that Super-Linter needs are installed." desc "Check that directories that Super-Linter needs are installed."
dirs = [ dirs = [
"/github/home",
"/node_modules", "/node_modules",
"/action/lib", "/action/lib",
"/action/lib/functions", "/action/lib/functions",