From 0d29097c0c3be091c1fa665ae1908ec05e3e7a39 Mon Sep 17 00:00:00 2001 From: Javed Habib Date: Mon, 13 May 2024 16:43:16 +0530 Subject: [PATCH] chore: change dockerfile due to moving to pyproject --- .dockerignore | 17 ++++++++- deployment/containers/filer.Dockerfile | 40 +++++++++++++------- deployment/containers/taskmaster.Dockerfile | 41 ++++++++++++++------- taskmaster => scripts/taskmaster | 0 tests/__init__.py | 0 tests/test_unit/__init__.py | 0 tests/test_unit/service/__init__.py | 0 7 files changed, 69 insertions(+), 29 deletions(-) rename taskmaster => scripts/taskmaster (100%) delete mode 100644 tests/__init__.py delete mode 100644 tests/test_unit/__init__.py delete mode 100644 tests/test_unit/service/__init__.py 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/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/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