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

fix(atlantis): allow .gitconfig write #407

Merged
merged 2 commits into from
Jul 18, 2024

Conversation

GMartinez-Sisti
Copy link
Member

@GMartinez-Sisti GMartinez-Sisti commented Jul 17, 2024

what

Chart users want to edit /home/atlantis/.gitconfig while specifying a default value for the file.

This PRs allows setting gitconfig and introduces gitconfigReadOnly to allow editing the .gitconfig file on the atlantis pod. While this is a technically a feature, it was something that was working previously (see references below) and gitconfigReadOnly behavior matches the existing version, so this is being treated as a fix.

The fix leverages /docker-entrypoint.d/ scripts to run the desired script on start, the script copies the gitconfig data into the file, ensuring that the file can be edited by atlantis.

Unit tests were added for this fix.

tests

Deploy with default value

Deploy command:

helm upgrade -i test-atlantis ./charts/atlantis/ -f ./charts/atlantis/test-values.yaml

Log from atlantis pod:

No files found in /docker-entrypoint.d/, skipping
{"level":"info","ts":"2024-07-17T11:59:58.011Z","caller":"server/server.go:319","msg":"Supported VCS Hosts%!(EXTRA string=hosts, ]models.VCSHostType=[Github])","json":{}}
{"level":"info","ts":"2024-07-17T11:59:58.359Z","caller":"server/server.go:467","msg":"Utilizing BoltDB","json":{}}
{"level":"info","ts":"2024-07-17T11:59:58.362Z","caller":"policy/conftest_client.go:153","msg":"failed to get default conftest version. Will attempt request scoped lazy loads DEFAULT_CONFTEST_VERSION not set","json":{}}
{"level":"info","ts":"2024-07-17T11:59:58.362Z","caller":"server/server.go:1017","msg":"Atlantis started - listening on port 4141","json":{}}
{"level":"info","ts":"2024-07-17T11:59:58.362Z","caller":"scheduled/executor_service.go:51","msg":"Scheduled Executor Service started","json":{}}

Deploy with gitconfigReadOnly set to false

Deploy command:

→ helm upgrade -i test-atlantis ./charts/atlantis/ -f ./charts/atlantis/test-values.yaml --set gitconfigReadOnly=false --set "gitconfig=foo
> bar
> "

Log from atlantis pod:

/docker-entrypoint.d/ is not empty, will attempt to perform script execition
Looking for shell scripts in /docker-entrypoint.d/
Launching /docker-entrypoint.d/gitconfig-init.sh
+ cp -v /etc/.gitconfig /home/atlantis/.gitconfig
'/etc/.gitconfig' -> '/home/atlantis/.gitconfig'
+ chown -v atlantis /home/atlantis/.gitconfig
changed ownership of '/home/atlantis/.gitconfig' to 100:0
Configuration complete; ready for start up
{"level":"info","ts":"2024-07-17T12:20:27.226Z","caller":"server/server.go:319","msg":"Supported VCS Hosts%!(EXTRA string=hosts, ]models.VCSHostType=[Github])","json":{}}
{"level":"info","ts":"2024-07-17T12:20:27.833Z","caller":"server/server.go:467","msg":"Utilizing BoltDB","json":{}}
{"level":"info","ts":"2024-07-17T12:20:27.834Z","caller":"policy/conftest_client.go:153","msg":"failed to get default conftest version. Will attempt request scoped lazy loads DEFAULT_CONFTEST_VERSION not set","json":{}}
{"level":"info","ts":"2024-07-17T12:20:27.834Z","caller":"server/server.go:1017","msg":"Atlantis started - listening on port 4141","json":{}}
{"level":"info","ts":"2024-07-17T12:20:27.834Z","caller":"scheduled/executor_service.go:51","msg":"Scheduled Executor Service started","json":{}}

Confirm we can edit the file, from the pod:

test-atlantis-0:/$ cat /home/atlantis/.gitconfig
foo
bar
test-atlantis-0:/$ echo baz >> /home/atlantis/.gitconfig
test-atlantis-0:/$ cat /home/atlantis/.gitconfig
foo
bar
baz
test-atlantis-0:/$

references

@GMartinez-Sisti GMartinez-Sisti marked this pull request as ready for review July 17, 2024 12:54
@GMartinez-Sisti GMartinez-Sisti requested a review from a team as a code owner July 17, 2024 12:54
Copy link
Member

@chenrui333 chenrui333 left a comment

Choose a reason for hiding this comment

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

lgtm

@GMartinez-Sisti GMartinez-Sisti merged commit 58ecee7 into runatlantis:main Jul 18, 2024
2 checks passed
@GMartinez-Sisti GMartinez-Sisti deleted the git-conf-rw branch July 18, 2024 10:01
@fede-r1c0
Copy link

This works, thanks!

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.

gitconfig credential.helper error: Resource busy helm chart gitconfig option ignored
3 participants