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

Image build is optimized.

parent 0de22e92
...@@ -14,4 +14,4 @@ cd "$BACKEND_PATH" || { ...@@ -14,4 +14,4 @@ cd "$BACKEND_PATH" || {
docker-compose up -d --build docker-compose up -d --build
# Message about successful deployment # Message about successful deployment
echo "Flask-бекенд развернут и запущен." echo "Flask NLP backend is up and running."
\ No newline at end of file \ No newline at end of file
FROM python:3.11-slim # Build stage
FROM python:3.10-slim AS builder
# Installing system dependencies # Install system dependencies
RUN apt-get update && apt-get install -y --no-install-recommends \ RUN apt-get update && apt-get install -y --no-install-recommends \
build-essential \ build-essential \
python3-venv \ python3-venv \
curl \
&& rm -rf /var/lib/apt/lists/* && rm -rf /var/lib/apt/lists/*
# Creating and activating the virtual environment \ # Create and activate virtual environment
RUN python3 -m venv /opt/myenv RUN python3 -m venv /opt/myenv
ENV PATH="/opt/myenv/bin:$PATH" ENV PATH="/opt/myenv/bin:$PATH"
WORKDIR /app WORKDIR /app
COPY . /app COPY . /app
COPY ./asyst /app/asyst COPY ./asyst /app/asyst
COPY requirements.txt .
# Installing dependencies # Install dependencies
RUN /opt/myenv/bin/pip install -r /app/requirements.txt RUN /opt/myenv/bin/pip install -r /app/requirements.txt \
RUN /opt/myenv/bin/python3 -m pip install --upgrade setuptools wheel && /opt/myenv/bin/python3 -m pip install --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 # Set permissions
RUN chown -R www-data:www-data /app/asyst RUN chown -R www-data:www-data /app/asyst \
RUN chmod -R 755 /app/asyst && chmod -R 755 /app/asyst
# Open port for Flask API # Expose port for Flask API
EXPOSE 5000 EXPOSE 5000
# Launch application # Run the application
CMD ["python", "/app/api.py"] CMD ["/opt/myenv/bin/python", "/app/api.py"]
\ No newline at end of file \ No newline at end of file
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