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 dockerfile #18

Closed
wants to merge 4 commits into from
Closed
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
31 changes: 25 additions & 6 deletions .github/workflows/test-endpoint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,19 @@ jobs:
python-version: ["3.10", "3.11"]
services:
# Label used to access the service container
db:
# Docker Hub image
image: postgis/postgis:16-3.4-alpine
# Provide the password for postgres
env:
POSTGRES_PASSWORD: postgres
# Set health checks to wait until postgres has started
options: >-
--health-cmd pg_isready
--health-interval 10s
--health-timeout 5s
--health-retries 5
# Label used to access the service container
kafka:
# Docker Hub image
image: bitnami/kafka:3.4
Expand All @@ -48,6 +61,13 @@ jobs:
ports:
# Tests run directly on the runner so we have to map the port
- 9092:9092
deviceregistry:
image: ghcr.io/city-of-helsinki/mittaridatapumppu-deviceregistry:latest
env:
DJANGO_SETTINGS_MODULE: "deviceregistry.settings"
ports:
- 8001:8000
# TODO:run migrations here
steps:
- uses: actions/checkout@v3
- name: Set up Python ${{ matrix.python-version }}
Expand All @@ -68,13 +88,12 @@ jobs:
ruff check --output-format=github .
- name: Test with pytest
env:
PYTEST_ADDOPTS: "--color=yes"
AUTH_TOKEN: "abcd1234"
KAFKA_HOST: "localhost"
KAFKA_PORT: 9092
DEVREG_ENDPOINTS_URL: "http://localhost:8001/api/v1/hosts/localhost/"
DEVREG_API_TOKEN: "abcdef1234567890abcdef1234567890abcdef12"
# Kafka client config
KAFKA_BOOTSTRAP_SERVERS: "localhost:9092"
LOG_LEVEL: "DEBUG"
UVICORN_LOG_LEVEL: "DEBUG"
DEBUG: 1
run: |
uvicorn app:app --host 0.0.0.0 --port 8000 --proxy-headers &&
pytest -v tests/test_api.py
pytest
161 changes: 161 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,161 @@
# Byte-compiled / optimized / DLL files
__pycache__/
*.py[cod]
*$py.class

# C extensions
*.so

# Distribution / packaging
.Python
build/
develop-eggs/
dist/
downloads/
eggs/
.eggs/
lib/
lib64/
parts/
sdist/
var/
wheels/
share/python-wheels/
*.egg-info/
.installed.cfg
*.egg
MANIFEST

# PyInstaller
# Usually these files are written by a python script from a template
# before PyInstaller builds the exe, so as to inject date/other infos into it.
*.manifest
*.spec

# Installer logs
pip-log.txt
pip-delete-this-directory.txt

# Unit test / coverage reports
htmlcov/
.tox/
.nox/
.coverage
.coverage.*
.cache
nosetests.xml
coverage.xml
*.cover
*.py,cover
.hypothesis/
.pytest_cache/
cover/

# Translations
*.mo
*.pot

# Django stuff:
*.log
local_settings.py
db.sqlite3
db.sqlite3-journal

# Flask stuff:
instance/
.webassets-cache

# Scrapy stuff:
.scrapy

# Sphinx documentation
docs/_build/

# PyBuilder
.pybuilder/
target/

# Jupyter Notebook
.ipynb_checkpoints

# IPython
profile_default/
ipython_config.py

# pyenv
# For a library or package, you might want to ignore these files since the code is
# intended to run in multiple environments; otherwise, check them in:
# .python-version

# pipenv
# According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control.
# However, in case of collaboration, if having platform-specific dependencies or dependencies
# having no cross-platform support, pipenv may install dependencies that don't work, or not
# install all needed dependencies.
#Pipfile.lock

# poetry
# Similar to Pipfile.lock, it is generally recommended to include poetry.lock in version control.
# This is especially recommended for binary packages to ensure reproducibility, and is more
# commonly ignored for libraries.
# https://python-poetry.org/docs/basic-usage/#commit-your-poetrylock-file-to-version-control
#poetry.lock

# pdm
# Similar to Pipfile.lock, it is generally recommended to include pdm.lock in version control.
#pdm.lock
# pdm stores project-wide configurations in .pdm.toml, but it is recommended to not include it
# in version control.
# https://pdm.fming.dev/#use-with-ide
.pdm.toml

