From f7c4f6a32ec01c3421f72b18ca2919f60d8e3f84 Mon Sep 17 00:00:00 2001 From: mlongobardo-gituname Date: Wed, 25 Sep 2024 12:40:24 +0200 Subject: [PATCH] first improvements --- Dockerfile | 77 ++++++++++++++++++++++++++++++++++++-------------- pyproject.toml | 33 +++++++++++++++++++--- 2 files changed, 85 insertions(+), 25 deletions(-) diff --git a/Dockerfile b/Dockerfile index 6bf865c..610128c 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,21 +1,56 @@ -FROM ubuntu:20.04 - -SHELL ["/bin/bash", "-c"] -ENV BASH_ENV=~/.bashrc \ - MAMBA_ROOT_PREFIX=/opt/conda \ - PATH=$PATH:/opt/conda/envs/env_cwl_wrapper/bin - -# Install basic commands and mamba -RUN apt-get update && \ - apt-get install -y ca-certificates wget bash bzip2 gcc linux-libc-dev libc6-dev curl && \ - wget -qO- https://micromamba.snakepit.net/api/micromamba/linux-64/latest | tar -xvj bin/micromamba --strip-components=1 && \ - ./micromamba shell init -s bash -p ~/micromamba && \ - apt-get clean autoremove --yes && \ - rm -rf /var/lib/{apt,dpkg,cache,log} && \ - cp ./micromamba /usr/bin - -COPY . /tmp - -RUN micromamba create -f /tmp/environment.yml && \ - cd /tmp && \ - /opt/conda/envs/env_cwl_wrapper/bin/python setup.py install +# Stage 1: Build stage +FROM rockylinux:9.3-minimal AS build + +# Install necessary build tools +RUN microdnf install -y curl tar + +# Download the hatch tar.gz file from GitHub +RUN curl -L https://github.com/pypa/hatch/releases/latest/download/hatch-x86_64-unknown-linux-gnu.tar.gz -o /tmp/hatch-x86_64-unknown-linux-gnu.tar.gz + +# Extract the hatch binary +RUN tar -xzf /tmp/hatch-x86_64-unknown-linux-gnu.tar.gz -C /tmp/ + +# Stage 2: Final stage +FROM rockylinux:9.3-minimal + +# Install runtime dependencies +RUN microdnf install -y --nodocs nodejs && \ + microdnf clean all + +# Set up a default user and home directory +ENV HOME=/home/wrapper + +# Create a user with UID 1001, group root, and a home directory +RUN useradd -u 1001 -r -g 0 -m -d ${HOME} -s /sbin/nologin \ + -c "Default CWL Wrapper User" wrapper && \ + mkdir -p /app && \ + mkdir -p /prod && \ + chown -R 1001:0 /app && \ + chmod g+rwx ${HOME} /app + +# Copy the hatch binary from the build stage +COPY --from=build /tmp/hatch /usr/bin/hatch + +# Ensure the hatch binary is executable +RUN chmod +x /usr/bin/hatch + +# Switch to the non-root user +USER wrapper + +# Copy the application files into the /app directory +COPY --chown=1001:0 . /tmp +WORKDIR /tmp + +# Set up virtual environment paths +ENV VIRTUAL_ENV=/app/envs/wrapper +ENV PATH="$VIRTUAL_ENV/bin:$PATH" + +# Prune any existing environments and create a new production environment +RUN cd /tmp && hatch env prune && \ + hatch env create prod && \ + rm -fr /tmp/* /tmp/.git /tmp/.pytest_cache + +WORKDIR /app + +# Set the default command to run when the container starts +CMD ["cwl-wrapper"] \ No newline at end of file diff --git a/pyproject.toml b/pyproject.toml index 5738b3c..5adccfd 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -5,14 +5,28 @@ build-backend = "hatchling.build" [project] name = "cwl-wrapper" dynamic = ["version"] -description = "xxx" +description = "CWL wrapper to add stage-in and stage-out to a base app package" readme = "README.md" license = "Apache-2.0" -keywords = [ - "keyword_1", - "keyword_2", +keywords = [] + +#To add other authors +authors = [ +{ name = "Fabrice Brito", email = "fabrice.brito@terradue.com" +} +] + +classifiers = [ + "Development Status :: 4 - Beta", + "Environment :: Console", + "Intended Audience :: Developers", + "Programming Language :: Python", + "Programming Language :: Python :: Implementation :: PyPy" ] +[tool.hatch.envs.prod] +path = "/app/envs/wrapper" + [project.scripts] cwl-wrapper = "cwl_wrapper.app:main" @@ -29,6 +43,11 @@ include = [ "/src", ] +[project.urls] +Documentation = "https://github.com/EOEPCA/cwl-wrapper#readme" +Issues = "https://github.com/EOEPCA/cwl-wrapper/issues" +Source = "https://github.com/EOEPCA/cwl-wrapper" + [tool.hatch.envs.default] dependencies = [ "click", @@ -52,9 +71,15 @@ dependencies = [ "loguru" ] +#[tool.hatch.envs.test.env-vars] +#RETRY_ATTEMPTS="0" + [tool.hatch.envs.test.scripts] test = "hatch run nose2" testv = "hatch run nose2 --verbose" +#it needs coverage in dependencies section +#cov = ["coverage run --source=src -m nose2", "coverage report"] + [[tool.hatch.envs.test.matrix]] python = ["3.8", "3.9", "3.10", "3.11", "3.12"] \ No newline at end of file