From 6924dd6df64118398d40bd297ea3219da0e16246 Mon Sep 17 00:00:00 2001 From: Fagner-lourenco <79019065+Fagner-lourenco@users.noreply.github.com> Date: Sat, 4 May 2024 20:50:11 -0300 Subject: [PATCH 1/2] Update Dockerfile --- application/Dockerfile | 62 ++++++++++++++++++++++-------------------- 1 file changed, 32 insertions(+), 30 deletions(-) diff --git a/application/Dockerfile b/application/Dockerfile index 5de93bc..5ea4417 100644 --- a/application/Dockerfile +++ b/application/Dockerfile @@ -1,79 +1,81 @@ -# Builder Stage +# Etapa de Construção FROM ubuntu:mantic as builder -# Install necessary packages and Python +# Configura o modo não interativo para evitar prompts +ENV DEBIAN_FRONTEND=noninteractive + +# Instala os pacotes necessários e o Python RUN apt-get update && \ apt-get install -y --no-install-recommends gcc curl wget unzip libc6-dev python3.11 python3-pip python3.11-venv && \ apt-get clean && \ rm -rf /var/lib/apt/lists/* -# Verify Python installation and setup symlink -RUN if [ -f /usr/bin/python3.11 ]; then \ - ln -s /usr/bin/python3.11 /usr/bin/python; \ - else \ +# Verifica a instalação do Python e configura um link simbólico +RUN if [ ! -f /usr/bin/python3.11 ]; then \ echo "Python 3.11 not found"; exit 1; \ - fi + fi && \ + ln -s /usr/bin/python3.11 /usr/bin/python -# Download and unzip the model +# Baixa e descompacta o modelo RUN wget https://d3dg1063dc54p9.cloudfront.net/models/embeddings/mpnet-base-v2.zip && \ unzip mpnet-base-v2.zip -d model && \ rm mpnet-base-v2.zip -# Install Rust +# Instala o Rust RUN curl https://sh.rustup.rs -sSf | sh -s -- -y -# Clean up to reduce container size -RUN apt-get remove --purge -y wget unzip && apt-get autoremove -y && rm -rf /var/lib/apt/lists/* +# Limpa para reduzir o tamanho do container +RUN apt-get purge -y wget unzip && apt-get autoremove -y && rm -rf /var/lib/apt/lists/* -# Copy requirements.txt +# Copia o requirements.txt COPY requirements.txt . -# Setup Python virtual environment +# Configura o ambiente virtual Python RUN python3.11 -m venv /venv -# Activate virtual environment and install Python packages +# Ativa o ambiente virtual e instala os pacotes Python ENV PATH="/venv/bin:$PATH" - -# Install Python packages RUN pip install --no-cache-dir --upgrade pip && \ pip install --no-cache-dir tiktoken && \ pip install --no-cache-dir -r requirements.txt -# Final Stage +# Etapa Final FROM ubuntu:mantic as final -# Install Python -RUN apt-get update && apt-get install -y --no-install-recommends python3.11 python3.11-venv && \ +# Instala o Python +RUN apt-get update && \ + apt-get install -y --no-install-recommends python3.11 python3.11-venv && \ ln -s /usr/bin/python3.11 /usr/bin/python && \ rm -rf /var/lib/apt/lists/* -# Set working directory +# Define o diretório de trabalho WORKDIR /app -# Create a non-root user: `appuser` (Feel free to choose a name) +# Cria um usuário não root: `appuser` RUN groupadd -r appuser && \ useradd -r -g appuser -d /app -s /sbin/nologin -c "Docker image user" appuser -# Copy the virtual environment and model from the builder stage +# Copia o ambiente virtual e o modelo da etapa de construção COPY --from=builder /venv /venv COPY --from=builder /model /app/model -# Copy your application code +# Copia o código da aplicação COPY . /app/application -# Change the ownership of the /app directory to the appuser -RUN chown -R appuser:appuser /app +# Muda a propriedade do diretório /app para o appuser +RUN mkdir -p /app/application/inputs/local && \ + chown -R appuser:appuser /app -# Set environment variables +# Configura variáveis de ambiente ENV FLASK_APP=app.py \ FLASK_DEBUG=true \ PATH="/venv/bin:$PATH" -# Expose the port the app runs on +# Expõe a porta em que o app roda EXPOSE 7091 -# Switch to non-root user +# Altera para o usuário não root USER appuser -# Start Gunicorn -CMD ["gunicorn", "-w", "2", "--timeout", "120", "--bind", "0.0.0.0:7091", "application.wsgi:app"] \ No newline at end of file +# Inicia o Gunicorn +CMD ["gunicorn", "-w", "2", "--timeout", "120", "--bind", "0.0.0.0:7091", "application.wsgi:app"] From 3f68e0d66f3048b49280ae218cc12505b49670e5 Mon Sep 17 00:00:00 2001 From: Alex Date: Sun, 12 May 2024 22:33:43 +0100 Subject: [PATCH 2/2] chore: Update Dockerfile --- application/Dockerfile | 62 ++++++++++++++++++++++-------------------- 1 file changed, 32 insertions(+), 30 deletions(-) diff --git a/application/Dockerfile b/application/Dockerfile index 5ea4417..2625431 100644 --- a/application/Dockerfile +++ b/application/Dockerfile @@ -1,81 +1,83 @@ -# Etapa de Construção +# Builder Stage FROM ubuntu:mantic as builder -# Configura o modo não interativo para evitar prompts ENV DEBIAN_FRONTEND=noninteractive -# Instala os pacotes necessários e o Python +# Install necessary packages and Python RUN apt-get update && \ apt-get install -y --no-install-recommends gcc curl wget unzip libc6-dev python3.11 python3-pip python3.11-venv && \ apt-get clean && \ rm -rf /var/lib/apt/lists/* -# Verifica a instalação do Python e configura um link simbólico -RUN if [ ! -f /usr/bin/python3.11 ]; then \ +# Verify Python installation and setup symlink +RUN if [ -f /usr/bin/python3.11 ]; then \ + ln -s /usr/bin/python3.11 /usr/bin/python; \ + else \ echo "Python 3.11 not found"; exit 1; \ - fi && \ - ln -s /usr/bin/python3.11 /usr/bin/python + fi -# Baixa e descompacta o modelo +# Download and unzip the model RUN wget https://d3dg1063dc54p9.cloudfront.net/models/embeddings/mpnet-base-v2.zip && \ unzip mpnet-base-v2.zip -d model && \ rm mpnet-base-v2.zip -# Instala o Rust +# Install Rust RUN curl https://sh.rustup.rs -sSf | sh -s -- -y -# Limpa para reduzir o tamanho do container -RUN apt-get purge -y wget unzip && apt-get autoremove -y && rm -rf /var/lib/apt/lists/* +# Clean up to reduce container size +RUN apt-get remove --purge -y wget unzip && apt-get autoremove -y && rm -rf /var/lib/apt/lists/* -# Copia o requirements.txt +# Copy requirements.txt COPY requirements.txt . -# Configura o ambiente virtual Python +# Setup Python virtual environment RUN python3.11 -m venv /venv -# Ativa o ambiente virtual e instala os pacotes Python +# Activate virtual environment and install Python packages ENV PATH="/venv/bin:$PATH" + +# Install Python packages RUN pip install --no-cache-dir --upgrade pip && \ pip install --no-cache-dir tiktoken && \ pip install --no-cache-dir -r requirements.txt -# Etapa Final +# Final Stage FROM ubuntu:mantic as final -# Instala o Python -RUN apt-get update && \ - apt-get install -y --no-install-recommends python3.11 python3.11-venv && \ +# Install Python +RUN apt-get update && apt-get install -y --no-install-recommends python3.11 && \ ln -s /usr/bin/python3.11 /usr/bin/python && \ rm -rf /var/lib/apt/lists/* -# Define o diretório de trabalho +# Set working directory WORKDIR /app -# Cria um usuário não root: `appuser` +# Create a non-root user: `appuser` (Feel free to choose a name) RUN groupadd -r appuser && \ useradd -r -g appuser -d /app -s /sbin/nologin -c "Docker image user" appuser -# Copia o ambiente virtual e o modelo da etapa de construção +# Copy the virtual environment and model from the builder stage COPY --from=builder /venv /venv COPY --from=builder /model /app/model -# Copia o código da aplicação +# Copy your application code COPY . /app/application -# Muda a propriedade do diretório /app para o appuser -RUN mkdir -p /app/application/inputs/local && \ - chown -R appuser:appuser /app +# Change the ownership of the /app directory to the appuser + +RUN mkdir -p /app/application/inputs/local +RUN chown -R appuser:appuser /app -# Configura variáveis de ambiente +# Set environment variables ENV FLASK_APP=app.py \ FLASK_DEBUG=true \ PATH="/venv/bin:$PATH" -# Expõe a porta em que o app roda +# Expose the port the app runs on EXPOSE 7091 -# Altera para o usuário não root +# Switch to non-root user USER appuser -# Inicia o Gunicorn -CMD ["gunicorn", "-w", "2", "--timeout", "120", "--bind", "0.0.0.0:7091", "application.wsgi:app"] +# Start Gunicorn +CMD ["gunicorn", "-w", "2", "--timeout", "120", "--bind", "0.0.0.0:7091", "application.wsgi:app"] \ No newline at end of file