Skip to content

Commit

Permalink
22303 auth api poetry upgrade (#2919)
Browse files Browse the repository at this point in the history
  • Loading branch information
avni-work authored Jul 19, 2024
1 parent 7076b5b commit 594e9c2
Show file tree
Hide file tree
Showing 10 changed files with 3,206 additions and 188 deletions.
70 changes: 56 additions & 14 deletions auth-api/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,33 +1,75 @@
FROM python:3.8.5-buster
FROM python:3.8.16-bullseye as development_build

ARG VCS_REF="missing"
ARG BUILD_DATE="missing"

ENV VCS_REF=${VCS_REF}
ENV BUILD_DATE=${BUILD_DATE}
ENV PORT=5001

LABEL org.label-schema.vcs-ref=${VCS_REF} \
org.label-schema.build-date=${BUILD_DATE}

USER root

# Create working directory
RUN mkdir /opt/app-root && chmod 755 /opt/app-root
WORKDIR /opt/app-root
LABEL maintainer="BCROS"
LABEL vendor="BCROS"

# Install the requirements
COPY ./requirements.txt .
ARG APP_ENV \
UID=1000 \
GID=1000

RUN pip install --upgrade pip
RUN pip install --no-cache-dir -r requirements.txt
ENV APP_ENV=${APP_ENV} \
PYTHONFAULTHANDLER=1 \
PYTHONUNBUFFERED=1 \
PYTHONHASHSEED=random \
PYTHONDONTWRITEBYTECODE=1 \
PIP_NO_CACHE_DIR=1 \
PIP_DISABLE_PIP_VERSION_CHECK=1 \
PIP_DEFAULT_TIMEOUT=100 \
PIP_ROOT_USER_ACTION=ignore \
POETRY_VERSION=1.8.3 \
POETRY_NO_INTERACTION=1 \
POETRY_VIRTUALENVS_CREATE=false \
POETRY_CACHE_DIR='/var/cache/pypoetry' \
POETRY_HOME='/usr/local'

COPY . .
SHELL ["/bin/bash", "-eo", "pipefail", "-c"]

RUN pip install .
RUN apt-get update && apt-get upgrade -y \
&& apt-get install --no-install-recommends -y \
bash \
build-essential \
curl \
git \
libpq-dev \
&& curl -sSL 'https://install.python-poetry.org' | python3 - \
&& poetry --version \
&& apt-get purge -y --auto-remove -o APT::AutoRemove::RecommendsImportant=false \
&& apt-get clean -y && rm -rf /var/lib/apt/lists/*

USER 1001
WORKDIR /code

# Set Python path
ENV PYTHONPATH=/opt/app-root/src
RUN groupadd -g "${GID}" -r web \
&& useradd -d '/code' -g web -l -r -u "${UID}" web \
&& chown web:web -R '/code'

ENTRYPOINT ["bash", "docker-entrypoint.sh"]
COPY --chown=web:web ./poetry.lock ./pyproject.toml /code/

COPY --chown=web:web ./src /code/src
COPY --chown=web:web ./README.md /code

RUN --mount=type=cache,target="$POETRY_CACHE_DIR" \
echo "$APP_ENV" \
&& poetry version \
&& poetry run pip install -U pip \
&& poetry install \
$(if [ -z ${APP_ENV+x} ] || [ "$APP_ENV" = 'production' ]; then echo '--only main'; fi) \
--no-interaction --no-ansi

USER web

FROM development_build AS production_build
COPY --chown=web:web . /code

CMD gunicorn --bind 0.0.0.0:${PORT} --config /code/gunicorn_config.py wsgi:app
37 changes: 12 additions & 25 deletions auth-api/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -42,44 +42,34 @@ clean-test: ## clean test files
rm -f .coverage
rm -fr htmlcov/

build-req: clean ## Upgrade requirements
test -f venv/bin/activate || python3 -m venv $(CURRENT_ABS_DIR)/venv ;\
. venv/bin/activate ;\
pip install --upgrade pip ;\
pip install -Ur requirements/prod.txt ;\
pip freeze | sort > requirements.txt ;\
cat requirements/repo-libraries.txt >> requirements.txt ;\
pip install -Ur requirements/repo-libraries.txt

install: clean ## Install python virtrual environment
test -f venv/bin/activate || python3 -m venv $(CURRENT_ABS_DIR)/venv ;\
. venv/bin/activate ;\
pip install --upgrade pip ;\
pip install -Ur requirements.txt
unset HOME ## unset HOME because it's in the DEV .env file, will cause permissions issues
pip install poetry ;\
poetry install

install-dev: ## Install local application
. venv/bin/activate ; \
pip install -Ur requirements/dev.txt; \
pip install -e .
install-dev: ## Instal development dependencies
poetry add --dev pylint astroid
poetry install --with dev

#################################################################################
# COMMANDS - CI #
#################################################################################
ci: lint flake8 test ## CI flow

pylint: ## Linting with pylint
. venv/bin/activate && pylint --rcfile=setup.cfg src/$(PROJECT_NAME)
poetry run pylint --rcfile=setup.cfg src/$(PROJECT_NAME)

flake8: ## Linting with flake8
. venv/bin/activate && flake8 src/$(PROJECT_NAME) tests
poetry run flake8 src/$(PROJECT_NAME) tests

lint: pylint flake8 ## run all lint type scripts

test: ## Unit testing
. venv/bin/activate && pytest
poetry run pytest

mac-cov: local-test ## Run the coverage report and display in a browser window (mac)
open -a "Google Chrome" htmlcov/index.html
@open -a "Google Chrome" htmlcov/index.html

#################################################################################
# COMMANDS - CD
Expand Down Expand Up @@ -135,11 +125,8 @@ tag: push ## tag image
#################################################################################
# COMMANDS - Local #
#################################################################################
run: db ## Run the project in local
. venv/bin/activate && python -m flask run -p 5000

db: ## Update the local database
. venv/bin/activate && python -m manage.py db upgrade
run: ## Run the project in local
poetry run flask run -p 5000

#################################################################################
# Self Documenting Commands #
Expand Down
4 changes: 0 additions & 4 deletions auth-api/docker-entrypoint.sh

This file was deleted.

Loading

0 comments on commit 594e9c2

Please sign in to comment.