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

Update project config #23

Merged
merged 6 commits into from
May 30, 2024
Merged
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
9 changes: 5 additions & 4 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
*
!app.py
!endpoints/
!requirements.txt
!tests/
!/endpoint/
!/endpoints/
!/requirements.txt
!/tests/
!/pyproject.toml
7 changes: 3 additions & 4 deletions .github/workflows/test-endpoint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -70,11 +70,10 @@ jobs:
env:
PYTEST_ADDOPTS: "--color=yes"
AUTH_TOKEN: "abcd1234"
KAFKA_HOST: "localhost"
KAFKA_PORT: 9092
KAFKA_BOOTSTRAP_SERVERS: "localhost:9092"
LOG_LEVEL: "DEBUG"
UVICORN_LOG_LEVEL: "debug"
ENDPOINT_CONFIG_URL: "tests/endpoint_config"
DEBUG: 1
run: |
uvicorn app:app --host 0.0.0.0 --port 8000 --proxy-headers &&
pytest -v tests/test_api.py
pytest
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -159,3 +159,6 @@ cython_debug/
# and can be added to the global gitignore or merged into this file. For a more nuclear
# option (not recommended) you can uncomment the following to ignore the entire idea folder.
.idea/

# Version file generated by setuptools-scm
_version.py
19 changes: 0 additions & 19 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,26 +5,7 @@ repos:
- id: check-yaml
- id: end-of-file-fixer
- id: trailing-whitespace
- repo: https://github.com/psf/black
rev: 23.12.0
hooks:
- id: black
- repo: https://github.com/charliermarsh/ruff-pre-commit
rev: 'v0.1.8'
hooks:
- id: ruff
- repo: https://github.com/jazzband/pip-tools
rev: 7.3.0
hooks:
- id: pip-compile
name: pip-compile requirements.txt
args: [--strip-extras, --output-file=requirements.txt]
files: ^(pyproject\.toml|requirements\.txt)$
- id: pip-compile
name: pip-compile requirements-test.txt
args: [--extra=test, --strip-extras, --output-file=requirements-test.txt]
files: ^(pyproject\.toml|requirements-test\.txt)$
- id: pip-compile
name: pip-compile requirements-dev.txt
args: [--extra=dev, --strip-extras, --output-file=requirements-dev.txt]
files: ^(pyproject\.toml|requirements-dev\.txt)$
43 changes: 29 additions & 14 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,31 +1,46 @@
# mittaridatapumppu-endpoint
# syntax=docker/dockerfile:1

FROM python:3.11-alpine
ARG PYTHON_VERSION="3.12"
ARG ALPINE_VERSION="3.19"

FROM python:${PYTHON_VERSION}-alpine${ALPINE_VERSION} as build

ENV PYTHONDONTWRITEBYTECODE 1
ENV PYTHONUNBUFFERED 1

RUN addgroup -S app && adduser -S app -G app
WORKDIR /home/app
ENV VIRTUAL_ENV=/opt/venv
ENV PATH="${VIRTUAL_ENV}/bin:$PATH"

# Install requirements to build aiokafka
RUN apk add --no-cache \
gcc \
python3-dev \
libc-dev \
zlib-dev
RUN --mount=type=cache,target=/var/cache/apk \
apk add gcc python3-dev libc-dev zlib-dev

# Copy and install requirements only first to cache the dependency layer
COPY --chown=app:app requirements.txt .
RUN pip install --no-cache-dir --no-compile --upgrade -r requirements.txt
RUN pip install uv

COPY pyproject.toml ./
RUN --mount=type=cache,target=/root/.cache/uv \
uv venv $VIRTUAL_ENV && \
uv pip install -r pyproject.toml

FROM python:3.12-alpine

ENV PYTHONDONTWRITEBYTECODE 1
ENV PYTHONUNBUFFERED 1
ENV VIRTUAL_ENV=/opt/venv
ENV PATH="${VIRTUAL_ENV}/bin:$PATH"

RUN addgroup -S app && adduser -S app -G app
WORKDIR /home/app

COPY --chown=app:app . .
COPY --from=build --chown=app:app $VIRTUAL_ENV $VIRTUAL_ENV
COPY --chown=app:app endpoint/ ./endpoint
COPY --chown=app:app endpoints/ ./endpoints

# Support Arbitrary User IDs
RUN chgrp -R 0 /home/app && \
chmod -R g+rwX /home/app

USER app

CMD ["uvicorn", "app:app", "--host", "0.0.0.0", "--port", "8000", "--proxy-headers"]
EXPOSE 8000/tcp
CMD ["uvicorn", "endpoint.endpoint:app", "--host", "0.0.0.0", "--port", "8000", "--proxy-headers"]
9 changes: 9 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1 +1,10 @@
# Mittaridatapumppu endpoint

```
pip install pip-tools pre-commit
. venv/bin/activate
pre-commit install
pip-sync requirements*.txt
uvicorn endpoint.endpoint:app --host 0.0.0.0 --port 8080 --proxy-headers
API_TOKEN=abcdef1234567890abcdef1234567890abcdef12 venv/bin/python tests/test_api2.py
```
Empty file added endpoint/__init__.py
Empty file.
Loading
Loading