Refactor Dockerfile to set API key environment variable and add entrypoint script for improved runtime configuration
Browse files- Dockerfile +14 -5
Dockerfile
CHANGED
|
@@ -7,14 +7,23 @@ ENV PYTHONPATH="/app/src"
|
|
| 7 |
|
| 8 |
WORKDIR /app
|
| 9 |
|
| 10 |
-
|
| 11 |
COPY --chown=user ./requirements.txt requirements.txt
|
| 12 |
RUN pip install --no-cache-dir --upgrade -r requirements.txt
|
| 13 |
|
| 14 |
-
|
| 15 |
COPY --chown=user . /app
|
| 16 |
|
|
|
|
| 17 |
RUN --mount=type=secret,id=APIKey,mode=0444,required=true \
|
| 18 |
-
|
| 19 |
-
|
| 20 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 7 |
|
| 8 |
WORKDIR /app
|
| 9 |
|
|
|
|
| 10 |
COPY --chown=user ./requirements.txt requirements.txt
|
| 11 |
RUN pip install --no-cache-dir --upgrade -r requirements.txt
|
| 12 |
|
|
|
|
| 13 |
COPY --chown=user . /app
|
| 14 |
|
| 15 |
+
# Set the environment variable at runtime from the secret
|
| 16 |
RUN --mount=type=secret,id=APIKey,mode=0444,required=true \
|
| 17 |
+
echo "export APIKEY=$(cat /run/secrets/APIKey)" >> /home/user/.bashrc
|
| 18 |
+
|
| 19 |
+
# Add a startup script to ensure environment variable is set
|
| 20 |
+
RUN echo '#!/bin/bash\n\
|
| 21 |
+
if [ -f /app/APIKey ]; then\n\
|
| 22 |
+
export APIKEY=$(cat /app/APIKey)\n\
|
| 23 |
+
fi\n\
|
| 24 |
+
exec "$@"' > /app/entrypoint.sh && \
|
| 25 |
+
chmod +x /app/entrypoint.sh
|
| 26 |
+
|
| 27 |
+
# Use the entrypoint script
|
| 28 |
+
ENTRYPOINT ["/app/entrypoint.sh"]
|
| 29 |
+
CMD ["uvicorn", "app:app", "--host", "0.0.0.0", "--port", "7860"]
|