Skip to content

Commit

Permalink
Merge pull request #6 from koldakov/fix/poetry-docker-deployment
Browse files Browse the repository at this point in the history
Fix/poetry docker deployment
  • Loading branch information
koldakov authored Jun 10, 2024
2 parents 0e01137 + 54fa7f5 commit c49632e
Show file tree
Hide file tree
Showing 119 changed files with 5,081 additions and 3,031 deletions.
Empty file removed .dockerignore
Empty file.
7 changes: 3 additions & 4 deletions .github/workflows/python-app.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,10 @@ jobs:
- name: Install dependencies
run: |
python -m pip install --upgrade pip
python -m pip install ruff pytest
python -m pip install -r requirements.txt
make install-dev
- name: Code style
run: |
pre-commit run --all-files
poetry run pre-commit run --all-files
- name: Pytest
run: |
make tests
make test
5 changes: 3 additions & 2 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,14 @@ repos:
rev: v4.5.0
hooks:
- id: check-added-large-files
args: ["--maxkb=700"]
- id: check-yaml
- id: check-toml
- id: check-json
- id: check-symlinks

- repo: https://github.com/astral-sh/ruff-pre-commit
rev: v0.1.7
rev: v0.4.2
hooks:
- id: ruff
- id: ruff-format
Expand All @@ -27,7 +28,7 @@ repos:
- manual

- repo: https://github.com/pre-commit/mirrors-mypy
rev: v1.7.1
rev: v1.10.0
hooks:
- id: mypy
pass_filenames: false
Expand Down
32 changes: 32 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
# Changelog

All notable changes to this project will be documented in this file.

This project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## [1.0.0] - 2024-06-01

### Added

- API: Character selection by id
- API: Paginated characters selection by gender, status, species, order by, order by direction
- API: Character search by name
- API: Episode selection by id
- API: Paginated episodes selection
- API: Season selection by id
- API: Paginated seasons selection
- API: Callbacks for characters, episodes, seasons
- API: Server Sent Events (SSE) for characters
- API: User registration
- API: User authorization
- API: User activation
- API: User confirmation resend message
- API: User information update
- GraphQL: Character selection by id
- GraphQL: Paginated (Edged) characters selection by gender, status, species, order by, order by direction
- GraphQL: Episode selection by id
- GraphQL: Paginated (Edged) episodes selection
- GraphQL: Season selection by id
- GraphQL: Paginated (Edged) seasons selection

[1.0.0]: https://github.com/koldakov/futuramaapi/releases/tag/1.0.0
62 changes: 36 additions & 26 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,46 +1,56 @@
FROM python:3.12.0-slim-bullseye
FROM python:3.12.0-slim-bullseye as python-base

# Environ
ENV PYTHONUNBUFFERED=1
ENV PYTHONDONTWRITEBYTECODE=1
ENV VIRTUAL_ENV=/opt/venv
ENV PATH="$VIRTUAL_ENV/bin:$PATH"
ENV PYTHONUNBUFFERED=1 \
PYTHONDONTWRITEBYTECODE=1 \
PATH="${PATH}:/root/.local/bin" \
POETRY_HOME=/opt/poetry \
POETRY_VENV=/opt/poetry-venv \
POETRY_CACHE_DIR=/opt/.cache

RUN curl -sSL https://install.python-poetry.org | python3 -

# Arguments
ARG APP_USER=qworpa
ARG APP_USER=userapp
ARG WORK_DIR=/app

# Install OS dependencies
COPY install-dependencies.sh /tmp
RUN . /tmp/install-dependencies.sh
# Install dependencies
RUN apt-get update
RUN apt-get -y install make

# Install python environ
RUN python3 -m venv $VIRTUAL_ENV
COPY requirements.txt /tmp
RUN pip install --upgrade pip
RUN pip install --no-cache-dir -r /tmp/requirements.txt
# Create stage for Poetry installation
FROM python-base as poetry-base

