Commit fbc1814f authored by Artem Baranovskyi's avatar Artem Baranovskyi
Browse files

Image build is optimized.

parent b1615fb1
Pipeline #10684 failed with stages
in 12 minutes and 41 seconds
......@@ -19,6 +19,8 @@ variables:
DOCKER_TLS_CERTDIR: ""
DOCKER_HOST: "unix:///var/run/docker.sock"
DOCKER_OPTS: "--data-root=/mnt/volume/docker-data"
DOCKER_MEMORY: "4g"
DOCKER_CPUS: "2"
build:
stage: build
......
# Build stage
FROM python:3.10-slim AS builder
FROM pytorch/pytorch:2.0.1-cuda11.7-cudnn8-runtime AS builder
# Install system dependencies
RUN apt-get update && apt-get install -y --no-install-recommends \
build-essential \
python3-venv \
&& apt-get clean \
&& rm -rf /var/lib/apt/lists/*
build-essential python3-venv && \
apt-get clean && \
rm -rf /var/lib/apt/lists/*
# Create and activate virtual environment
RUN python3 -m venv /opt/myenv
ENV PATH="/opt/myenv/bin:$PATH"
WORKDIR /app
COPY . /app
# Install dependencies in separate steps to reduce memory usage
RUN /opt/myenv/bin/pip install torch && \
rm -rf /root/.cache/pip \
RUN /opt/myenv/bin/pip install Flask && \
rm -rf /root/.cache/pip
RUN /opt/myenv/bin/pip install matplotlib && \
rm -rf /root/.cache/pip
RUN /opt/myenv/bin/pip install scikit-learn && \
rm -rf /root/.cache/pip
RUN /opt/myenv/bin/pip install transformers && \
rm -rf /root/.cache/pip
RUN /opt/myenv/bin/pip install pandas && \
rm -rf /root/.cache/pip
RUN /opt/myenv/bin/pip install sentence_transformers && \
rm -rf /root/.cache/pip
RUN /opt/myenv/bin/pip install --upgrade setuptools wheel
# Install dependencies in smaller steps
RUN pip install --no-cache-dir Flask matplotlib scikit-learn transformers pandas sentence_transformers
RUN pip install --no-cache-dir --upgrade setuptools wheel
# Final image
FROM python:3.10-slim
# Install system dependencies
RUN apt-get update && apt-get install -y --no-install-recommends \
&& rm -rf /var/lib/apt/lists/*
# Copy virtual environment and application from build stage
COPY --from=builder /opt/myenv /opt/myenv
COPY --from=builder /app /app
# Activate virtual environment in the final image
ENV PATH="/opt/myenv/bin:$PATH"
# Set permissions
RUN chown -R www-data:www-data /app/asyst \
&& chmod -R 755 /app/asyst
RUN chown -R www-data:www-data /app && chmod -R 755 /app
# Expose port for Flask API
EXPOSE 5000
# Run the application
CMD ["/opt/myenv/bin/python", "/app/api.py"]
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment