ai-engine / Dockerfile
Severian's picture
Update Dockerfile
0c01f90 verified
raw
history blame
2.46 kB
# Base Python image with correct version
FROM python:3.12-slim-bookworm AS base
# Set shared environment variables
ENV POETRY_VERSION=1.8.4 \
POETRY_NO_INTERACTION=1 \
POETRY_VIRTUALENVS_CREATE=true \
POETRY_VIRTUALENVS_IN_PROJECT=true \
POETRY_CACHE_DIR=/tmp/poetry_cache \
PYTHONDONTWRITEBYTECODE=1
# Pull official images first
FROM langgenius/dify-web:latest AS web
FROM langgenius/dify-api:latest AS api
# Final stage
FROM base
# Create users and set up directories
RUN useradd -m -u 1000 user && \
apt-get update && \
apt-get install -y postgresql postgresql-contrib curl git gcc python3-dev \
libgmp-dev libmpfr-dev libmpc-dev nodejs npm && \
rm -rf /var/lib/apt/lists/* && \
mkdir -p /var/run/postgresql /var/lib/postgresql/data /app/api /app/web /data/storage && \
chown -R postgres:postgres /var/run/postgresql /var/lib/postgresql/data && \
chmod 2777 /var/run/postgresql && \
chmod 700 /var/lib/postgresql/data && \
chown -R user:user /app /data
# Initialize PostgreSQL
USER postgres
RUN /usr/lib/postgresql/15/bin/initdb -D /var/lib/postgresql/data && \
echo "host all all 0.0.0.0/0 md5" >> /var/lib/postgresql/data/pg_hba.conf && \
echo "listen_addresses='*'" >> /var/lib/postgresql/data/postgresql.conf
# Switch back to user
USER user
ENV HOME=/home/user \
PATH=/home/user/.local/bin:$PATH
# Copy application files
WORKDIR /app
COPY --from=web --chown=user:user /app/web /app/web/
COPY --from=api --chown=user:user /app/api /app/api/
# Set up API dependencies
WORKDIR /app/api
COPY --from=api --chown=user /app/api/pyproject.toml /app/api/poetry.lock /app/api/poetry.toml ./
RUN pip install --no-cache-dir "poetry==${POETRY_VERSION}" && \
poetry install --no-root --no-dev
# Create storage symlink
RUN ln -s /data/storage /app/api/storage
# Copy and set up entrypoint script
COPY --from=api --chown=user:user /entrypoint.sh /app/entrypoint.sh
RUN chmod +x /app/entrypoint.sh
# Add all environment variables from the compose file
ENV FLASK_APP=app.py \
EDITION=SELF_HOSTED \
DEPLOY_ENV=PRODUCTION \
MODE=api \
DB_USERNAME=postgres \
DB_PASSWORD=difyai123456 \
DB_HOST=localhost \
DB_PORT=5432 \
DB_DATABASE=dify \
REDIS_HOST=localhost \
REDIS_PORT=6379 \
REDIS_PASSWORD=difyai123456 \
VECTOR_STORE=weaviate \
MIGRATION_ENABLED=true
EXPOSE 7860 3000
WORKDIR /app
ENTRYPOINT ["/bin/bash", "/app/entrypoint.sh"]