-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #57 from codeforjapan/chore/issue-54-dockerize-api
APIのDocker化
- Loading branch information
Showing
12 changed files
with
241 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
tests |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
ARG PYTHON_VERSION_CODE=3.10 | ||
ARG ENVIRONMENT="dev" | ||
# ENVIRONMENT: dev or prod, refer to project.optional-dependencies in pyproject.toml | ||
|
||
FROM python:${PYTHON_VERSION_CODE}-bookworm as builder | ||
ARG PYTHON_VERSION_CODE | ||
ARG ENVIRONMENT | ||
|
||
WORKDIR /app | ||
ENV PYTHONDONTWRITEBYTECODE=1 \ | ||
PYTHONUNBUFFERED=1 | ||
|
||
COPY pyproject.toml README.md ./ | ||
COPY birdxplorer_api/__init__.py ./birdxplorer_api/ | ||
|
||
RUN if [ "${ENVIRONMENT}" = "prod" ]; then \ | ||
apt-get update && apt-get install -y --no-install-recommends \ | ||
postgresql-client-15 \ | ||
&& apt-get clean \ | ||
&& rm -rf /var/lib/apt/lists/*; \ | ||
fi | ||
RUN pip install --no-cache-dir -e ".[${ENVIRONMENT}]" | ||
|
||
FROM python:${PYTHON_VERSION_CODE}-slim-bookworm as runner | ||
ARG PYTHON_VERSION_CODE | ||
ARG ENVIRONMENT | ||
|
||
WORKDIR /app | ||
|
||
RUN if [ "${ENVIRONMENT}" = "prod" ]; then \ | ||
apt-get update && apt-get install -y --no-install-recommends \ | ||
libpq5 \ | ||
&& apt-get clean \ | ||
&& rm -rf /var/lib/apt/lists/*; \ | ||
fi | ||
|
||
RUN groupadd -r app && useradd -r -g app app | ||
RUN chown -R app:app /app | ||
USER app | ||
|
||
COPY --from=builder /usr/local/lib/python${PYTHON_VERSION_CODE}/site-packages /usr/local/lib/python${PYTHON_VERSION_CODE}/site-packages | ||
COPY --chown=app:app . ./ | ||
|
||
ENTRYPOINT ["python", "-m", "uvicorn", "birdxplorer_api.main:app", "--host", "0.0.0.0"] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
|
||
# BirdXplorer API |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
ARG PYTHON_VERSION_CODE=3.10 | ||
ARG ENVIRONMENT="dev" | ||
# ENVIRONMENT: dev or prod, refer to project.optional-dependencies in pyproject.toml | ||
|
||
FROM python:${PYTHON_VERSION_CODE}-bookworm as builder | ||
ARG PYTHON_VERSION_CODE | ||
ARG ENVIRONMENT | ||
|
||
WORKDIR /app | ||
ENV PYTHONDONTWRITEBYTECODE=1 \ | ||
PYTHONUNBUFFERED=1 | ||
|
||
COPY pyproject.toml README.md ./ | ||
COPY birdxplorer_migration/__init__.py ./birdxplorer_migration/ | ||
|
||
RUN if [ "${ENVIRONMENT}" = "prod" ]; then \ | ||
apt-get update && apt-get install -y --no-install-recommends \ | ||
postgresql-client-15 \ | ||
&& apt-get clean \ | ||
&& rm -rf /var/lib/apt/lists/*; \ | ||
fi | ||
|
||
RUN pip install --no-cache-dir -e ".[${ENVIRONMENT}]" | ||
|
||
FROM python:${PYTHON_VERSION_CODE}-slim-bookworm as runner | ||
ARG PYTHON_VERSION_CODE | ||
ARG ENVIRONMENT | ||
|
||
WORKDIR /app | ||
|
||
RUN if [ "${ENVIRONMENT}" = "prod" ]; then \ | ||
apt-get update && apt-get install -y --no-install-recommends \ | ||
libpq5 \ | ||
&& apt-get clean \ | ||
&& rm -rf /var/lib/apt/lists/*; \ | ||
fi | ||
|
||
RUN groupadd -r app && useradd -r -g app app | ||
RUN chown -R app:app /app | ||
USER app | ||
|
||
COPY --from=builder /usr/local/lib/python${PYTHON_VERSION_CODE}/site-packages /usr/local/lib/python${PYTHON_VERSION_CODE}/site-packages | ||
COPY --chown=app:app . ./ | ||
|
||
ENTRYPOINT ["python", "birdxplorer_migration/scripts/migrate_all.py", "birdxplorer_migration/data/appv1/"] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
|
||
# BirdXplorer Migrations |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
__version__ = "0.0.1" |
File renamed without changes.
File renamed without changes.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,104 @@ | ||
[build-system] | ||
build-backend = "flit_core.buildapi" | ||
requires = ["flit_core >=3.8.0,<4"] | ||
|
||
|
||
[project] | ||
name = "birdxplorer_migration" | ||
description = "The Migration Scripts for BirdXplorer project." | ||
authors = [ | ||
{name = "osoken"}, | ||
] | ||
dynamic = [ | ||
"version", | ||
] | ||
readme = "README.md" | ||
license = {file = "../LICENSE"} | ||
requires-python = ">=3.10" | ||
|
||
classifiers = [ | ||
"Development Status :: 3 - Alpha", | ||
"Natural Language :: Japanese", | ||
"Operating System :: OS Independent", | ||
"Programming Language :: Python", | ||
"Programming Language :: Python :: 3.10", | ||
] | ||
|
||
dependencies = [ | ||
"birdxplorer_common @ git+https://github.com/codeforjapan/BirdXplorer.git@feature/issue-53-divide-python-packages#subdirectory=common", | ||
"sqlalchemy", | ||
"python-dotenv", | ||
] | ||
|
||
[project.urls] | ||
Source = "https://github.com/codeforjapan/BirdXplorer" | ||
|
||
[tool.setuptools] | ||
packages=["birdxplorer"] | ||
|
||
[tool.setuptools.package-data] | ||
birdxplorer = ["py.typed"] | ||
|
||
[project.optional-dependencies] | ||
dev=[ | ||
"black", | ||
"flake8", | ||
"pyproject-flake8", | ||
"pytest", | ||
"mypy", | ||
"tox", | ||
"isort", | ||
"pytest-mock", | ||
"pytest-cov", | ||
"freezegun", | ||
"types-python-dateutil", | ||
"psycopg2-binary", | ||
"factory_boy", | ||
"uvicorn", | ||
"polyfactory", | ||
"httpx", | ||
] | ||
prod=[ | ||
"psycopg2" | ||
] | ||
|
||
[tool.black] | ||
line-length = 120 | ||
target-version = ['py310'] | ||
|
||
[tool.flake8] | ||
max-line-length = 120 | ||
extend-ignore = "E203,E701" | ||
|
||
[tool.mypy] | ||
python_version = "3.10" | ||
warn_return_any = true | ||
warn_unused_configs = true | ||
plugins = ["pydantic.mypy"] | ||
|
||
[tool.pydantic.mypy] | ||
init_typed = true | ||
|
||
[tool.isort] | ||
profile = "black" | ||
known_first_party = "birdxplorer_api,birdxplorer_common,birdxplorer_etl" | ||
|
||
[tool.tox] | ||
legacy_tox_ini = """ | ||
[tox] | ||
skipsdist = true | ||
envlist = py310 | ||
[testenv] | ||
setenv = | ||
VIRTUALENV_PIP = 24.0 | ||
deps = | ||
-e .[dev] | ||
commands = | ||
black birdxplorer_api tests | ||
isort birdxplorer_api tests | ||
pytest | ||
pflake8 birdxplorer_api/ tests/ | ||
mypy birdxplorer_api --strict | ||
mypy tests --strict | ||
""" |