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

feat: Migrate to poetry #2214

Merged
merged 21 commits into from
Aug 7, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
21 commits
Select commit Hold shift + click to select a range
952b964
feat: Migrate to poetry
tushar5526 May 17, 2023
d8e0548
fix: Add missing dependencies in pyproject.toml
tushar5526 May 17, 2023
c6fc26d
feat: Migrate redhat dockerfile
tushar5526 May 17, 2023
65b423f
Update api/pyproject.toml
tushar5526 May 18, 2023
fefddfd
fix: Pin poetry version and update Makefile
tushar5526 May 19, 2023
d3a3ceb
fix: Update pyproject.toml for project description
tushar5526 May 19, 2023
042893b
feat: Fix main dependencies
tushar5526 May 19, 2023
7460e80
feat: fix dev dependencies
tushar5526 May 19, 2023
31e3177
fix: Add poetry version to build-system
tushar5526 May 19, 2023
c0d49d0
fix: Fix dockerfile for older docker versions
tushar5526 May 22, 2023
af4af84
Refactor Makefile and Dockerfile
tushar5526 Jun 16, 2023
84806f8
remove piplist
tushar5526 Jun 16, 2023
6a555b9
feat: Update redhat dockerfile. Add generate requirements file target…
tushar5526 Jun 20, 2023
cb02819
fix: Generate requirements.txt and then install
tushar5526 Jun 20, 2023
38c0e1f
fix: Use venv created by poetry for make commands
tushar5526 Jul 1, 2023
b20e9a9
fix: Add missing dependencies after rebase
tushar5526 Jul 2, 2023
3586c62
fix: update dependencies
tushar5526 Jul 3, 2023
5e06184
fix: typo in Makefile and fix version for pyotp
tushar5526 Jul 4, 2023
26ddb4e
fix: use tilde requirements and remove pyotp as base dependency
tushar5526 Jul 13, 2023
0e5e28b
Merge remote-tracking branch 'upstream/main' into poetry-migrate
tushar5526 Aug 3, 2023
4fac674
feat: add pytest-cov to dev dependencies
tushar5526 Aug 3, 2023
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
29 changes: 10 additions & 19 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -10,33 +10,21 @@ ENV ENV=prod
ENV STATIC_ASSET_CDN_URL=/static/
RUN cd frontend && npm run bundledjango


# Step 2 - Build Python virtualenv
FROM python:3.11 as build-python
WORKDIR /app

RUN apt-get update && apt-get install -y gcc build-essential libpq-dev musl-dev python3-dev

# Set up venv
RUN python -m venv /opt/venv
# Make sure we use the virtualenv:
ENV PATH="/opt/venv/bin:$PATH"

COPY api/requirements.txt .
COPY api/pyproject.toml api/poetry.lock api/Makefile ./
ARG POETRY_VIRTUALENVS_CREATE=false
RUN make install-poetry
ENV PATH="$PATH:/root/.local/bin"

# Make sure we are running latest pip and setuptools to avoid potential security warnings
RUN pip install --upgrade pip
RUN pip install --upgrade setuptools

# Install our python dependencies
RUN make generate-requirements-file opts="main"
RUN pip install -r requirements.txt


# Step 3 - Build Django Application
FROM python:3.11-slim as application

WORKDIR /app
COPY api /app/

