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

Allow UID for git user in docker container to be specified via ENV variable #3520

Closed
JohnOmernik opened this issue Aug 26, 2016 · 8 comments
Closed
Labels
🔨 enhancement Make it better, faster status: needs feedback Tell me more about it

Comments

@JohnOmernik
Copy link

  • Operating system: Docker
  • Feature Request:

    Description

    It would be helpful for users who may use NFS or other shared storage for the gogs volume to have the UID of the git user specified in the add user command in build.sh. Basically, a variable such as GIT_UID, if set would invoke the add user command with the speceific user id, if not set, then don't run the command with a UID specified.

Thanks

@unknwon
Copy link
Member

unknwon commented Aug 26, 2016

cc @0rax

@unknwon unknwon added the 🔨 enhancement Make it better, faster label Aug 26, 2016
@0rax
Copy link
Contributor

0rax commented Sep 3, 2016

Hi there, sorry for the delay.

The thing being that the Git user is created a the creation of the container and not at runtime does not really allow us to make that configurable on a user to user basis.

Nonetheless, this can still be possible by creating this user during container initialization (before Gogs is started). I totally understand the need for this kind of feature and will definitly try to implement that.

I will keep you informed here, but as said, there is two way to do that:

  • At container build time (which requires people to build their own version of the container to run with a specific UID) using Docker build-args.
  • Or move the creation of the user during container initialization and using an environment variable, by adding something like this to docker/s6/gogs/setup or docker/start.sh:
GIT_UID=$(GIT_UID:-500) # default

adduser -H -D -g 'Gogs Git User' git -h /data/git -s /bin/bash -u ${GIT_UID} && passwd -u git

Both options are correct, and I would prefer the creation of the user at runtime for ease of use (having to build the container yourself whenever there is an update upstream doesn't feel right when the project is already giving you a container). And this might not be that hard to implement as well, as we already change user at runtime to run gogs (running user is not set staticly in the Dockerfile).

I have some other work to do on the container (upgrade to latest alpine and so on), I will definitly look at it in the mean time.

@davidjb
Copy link
Contributor

davidjb commented Mar 28, 2017

Could this be implemented with the ability to set GID as well?

Either way, ability to set UID/GUID would help avoid conflicts of user/group between host and container. Gogs is currently writing files as the git user inside the container, but it ends up as a different user outside because of the UID being reused.

An example of UID/GID setting from env variables, if it helps:
https://github.com/plexinc/pms-docker/blob/d1ea49cc79deaad395f8448a606811aafc64d402/root/etc/cont-init.d/40-plex-first-run#L37

@unknwon
Copy link
Member

unknwon commented Mar 28, 2017

Do need someone with expertise to propose a PR...

@robertbeal
Copy link
Contributor

robertbeal commented Sep 16, 2017

Made a PR, hope it's ok. It uses usermod and groupmod to change the id's of the user/group. A fairly common technique for handling this sort of issue. Means the user creation can stay in the build process, the setting of the uid/gid happens at runtime.

Like others, I noticed the file ownership of my /var/gogs directory was 1000:1000 which mapped to my user (when I have a gogs system user for all things gogs) which I didn't want it to.

@unknwon
Copy link
Member

unknwon commented Oct 13, 2017

This is claimed to be fixed by merging #4776, please help test on develop branch.

@unknwon unknwon added the status: needs feedback Tell me more about it label Oct 13, 2017
@unknwon unknwon removed the status: assigned to maintainer Welcome onboard label Oct 13, 2017
@unknwon unknwon added this to the 0.12 milestone Oct 13, 2017
@ccvca
Copy link

ccvca commented Nov 1, 2017

Just one notice: Jenkins does this by a build argument:
https://github.com/jenkinsci/docker/blob/master/Dockerfile-alpine

I do not know the pros and cons for this approach instead of environment variables, ...

@robertbeal
Copy link
Contributor

Both can be done. via build argument means you have to build the container yourself (which can be a nuisance as you'll have to manage changes and updates etc...)

Using environment variable means you can use the official image and specify the ID's at runtime. The downside is that you can't run your container in --read-only mode as this method modifies /etc/passwd.

I run my own image here: https://github.com/robertbeal/docker-gogs. The readme probably better explains the above.

@unknwon unknwon closed this as completed Nov 19, 2017
@unknwon unknwon removed this from the 0.13 milestone Nov 26, 2019
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Mar 20, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
🔨 enhancement Make it better, faster status: needs feedback Tell me more about it
Projects
None yet
Development

No branches or pull requests

6 participants