# Add user
RUN groupadd \
--system ${APP_USER} \
&& useradd --no-log-init --system --gid ${APP_USER} ${APP_USER}
# Creating a virtual environment just for poetry and install it with pip
RUN python3 -m venv $POETRY_VENV \
&& $POETRY_VENV/bin/pip install poetry

# Create a new stage from the base python image
FROM python-base as example-app

# Copy project files to the work dir
COPY ./ ${WORK_DIR}
# Copy Poetry to app image
COPY --from=poetry-base ${POETRY_VENV} ${POETRY_VENV}

# Set owner to the project
RUN chown -R ${APP_USER}:${APP_USER} ${WORK_DIR}
# Add Poetry to PATH
ENV PATH="${PATH}:${POETRY_VENV}/bin"

# Set work dir
WORKDIR ${WORK_DIR}

# Copy Dependencies
COPY . ${WORK_DIR}

# Install Dependencies
RUN poetry install --no-interaction --no-cache --without dev --without test

EXPOSE 8000

# Add user
RUN groupadd \
--system ${APP_USER} \
&& useradd --no-log-init --system --gid ${APP_USER} ${APP_USER}

# Set project user
USER ${APP_USER}:${APP_USER}

# Compile messages
RUN cd ${WORK_DIR}; make messages-compile

# Main launch command
CMD ["./docker-entrypoint.sh"]
33 changes: 12 additions & 21 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,28 +1,19 @@
SHELL = /bin/bash
PYTHON = python3.12

help: # Display this message
@sed -ne '/@sed/!s/# //p' $(MAKEFILE_LIST)

messages-init: # locale=LANG, init LANG language
@test $${locale?Please specify locale. Example \"locale=en_CA\"}
@pybabel init -l $(locale) -i locale/messages.pot -d locale
install-dev: # Install DEV/TEST Environ and dependencies
@echo "Upgrading pip"
@$(PYTHON) -m pip install --upgrade pip
@echo "Installing poetry"
@$(PYTHON) -m pip install poetry
@echo "Installing dependencies"
@poetry install

messages-extract: # Extract messages to locale/messages.pot
@pybabel extract \
--version=0.0.1 \
[email protected] \
--project=FuturamaAPI \
--copyright-holder=FuturamaAPI \
--mapping babel.cfg \
--output-file=locale/messages.pot \
.
test: # Run tests
@poetry run $(PYTHON) -m pytest

messages: # Update all locales
@$(MAKE) messages-extract
@pybabel update --input-file=locale/messages.pot --output-dir=locale

messages-compile: # Generate .mo files for all locales
@pybabel compile --directory=locale

tests: # Run tests
@python -m pytest
migrate: # Migrate
@poetry run $(PYTHON) -m alembic upgrade head
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -58,8 +58,8 @@ If you create models in a new file please import it in env.py.
Because alembic does not detect child classes.

```commandline
alembic revision --autogenerate -m "Revision Name"
alembic upgrade head
poetry run alembic revision --autogenerate -m "Revision Name"
poetry run alembic upgrade head
```

<p align="right">(<a href="#top">back to top</a>)</p>
Expand All @@ -72,7 +72,7 @@ export $(cat .env | xargs)
# Compile tranlations
make messages-compile
# Run hypercorn server
hypercorn --reload app.main:app
hypercorn --reload futuramaapi.main:app
```

<p align="right">(<a href="#top">back to top</a>)</p>
Expand Down
2 changes: 1 addition & 1 deletion alembic.ini
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

[alembic]
# path to migration scripts
script_location = alembic
script_location = futuramaapi/repositories/migrations

# template used to generate migration file names; The default value is %%(rev)s_%%(slug)s
# Uncomment the line below if you want the files to be prepended with date and time
Expand Down
6 changes: 0 additions & 6 deletions app/core/__init__.py

This file was deleted.

7 changes: 0 additions & 7 deletions app/graph_ql/routers.py

This file was deleted.

Loading

0 comments on commit c49632e

Please sign in to comment.