Severian commited on
Commit
7d9154c
·
verified ·
1 Parent(s): 2164287

Update Dockerfile

Browse files
Files changed (1) hide show
  1. Dockerfile +35 -48
Dockerfile CHANGED
@@ -1,32 +1,43 @@
1
  # Base Python image with correct version
2
  FROM python:3.12-slim-bookworm AS base
3
 
4
- # Set shared environment variables
5
- ENV POETRY_VERSION=1.8.4 \
6
- POETRY_NO_INTERACTION=1 \
7
- POETRY_VIRTUALENVS_CREATE=true \
8
- POETRY_VIRTUALENVS_IN_PROJECT=true \
9
- POETRY_CACHE_DIR=/tmp/poetry_cache \
10
- PYTHONDONTWRITEBYTECODE=1
11
-
12
- # Pull official images first
13
- FROM langgenius/dify-web:latest AS web
14
- FROM langgenius/dify-api:latest AS api
15
-
16
- # Final stage
17
- FROM base
18
-
19
- # Create users and set up directories
20
  RUN useradd -m -u 1000 user && \
21
- apt-get update && \
 
 
 
 
 
 
 
 
 
 
 
 
 
 
22
  apt-get install -y postgresql postgresql-contrib curl git gcc python3-dev \
23
  libgmp-dev libmpfr-dev libmpc-dev nodejs npm && \
24
  rm -rf /var/lib/apt/lists/* && \
25
- mkdir -p /var/run/postgresql /var/lib/postgresql/data /app/api /app/web /data/storage && \
26
  chown -R postgres:postgres /var/run/postgresql /var/lib/postgresql/data && \
27
  chmod 2777 /var/run/postgresql && \
28
- chmod 700 /var/lib/postgresql/data && \
29
- chown -R user:user /app /data
30
 
31
  # Initialize PostgreSQL
32
  USER postgres
@@ -39,31 +50,11 @@ USER user
39
  ENV HOME=/home/user \
40
  PATH=/home/user/.local/bin:$PATH
41
 
42
- # Copy application files
43
- WORKDIR /app
44
- COPY --from=web --chown=user:user /app/web /app/web/
45
- COPY --from=api --chown=user:user /app/api /app/api/
46
-
47
- # Set up API dependencies
48
- WORKDIR /app/api
49
- COPY --from=api --chown=user /app/api/pyproject.toml /app/api/poetry.lock /app/api/poetry.toml ./
50
-
51
- # Set up Python virtual environment
52
- ENV VIRTUAL_ENV=/app/api/.venv
53
- COPY --from=api ${VIRTUAL_ENV} ${VIRTUAL_ENV}
54
- ENV PATH="${VIRTUAL_ENV}/bin:${PATH}"
55
-
56
- RUN pip install --no-cache-dir "poetry==${POETRY_VERSION}" && \
57
- poetry install --no-root --no-dev
58
-
59
- # Create storage symlink
60
- RUN ln -s /data/storage /app/api/storage
61
-
62
- # Copy and set up entrypoint script
63
- COPY --from=api --chown=user:user /entrypoint.sh /app/entrypoint.sh
64
  RUN chmod +x /app/entrypoint.sh
65
 
66
- # Add all environment variables from the compose file
67
  ENV FLASK_APP=app.py \
68
  EDITION=SELF_HOSTED \
69
  DEPLOY_ENV=PRODUCTION \
@@ -73,13 +64,9 @@ ENV FLASK_APP=app.py \
73
  DB_HOST=localhost \
74
  DB_PORT=5432 \
75
  DB_DATABASE=dify \
76
- REDIS_HOST=localhost \
77
- REDIS_PORT=6379 \
78
- REDIS_PASSWORD=difyai123456 \
79
- VECTOR_STORE=weaviate \
80
  MIGRATION_ENABLED=true
81
 
82
- EXPOSE 7860 3000
83
 
84
  WORKDIR /app
85
 
 
1
  # Base Python image with correct version
2
  FROM python:3.12-slim-bookworm AS base
3
 
4
+ WORKDIR /app/api
5
+
6
+ # Install Poetry
7
+ ENV POETRY_VERSION=1.8.4
8
+ ENV POETRY_HOME=/opt/poetry
9
+ ENV POETRY_CACHE_DIR=/tmp/poetry_cache
10
+ ENV POETRY_NO_INTERACTION=1
11
+ ENV POETRY_VIRTUALENVS_IN_PROJECT=true
12
+ ENV POETRY_VIRTUALENVS_CREATE=true
13
+
14
+ # Install poetry in a separate layer
15
+ RUN pip install --no-cache-dir "poetry==${POETRY_VERSION}"
16
+
17
+ # Create and switch to non-root user early
 
 
18
  RUN useradd -m -u 1000 user && \
19
+ chown -R user:user /app /opt/poetry /tmp/poetry_cache
20
+
21
+ USER user
22
+
23
+ # Copy dependency files
24
+ COPY --chown=user:user pyproject.toml poetry.lock poetry.toml ./
25
+
26
+ # Install dependencies
27
+ RUN poetry install --no-root --no-dev
28
+
29
+ # Switch back to root for system installations
30
+ USER root
31
+
32
+ # Install system dependencies
33
+ RUN apt-get update && \
34
  apt-get install -y postgresql postgresql-contrib curl git gcc python3-dev \
35
  libgmp-dev libmpfr-dev libmpc-dev nodejs npm && \
36
  rm -rf /var/lib/apt/lists/* && \
37
+ mkdir -p /var/run/postgresql /var/lib/postgresql/data /data/storage && \
38
  chown -R postgres:postgres /var/run/postgresql /var/lib/postgresql/data && \
39
  chmod 2777 /var/run/postgresql && \
40
+ chmod 700 /var/lib/postgresql/data
 
41
 
42
  # Initialize PostgreSQL
43
  USER postgres
 
50
  ENV HOME=/home/user \
51
  PATH=/home/user/.local/bin:$PATH
52
 
53
+ # Copy entrypoint script
54
+ COPY --chown=user:user docker/entrypoint.sh /app/entrypoint.sh
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
55
  RUN chmod +x /app/entrypoint.sh
56
 
57
+ # Set environment variables
58
  ENV FLASK_APP=app.py \
59
  EDITION=SELF_HOSTED \
60
  DEPLOY_ENV=PRODUCTION \
 
64
  DB_HOST=localhost \
65
  DB_PORT=5432 \
66
  DB_DATABASE=dify \
 
 
 
 
67
  MIGRATION_ENABLED=true
68
 
69
+ EXPOSE 7860
70
 
71
  WORKDIR /app
72