From 0d0b64b4a24ea16048874eeec59bc93b427ccea0 Mon Sep 17 00:00:00 2001 From: Enrico Paganin Date: Sun, 11 Oct 2020 20:11:26 +0200 Subject: [PATCH 1/2] Add uid and gid as environment variable --- .circleci/config.yml | 5 ++++- .env | 2 ++ Dockerfile | 4 +++- docker-compose.yml | 4 ++++ 4 files changed, 13 insertions(+), 2 deletions(-) diff --git a/.circleci/config.yml b/.circleci/config.yml index 0661491e..2f0c21d9 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -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: @@ -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: | diff --git a/.env b/.env index 033b04cc..ac6892b1 100644 --- a/.env +++ b/.env @@ -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 diff --git a/Dockerfile b/Dockerfile index 2eea6695..d8accbfc 100644 --- a/Dockerfile +++ b/Dockerfile @@ -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 @@ -23,7 +25,7 @@ RUN poetry install --no-dev --no-interaction --no-ansi COPY . /src -RUN useradd --no-create-home --system -s /bin/false --uid 5000 uwsgi +RUN useradd --no-create-home --system -s /bin/false --uid $UID --gid $GID uwsgi RUN chown -R uwsgi /src diff --git a/docker-compose.yml b/docker-compose.yml index 42084958..efc13c1a 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -7,6 +7,10 @@ services: container_name: resources-api env_file: - .env + environment: + - UID=${UID} + - GID=${GID} + user: ${UID}:${GID} volumes: - .:/src ports: From abdb59fd688c30b8d625eb079cf57e8fb4c73c2b Mon Sep 17 00:00:00 2001 From: Enrico Paganin Date: Sun, 11 Oct 2020 20:20:12 +0200 Subject: [PATCH 2/2] Add uwsgi group in Dockerfile --- Dockerfile | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/Dockerfile b/Dockerfile index d8accbfc..fae22fea 100644 --- a/Dockerfile +++ b/Dockerfile @@ -25,7 +25,8 @@ RUN poetry install --no-dev --no-interaction --no-ansi COPY . /src -RUN useradd --no-create-home --system -s /bin/false --uid $UID --gid $GID uwsgi +RUN groupadd --gid $GID uwsgi \ + && useradd --no-create-home --system -s /bin/false --uid $UID --gid $GID uwsgi RUN chown -R uwsgi /src