# Install SAML dependency if required
ARG SAML_INSTALLED="0"
Expand All @@ -47,8 +35,11 @@ ARG TARGETARCH
RUN if [ "${TARGETARCH}" != "amd64" ]; then apt-get update && apt-get install -y libpq-dev && rm -rf /var/lib/apt/lists/*; fi;

# Copy the python venv from step 2
COPY --from=build-python /opt/venv /opt/venv
ENV PATH="/opt/venv/bin:$PATH"
COPY --from=build-python /usr/local/lib/python3.11/site-packages /usr/local/lib/python3.11/site-packages
# Copy the bin folder as well to copy the executables created in package installation
COPY --from=build-python /usr/local/bin /usr/local/bin

COPY api /app/

# Compile static Django assets
RUN python /app/manage.py collectstatic --no-input
Expand Down
28 changes: 11 additions & 17 deletions api/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,29 +1,20 @@

# Step 1 - Build Python virtualenv
FROM python:3.11 as build-python
WORKDIR /app

RUN apt-get update && apt-get install -y gcc build-essential libpq-dev musl-dev python3-dev

# Set up venv
RUN python -m venv /opt/venv
# Make sure we use the virtualenv:
ENV PATH="/opt/venv/bin:$PATH"
COPY pyproject.toml poetry.lock Makefile ./

COPY requirements.txt .
ARG POETRY_VIRTUALENVS_CREATE=false
RUN make install-poetry
ENV PATH="$PATH:/root/.local/bin"

# Make sure we are running latest pip and setuptools to avoid potential security warnings
RUN pip install --upgrade pip
RUN pip install --upgrade setuptools

# Install our python dependencies
RUN make generate-requirements-file opts="main"
RUN pip install -r requirements.txt


# Step 2 - Build Django Application
FROM python:3.11-slim as application

WORKDIR /app
COPY . .

# Install SAML dependency if required
ARG SAML_INSTALLED="0"
Expand All @@ -34,8 +25,11 @@ ARG TARGETARCH
RUN if [ "${TARGETARCH}" != "amd64" ]; then apt-get update && apt-get install -y libpq-dev && rm -rf /var/lib/apt/lists/*; fi;

# Copy the python venv from step 2
COPY --from=build-python /opt/venv /opt/venv
ENV PATH="/opt/venv/bin:$PATH"
COPY --from=build-python /usr/local/lib/python3.11/site-packages /usr/local/lib/python3.11/site-packages
# Copy the bin folder as well to copy the executables created in package installation
COPY --from=build-python /usr/local/bin /usr/local/bin

COPY . .

# Compile static Django assets
RUN python manage.py collectstatic --no-input
Expand Down
7 changes: 6 additions & 1 deletion api/Dockerfile.redhat-ubi
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,13 @@ USER root
RUN yum -y update-minimal --security --sec-severity=Important --sec-severity=Critical
USER 1001

ADD --chown=1001:0 requirements.txt .
ARG POETRY_VIRTUALENVS_CREATE=false
ADD --chown=1001:0 pyproject.toml poetry.lock Makefile .
RUN make generate-requirements-file opts="main"
RUN pip install -r requirements.txt
ENV PATH="$PATH:/root/.local/bin"
RUN make install-packages opts="--no-root --only main"

ADD --chown=1001:0 docker/ bin/
ADD --chown=1001:0 . src/

Expand Down
34 changes: 22 additions & 12 deletions api/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -7,31 +7,41 @@ COMPOSE_PROJECT_NAME ?= flagsmith

DOTENV_OVERRIDE_FILE ?= .env

POETRY_VERSION ?= 1.5.0

-include .env-local
-include $(DOTENV_OVERRIDE_FILE)

.PHONY: install-pip
install-pip:
python -m pip install --upgrade pip

.PHONY: install-poetry
install-poetry:
curl -sSL https://install.python-poetry.org | python3 - --version ${POETRY_VERSION}

.PHONY: install-packages
install-packages:
pip install -r requirements-all.txt
poetry install $(opts)

.PHONY: install
install: install-pip install-packages
install: install-pip install-poetry install-packages

.PHONY: generate-requirements-file
generate-requirements-file:
poetry export -f requirements.txt --output requirements.txt --only $(opts)

.PHONY: lint-black
lint-black:
black --check .
poetry run black --check .

.PHONY: lint-isort
lint-isort:
isort --check-only --diff .
poetry run isort --check-only --diff .

.PHONY: lint-flake8
lint-flake8:
flake8
poetry run flake8

.PHONY: lint
lint: lint-black lint-isort lint-flake8
Expand All @@ -58,22 +68,22 @@ docker-build:

.PHONY: test
test:
pytest $(opts)
poetry run pytest $(opts)

.PHONY: django-make-migrations
django-make-migrations:
python manage.py waitfordb
python manage.py makemigrations $(opts)
poetry run python manage.py waitfordb
poetry run python manage.py makemigrations $(opts)

.PHONY: django-migrate
django-migrate:
python manage.py waitfordb
python manage.py migrate
poetry run python manage.py waitfordb
poetry run python manage.py migrate

.PHONY: django-collect-static
django-collect-static:
python manage.py collectstatic --noinput
poetry run python manage.py collectstatic --noinput

.PHONY: serve
serve:
gunicorn --bind 0.0.0.0:8000 app.wsgi --reload
poetry run gunicorn --bind 0.0.0.0:8000 app.wsgi --reload
Loading