# PEP 582; used by e.g. github.com/David-OConnor/pyflow and github.com/pdm-project/pdm
__pypackages__/

# Celery stuff
celerybeat-schedule
celerybeat.pid

# SageMath parsed files
*.sage.py

# Environments
.env
.venv
env/
venv/
ENV/
env.bak/
venv.bak/
venv*/

# Spyder project settings
.spyderproject
.spyproject

# Rope project settings
.ropeproject

# mkdocs documentation
/site

# mypy
.mypy_cache/
.dmypy.json
dmypy.json

# Pyre type checker
.pyre/

# pytype static type analyzer
.pytype/

# Cython debug symbols
cython_debug/

# PyCharm
# JetBrains specific template is maintained in a separate JetBrains.gitignore that can
# be found at https://github.com/github/gitignore/blob/main/Global/JetBrains.gitignore
# 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/
11 changes: 11 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,20 @@

FROM python:3.11-alpine

LABEL org.opencontainers.image.source=https://github.com/city-of-helsinki/mittaridatapumppu
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is not correct anymore

LABEL org.opencontainers.image.description="Mittaridatapumppu Endpoint"
LABEL org.opencontainers.image.licenses="Apache License 2.0"

ENV PYTHONDONTWRITEBYTECODE 1
ENV PYTHONUNBUFFERED 1

# Device registry config
ENV DEVREG_ENDPOINTS_URL "http://devreg:8000/api/v1/hosts/localhost/"
ENV DEVREG_API_TOKEN "abcdef1234567890abcdef1234567890abcdef12"

# Kafka config
ENV KAFKA_BOOTSTRAP_SERVERS "kafka:9092"

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

Expand Down
18 changes: 5 additions & 13 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
version: '3.8'

services:
endpoint-digita:
endpoint:
image: ghcr.io/city-of-helsinki/mittaridatapumppu-endpoint
build: .
ports:
Expand All @@ -12,21 +12,13 @@ services:
kafka:
condition: service_healthy
environment:
# Endpoint config
ALLOWED_IP_ADDRESSES: "127.0.0.1"
AUTH_TOKEN: "abcd1234"
DATA_SOURCE_NAME: "digita.thingpark.http"
ENDPOINT_PATH: "/digita/v2"
HTTP_REQUESTHANDLER: "endpoints.digita.aiothingpark"
DEVREG_ENDPOINTS_URL: "http://devreg:8000/api/v1/hosts/localhost/"
DEVREG_API_TOKEN: "abcdef1234567890abcdef1234567890abcdef12"
# Kafka client config
KAFKA_HOST: "kafka"
KAFKA_PORT: 9092
KAFKA_BOOTSTRAP_SERVERS: "kafka:9092"
KAFKA_GROUP_ID: "digita_dev"
KAFKA_PARSED_DATA_TOPIC_NAME: "digita.parseddata"
KAFKA_RAW_DATA_TOPIC_NAME: "digita.rawdata"
# Debug config
LOG_LEVEL: "DEBUG"
UVICORN_LOG_LEVEL: "debug"
UVICORN_RELOAD: "true"
DEBUG: 1
kafka:
image: bitnami/kafka:3.4
Expand Down
17 changes: 7 additions & 10 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,10 +1,3 @@
[tool.setuptools]
py-modules = []

[build-system]
requires = ["setuptools"]
build-backend = "setuptools.build_meta"

[tool.ruff]
line-length = 120
target-version = "py311"
Expand All @@ -17,11 +10,9 @@ requires-python = ">=3.10"
dynamic = ["version"]

dependencies = [
"aiokafka",
"fastapi",
"fvhiot@https://github.com/ForumViriumHelsinki/FVHIoT-python/archive/refs/tags/v0.3.2.zip",
"fastapi",
"httpx",
"kafka-python",
"python-multipart",
"sentry-asgi",
"uvicorn",
Expand All @@ -46,3 +37,9 @@ test = [
"pytest",
"requests"
] #pip-compile --resolver=backtracking --extra test pyproject.toml

[tool.pytest.ini_options]
log_cli = 1
log_cli_level = 20
testpaths = ["tests"]
addopts = ["--color=yes"]
Loading
Loading