Spaces:
Sleeping
Sleeping
Commit
·
6692ef0
1
Parent(s):
bd54343
Refactor Dockerfile: streamline user creation and directory setup, ensure correct ownership for application files, and enhance script permissions for improved build process clarity and security.
Browse files- Dockerfile +15 -18
Dockerfile
CHANGED
|
@@ -16,33 +16,30 @@ RUN apt-get update && apt-get install -y \
|
|
| 16 |
ffmpeg \
|
| 17 |
&& rm -rf /var/lib/apt/lists/*
|
| 18 |
|
| 19 |
-
# Create
|
|
|
|
|
|
|
|
|
|
| 20 |
RUN mkdir -p /app/storage/audio \
|
| 21 |
/app/storage/text \
|
| 22 |
/app/storage/temp \
|
| 23 |
-
/app/app/models
|
|
|
|
| 24 |
|
| 25 |
# Copy requirements first to leverage Docker cache
|
| 26 |
-
COPY requirements.txt .
|
| 27 |
RUN pip install --no-cache-dir -r requirements.txt
|
| 28 |
|
| 29 |
-
#
|
| 30 |
-
|
| 31 |
-
|
| 32 |
-
# Copy application code
|
| 33 |
-
COPY . .
|
| 34 |
|
| 35 |
-
#
|
| 36 |
-
RUN
|
| 37 |
-
|
| 38 |
-
|
| 39 |
|
| 40 |
-
#
|
| 41 |
-
RUN chmod +x /app/scripts
|
| 42 |
-
# Create app user
|
| 43 |
-
useradd -m -u 1000 app && \
|
| 44 |
-
# Set ownership of all files and directories
|
| 45 |
-
chown -R app:app /app
|
| 46 |
|
| 47 |
# Switch to app user
|
| 48 |
USER app
|
|
|
|
| 16 |
ffmpeg \
|
| 17 |
&& rm -rf /var/lib/apt/lists/*
|
| 18 |
|
| 19 |
+
# Create app user first (before creating directories)
|
| 20 |
+
RUN useradd -m -u 1000 app
|
| 21 |
+
|
| 22 |
+
# Create necessary directories and set permissions
|
| 23 |
RUN mkdir -p /app/storage/audio \
|
| 24 |
/app/storage/text \
|
| 25 |
/app/storage/temp \
|
| 26 |
+
/app/app/models \
|
| 27 |
+
&& chown -R app:app /app
|
| 28 |
|
| 29 |
# Copy requirements first to leverage Docker cache
|
| 30 |
+
COPY --chown=app:app requirements.txt .
|
| 31 |
RUN pip install --no-cache-dir -r requirements.txt
|
| 32 |
|
| 33 |
+
# Copy the entire application code
|
| 34 |
+
COPY --chown=app:app . .
|
|
|
|
|
|
|
|
|
|
| 35 |
|
| 36 |
+
# Ensure the models directory exists and has the correct files
|
| 37 |
+
RUN mkdir -p /app/app/models && \
|
| 38 |
+
cp -r app/models/* /app/app/models/ && \
|
| 39 |
+
chown -R app:app /app/app/models
|
| 40 |
|
| 41 |
+
# Make scripts executable
|
| 42 |
+
RUN chmod +x /app/scripts/*.sh
|
|
|
|
|
|
|
|
|
|
|
|
|
| 43 |
|
| 44 |
# Switch to app user
|
| 45 |
USER app
|