akeneo / Dockerfiles

DEPRECATED for PIM 4.0 and above - Official Dockerfiles for Akeneo development and testing
https://hub.docker.com/r/akeneo/
MIT License
49 stars 34 forks source link

Allow for user-ids other than 1000 #354

Closed aligent-lturner closed 4 years ago

aligent-lturner commented 4 years ago
Q A
Bug report? no
Feature request? yes
BC Break report? no
RFC? no
Affected image and tag akeneo/node:10

By default, the node user is given user and group id of 1000. This is difficult to work with your local user does not have the same id. Instead, we should provide the option for an argument to allow a different id to be passed in and assigned to the node user.

damien-carcel commented 4 years ago

Hello @aligent-lturner.

First thing first, thank you for raising this issue and proposing a pull-request :+1:.

However, I don't think you need to go that far as rebuild the Node image. If your IDs, are different from the node user, you can just choose not to use this user at all. This is what we do on the CI of some of the projects I work on (I use CircleCI, and the default user has 1001:1002 as user IDs).

Here is an example of Docker Compose service that is working great in that case:

services:
  node:
    image: 'akeneo/node:10'
    user: '${HOST_USER_IDS:-1000:1000}'
    volumes:
      - './:/srv/app'
      - '${HOST_YARN_CACHE_FOLDER:-~/.cache/yarn}:/home/yarn-cache'
      - '${HOST_YARN_CONFIG_FOLDER:-~/.yarn}:/.yarn'
      - '${HOST_YARN_CONFIG_FILE:-~/.yarnrc}:/.yarnrc'

The trick here is to export on your own machine your own IDs so the container runs with those instead of 1000:1000. It doesn't matter the user does not exist, the only consequence is you'll have the message "I have no name!" if you connect in the container (using docker-compose run --rm node bash for instance).

But for the trick to work, you need to define the Yarn configuration files and folders and to bind-mount them to yours, or Yarn will complain it cannot create them, as there is no real user.

Let me know if this solution is enough for you, as it avoid to locally building the image. If not (maybe there are issues I don't know about), I'll merge your pull-request (I suggested a change on it :slightly_smiling_face:).

aligent-lturner commented 4 years ago

@damien-carcel there are ways around the restriction, it's true. This pull request was more for trying to get some consistency with the other images used in the default docker-compose of the akeneo pim repository (for PHP and fpm). I want to make it as easy as possible for users to set up the pim for development locally, by being able to use a single environment variable as the user id for all the relevant containers. The official documentation itself states that your user must have the id of 1000, so I want to rejoice that barrier for people with as little work at possible on their end (i.e. still being able to use the default cache locations, etc.

I've just gone through this whole process myself while trying to get v4 running locally, so I want others to not face the same issues I did.

If people don't want to change anything, they don't need to, and it will default to 1000 anyway.

Thoughts?

damien-carcel commented 4 years ago

I totally agree with you on "make it as easy as possible".

In fact, I think that ideally, the node image should build from the PIM Dockerfile itself, like it is done since Akeneo 4.0 for PHP/FPM. And the PHP/FPM image should set the www-data user IDs during the build exactly like you are doing in the Node image. This way both images would have the same IDs as the host machine.

I tried to push this solution to the PIM team recently, but the answer was "we are not aware of such an issue with the IDs"... I think it could help if you opened an issue on the akeneo/pim-community-dev repository explaining the issues you had during the setup of the PIM with Docker. This could make things move.

Meanwhile, I'm gonna merge your PR as it works like a charm and doesn't impact its current usage.

Again, thank you for the pull-request and the nice issue linked to it :slightly_smiling_face:.