-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
10 changed files
with
301 additions
and
1,450 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 |
---|---|---|
|
@@ -19,7 +19,7 @@ Modelfile | |
|
||
# Docker | ||
docker-compose.yml | ||
Dockerfile | ||
Dockerfile* | ||
.docker | ||
.dockerignore | ||
|
||
|
This file was deleted.
Oops, something went wrong.
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 @@ | ||
3.12 |
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 |
---|---|---|
@@ -1,91 +1,70 @@ | ||
FROM python:3.12-slim AS python-base | ||
FROM python:3.12-slim AS builder | ||
|
||
ENV \ | ||
BASE_DIR=/app | ||
COPY --from=ghcr.io/astral-sh/uv:latest /uv /bin/uv | ||
|
||
WORKDIR $BASE_DIR | ||
ENV APP_DIR=/app | ||
|
||
ENV \ | ||
# OS | ||
PORT=8000 \ | ||
# uv | ||
UV_COMPILE_BYTECODE=1 \ | ||
UV_LINK_MODE=copy \ | ||
UV_PYTHON_DOWNLOADS=never \ | ||
UV_CACHE_DIR="$APP_DIR/.uv_cache" \ | ||
# Python | ||
PYTHONUNBUFFERED=1 \ | ||
PYTHONDONTWRITEBYTECODE=1 \ | ||
PYTHONIOENCODING=utf-8 \ | ||
LANG=en_US.UTF-8 \ | ||
LANGUAGE=en_US.UTF-8 \ | ||
# LC_ALL=en_US.UTF-8 \ | ||
# pip | ||
PIP_DISABLE_PIP_VERSION_CHECK=on \ | ||
# poetry | ||
POETRY_HOME="$BASE_DIR/poetry" \ | ||
POETRY_NO_INTERACTION=1 \ | ||
POETRY_VIRTUALENVS_CREATE=false \ | ||
# venv and requirements path | ||
VIRTUAL_ENV="$BASE_DIR/venv" \ | ||
# cache path is HOME/.cache | ||
CACHE_PATH="/root/.cache" | ||
|
||
ENV PATH="$POETRY_HOME/bin:$VIRTUAL_ENV/bin:$PATH" | ||
|
||
RUN python -m venv $VIRTUAL_ENV | ||
|
||
ENV PYTHONPATH="$BASE_DIR:$PYTHONPATH" | ||
|
||
|
||
FROM python-base AS builder-base | ||
|
||
RUN apt-get update && \ | ||
apt-get install -y curl | ||
|
||
RUN --mount=type=cache,target=$CACHE_PATH \ | ||
curl -sSL https://install.python-poetry.org | python - | ||
|
||
WORKDIR $BASE_DIR | ||
|
||
COPY poetry.lock pyproject.toml ./ | ||
|
||
RUN --mount=type=cache,target=$CACHE_PATH \ | ||
poetry install --no-root --only main --compile | ||
VIRTUAL_ENV="$APP_DIR/.venv" \ | ||
PYTHONPATH="$APP_DIR/apps:$PYTHONPATH" | ||
|
||
WORKDIR $APP_DIR | ||
|
||
FROM builder-base AS development | ||
# Cache and bind mounts for uv | ||
RUN \ | ||
--mount=type=cache,target=$UV_CACHE_DIR \ | ||
--mount=type=bind,source=uv.lock,target=uv.lock \ | ||
--mount=type=bind,source=pyproject.toml,target=pyproject.toml \ | ||
uv sync --frozen --no-install-project --no-dev | ||
|
||
WORKDIR $BASE_DIR | ||
ADD . . | ||
|
||
RUN --mount=type=cache,target=$CACHE_PATH \ | ||
poetry install --no-root --compile | ||
# Cache mount again for uv sync | ||
RUN \ | ||
--mount=type=cache,target=$UV_CACHE_DIR \ | ||
uv sync --frozen --no-dev | ||
|
||
CMD ["bash"] | ||
|
||
FROM builder AS development | ||
|
||
FROM python-base AS production | ||
ENV PATH="$VIRTUAL_ENV/bin:$PATH" | ||
|
||
COPY --from=builder-base $POETRY_HOME $POETRY_HOME | ||
COPY --from=builder-base $VIRTUAL_ENV $VIRTUAL_ENV | ||
COPY --from=builder $APP_DIR $APP_DIR | ||
|
||
RUN \ | ||
apt-get update \ | ||
&& apt-get install -y --no-install-recommends curl \ | ||
&& apt-get clean \ | ||
&& rm -rf /var/lib/apt/lists/* | ||
EXPOSE $PORT | ||
|
||
WORKDIR $BASE_DIR | ||
VOLUME /data | ||
|
||
COPY . ./ | ||
FROM development AS production | ||
|
||
RUN chmod +x ./*.sh | ||
ENV USERNAME=nonroot | ||
|
||
VOLUME /data | ||
RUN useradd -ms /bin/bash $USERNAME | ||
|
||
ENV \ | ||
PYTHONPATH="$BASE_DIR/apps:$PYTHONPATH" \ | ||
PORT=8000 \ | ||
PYTHONIOENCODING=utf-8 \ | ||
LC_ALL=en_US.UTF-8 \ | ||
LANG=en_US.UTF-8 \ | ||
LANGUAGE=en_US.UTF-8 | ||
USER $USERNAME | ||
|
||
EXPOSE $PORT | ||
COPY --from=development --chown=$USERNAME:$USERNAME $APP_DIR $APP_DIR | ||
|
||
HEALTHCHECK --interval=10s --timeout=5s --start-period=10s --retries=5 \ | ||
CMD curl localhost:${PORT}/health || exit 1 | ||
HEALTHCHECK \ | ||
--interval=10s --timeout=5s --start-period=10s --retries=5 \ | ||
CMD curl localhost:${PORT}/health || exit 1 | ||
|
||
CMD ["./entrypoint.sh"] |
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 was deleted.
Oops, something went wrong.
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 |
---|---|---|
@@ -1,22 +1,19 @@ | ||
[tool.poetry] | ||
[project] | ||
name = "import-tax-calc" | ||
version = "0.1.0" | ||
description = "Import Tax Calculator for Ukraine" | ||
authors = ["Alexey ALERT Rubasheff <[email protected]>"] | ||
readme = "README.md" | ||
requires-python = ">=3.12" | ||
dependencies = [ | ||
"django>=5.1.1", | ||
"django-cors-headers>=4.4.0", | ||
"djangorestframework>=3.15.2", | ||
"gunicorn>=23.0.0", | ||
"psycopg[binary,pool]>=3.2.3", | ||
] | ||
|
||
[tool.poetry.dependencies] | ||
python = "^3.12" | ||
django = "^5.1.1" | ||
psycopg = {version = "^3.2.1", extras = ["binary", "pool"]} | ||
gunicorn = "^23.0.0" | ||
django-cors-headers = "^4.4.0" | ||
djangorestframework = "^3.15.2" | ||
|
||
[tool.poetry.group.dev.dependencies] | ||
poetry = "^1.8.3" | ||
pytest = "^8.3.2" | ||
|
||
[build-system] | ||
requires = ["poetry-core"] | ||
build-backend = "poetry.core.masonry.api" | ||
[tool.uv] | ||
dev-dependencies = [ | ||
"pytest>=8.3.3", | ||
] |
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,12 @@ | ||
|
||
@if not defined DOCKER_HOST set DOCKER_HOST=tcp://docker:2375 | ||
@if not defined STAGE set STAGE=production | ||
@if not defined CONTAINER_NAME set CONTAINER_NAME=test | ||
@if not defined DOCKERFILENAME set DOCKERFILENAME=Dockerfile | ||
|
||
docker kill %CONTAINER_NAME% | ||
docker rm %CONTAINER_NAME% | ||
docker build -f %DOCKERFILENAME% --target %STAGE% -t %CONTAINER_NAME%:latest . || exit /b 1 | ||
docker run -p "8000:8000/tcp" -e ALLOWED_HOSTS=gitlab --name %CONTAINER_NAME% -t -d %CONTAINER_NAME% || exit /b 1 | ||
where nircmd >nul 2>nul && nircmd beep 500 500 | ||
docker exec -it %CONTAINER_NAME% bash |
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
Oops, something went wrong.