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

Add uid and gid as Docker environment variables #396

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ version: 2.1
orbs:
docker: circleci/docker@0.5.1
aws-eks: circleci/aws-eks@0.2.7
dotenv: anilanar/dotenv@1.0.0

workflows:
build_test_deploy:
Expand Down Expand Up @@ -60,7 +61,9 @@ jobs:
curl -L https://codeclimate.com/downloads/test-reporter/test-reporter-latest-linux-amd64 > /usr/local/bin/cc-test-reporter
chmod +x /usr/local/bin/cc-test-reporter
/usr/local/bin/cc-test-reporter before-build
- run: sudo chown -R 5000 .
- dotenv/source:
path: .env
- run: sudo chown -R ${UID}:${GID} .
- run:
name: Run tests
command: |
Expand Down
2 changes: 2 additions & 0 deletions .env
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,5 @@ FLASK_DEBUG=1
ALGOLIA_APP_ID=search_id
ALGOLIA_API_KEY=search_key
INDEX_NAME=resources_api
UID=5000
GID=5000
5 changes: 4 additions & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ ENV PYTHONUNBUFFERED 1
ENV PIP_NO_BINARY psycopg2
ENV FLASK_SKIP_DOTENV 1
ENV FLASK_APP run.py
ENV UID 1000
ENV GID 1000

WORKDIR /src

Expand All @@ -23,7 +25,8 @@ RUN poetry install --no-dev --no-interaction --no-ansi

COPY . /src

RUN useradd --no-create-home --system -s /bin/false --uid 5000 uwsgi
RUN groupadd --gid $GID uwsgi \
&& useradd --no-create-home --system -s /bin/false --uid $UID --gid $GID uwsgi
Copy link
Member

Choose a reason for hiding this comment

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

When you exec into the container, it's a little weird not having a name. Maybe we should give it one?

$ docker exec -it a536b7b91577 /bin/bash
I have no name!@a536b7b91577:/src$ whoami
whoami: cannot find name for user ID 5000
I have no name!@a536b7b91577:/src$

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I'm very consufed by the missing name because both the uwsgi is specified as group and user name and in the container I just built the container and this is the output:

platipo:~/resources_api $ sudo docker run -p80:5000 -it --rm resources_api/uwsgi /bin/bash
uwsgi@e26da29e625a:/src$ whoami
uwsgi

Copy link
Member

Choose a reason for hiding this comment

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

I ran my container with make run, I wonder if that has something to do with it?

Copy link
Member

Choose a reason for hiding this comment

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

It does docker-compose run -p 5000:5000 resources-api flask run -h 0.0.0.0. If you do that, do you also find that you're missing the user?

${DOCKER_COMPOSE} run -p 5000:5000 ${RESOURCES_CONTAINER} ${FLASK} run -h 0.0.0.0

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I tried some solutions, but I have no clue how to solve this 😢

Copy link
Member

Choose a reason for hiding this comment

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

Ok when I have some time I'll see if I can solve it. Maybe it's worth merging and opening that as a separate issue... I'll want to give it one more good review before I determine that. Thanks for your patience on this


RUN chown -R uwsgi /src

Expand Down
4 changes: 4 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@ services:
container_name: resources-api
env_file:
- .env
environment:
- UID=${UID}
- GID=${GID}
user: ${UID}:${GID}
volumes:
- .:/src
ports:
Expand Down