diff --git a/.dockerignore b/.dockerignore index 8f1b5cda..a5a3c59e 100644 --- a/.dockerignore +++ b/.dockerignore @@ -1,9 +1,22 @@ +# cache and dot files .eggs/ -./deployment/containers/ .venv/ .mypy_cache/ .pytest_cache/ .coverage/ .ruff/ .ruff_cache/ -.eggs/ \ No newline at end of file +.eggs/ +.github/ +.gitignore +# Docs and atifacts +./deployment +./docs +/images +# build +./build +./dist +# Scripts and tools +./scripts +Makefile +PULL_REQUEST_TEMPLATE.md \ No newline at end of file diff --git a/Makefile b/Makefile index 9f3c0a10..f8c6867c 100644 --- a/Makefile +++ b/Makefile @@ -84,12 +84,29 @@ install: @if [ -x "$(POETRY_CMD)" ]; then \ poetry install; \ else \ - echo "🔏 Install poetry."; \ + echo "🔏 Consider installing poetry to leverage poetry.lock."; \ + echo "⬇️ Typing to installing with pip."; \ + if [ -f .venv/bin/pip ]; then \ + .venv/bin/pip install .; \ + else \ + echo "⬇️ Install dependencies, create virtual environment using 'make v'."; \ + fi; \ fi .PHONY: i i: install +.PHONY: wheel +wheel: + @if [ -x "$(POETRY_CMD)" ]; then \ + poetry build -f wheel; \ + else \ + echo "🔏 Poetry needed to build wheel."; \ + fi + +.PHONY: w +w: wheel + .PHONY: format-lint format-lint: @if [ -f .venv/bin/ruff ]; then \ diff --git a/deployment/containers/filer.Dockerfile b/deployment/containers/filer.Dockerfile index c9685121..a70e6ee2 100644 --- a/deployment/containers/filer.Dockerfile +++ b/deployment/containers/filer.Dockerfile @@ -1,25 +1,39 @@ -# Builder: produce wheels +################################################### +# Stage 1: Build wheel # +################################################### +FROM python:3.11-alpine AS builder -FROM alpine:3.10 as builder +# Set work directory +WORKDIR /app -RUN apk add --no-cache python3 -RUN apk add --no-cache git -RUN python3 -m pip install --upgrade setuptools pip wheel +# Install poetry +RUN pip install poetry -WORKDIR /app/ +# Copy source code COPY . . -RUN python3 setup.py bdist_wheel +# Build wheel +RUN poetry build -f wheel -# Install: copy tesk-core*.whl and install it with dependencies +################################################### +# Stage 2: Install wheel and create user # +################################################### +FROM python:3.11-alpine AS runner -FROM alpine:3.10 +# Copy built wheel from the builder stage +COPY --from=builder /app/dist/*.whl /dist/ -RUN apk add --no-cache python3 +# Install the application with dependencies +RUN pip install /dist/*.whl -COPY --from=builder /app/dist/tesk*.whl /root/ -RUN python3 -m pip install --disable-pip-version-check --no-cache-dir /root/tesk*.whl +# Create a non-root user +RUN adduser -D -u 1000 filerUser -USER 100 +# Switch to the non-root user +USER filerUser +# Set the working directory +WORKDIR /app + +# Entrypoint command ENTRYPOINT ["filer"] diff --git a/deployment/containers/taskmaster.Dockerfile b/deployment/containers/taskmaster.Dockerfile index 5e5418d3..fb06408b 100644 --- a/deployment/containers/taskmaster.Dockerfile +++ b/deployment/containers/taskmaster.Dockerfile @@ -1,26 +1,39 @@ -# Builder: produce wheels +################################################### +# Stage 1: Build wheel # +################################################### +FROM python:3.11-alpine AS builder -FROM alpine:3.10 as builder +# Set work directory +WORKDIR /app -RUN apk add --no-cache python3 -RUN apk add --no-cache git -RUN python3 -m pip install --upgrade setuptools pip wheel +# Install poetry +RUN pip install poetry -WORKDIR /app/ +# Copy source code COPY . . -RUN python3 setup.py bdist_wheel +# Build wheel +RUN poetry build -f wheel -# Install: copy tesk-core*.whl and install it with dependencies +################################################### +# Stage 2: Install wheel and create user # +################################################### +FROM python:3.11-alpine AS runner -FROM alpine:3.10 +# Copy built wheel from the builder stage +COPY --from=builder /app/dist/*.whl /dist/ -RUN apk add --no-cache python3 +# Install the application with dependencies +RUN pip install /dist/*.whl -COPY --from=builder /app/dist/tesk*.whl /root/ -RUN python3 -m pip install --disable-pip-version-check --no-cache-dir /root/tesk*.whl +# Create a non-root user +RUN adduser -D -u 1000 taskmasterUser -RUN adduser --uid 100 -S taskmaster -USER 100 +# Switch to the non-root user +USER taskmasterUser +# Set the working directory +WORKDIR /app + +# Entrypoint command ENTRYPOINT ["taskmaster"] diff --git a/pyproject.toml b/pyproject.toml index 7379bc39..565dae2f 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -43,20 +43,13 @@ mypy = "^1.10.0" [tool.ruff.lint] select = [ - # pycodestyle - "E", - # Pyflakes - "F", - # pyupgrade - "UP", - # flake8-bugbear - "B", - # flake8-simplify - "SIM", - # isort - "I", - # pylint - "PL" + "E", # pycodestyle + "F", # Pyflakes + "UP", # pyupgrade + "B", # flake8-bugbear + "SIM", # flake8-simplify + "I", # isort + "PL" # pylint ] [tool.ruff.format] diff --git a/taskmaster b/scripts/taskmaster similarity index 100% rename from taskmaster rename to scripts/taskmaster diff --git a/tests/__init__.py b/tests/__init__.py deleted file mode 100644 index e69de29b..00000000 diff --git a/tests/test_unit/__init__.py b/tests/test_unit/__init__.py deleted file mode 100644 index e69de29b..00000000 diff --git a/tests/test_unit/service/__init__.py b/tests/test_unit/service/__init__.py deleted file mode 100644 index e69de29b..00000000