Spaces:
Running
Running
Expose the secret SECRETS at build-time
Browse files- Expose the secret SECRETS at build-time
- All Redis credentials to enable connection to redis cache
- Dockerfile +40 -24
Dockerfile
CHANGED
@@ -1,25 +1,41 @@
|
|
1 |
-
FROM python:3.11.9-slim
|
2 |
-
|
3 |
-
#
|
4 |
-
|
5 |
-
|
6 |
-
|
7 |
-
|
8 |
-
|
9 |
-
|
10 |
-
|
11 |
-
|
12 |
-
|
13 |
-
|
14 |
-
|
15 |
-
|
16 |
-
|
17 |
-
|
18 |
-
|
19 |
-
|
20 |
-
|
21 |
-
|
22 |
-
|
23 |
-
|
24 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
25 |
CMD ["uvicorn", "main:app", "--host", "0.0.0.0", "--port", "7860"]
|
|
|
1 |
+
FROM python:3.11.9-slim
|
2 |
+
|
3 |
+
# Expose the secret SECRETS at build-time
|
4 |
+
RUN --mount=type=secret,id=REDIS_URL,mode=0444,required=true
|
5 |
+
RUN --mount=type=secret,id=REDIS_USERNAME,mode=0444,required=true
|
6 |
+
RUN --mount=type=secret,id=REDIS_PASSWORD,mode=0444,required=true
|
7 |
+
|
8 |
+
# Read secrets and set environment variables
|
9 |
+
RUN export REDIS_URL=$(cat /run/secrets/REDIS_URL) \
|
10 |
+
&& export REDIS_USERNAME=$(cat /run/secrets/REDIS_USERNAME) \
|
11 |
+
&& export REDIS_PASSWORD=$(cat /run/secrets/REDIS_PASSWORD) \
|
12 |
+
&& echo "REDIS_URL=$REDIS_URL" >> /etc/environment \
|
13 |
+
&& echo "REDIS_USERNAME=$REDIS_USERNAME" >> /etc/environment \
|
14 |
+
&& echo "REDIS_PASSWORD=$REDIS_PASSWORD" >> /etc/environment
|
15 |
+
|
16 |
+
# Source the environment file
|
17 |
+
RUN . /etc/environment
|
18 |
+
|
19 |
+
# Copy requirements file
|
20 |
+
COPY requirements.txt .
|
21 |
+
|
22 |
+
# Update pip
|
23 |
+
RUN pip --timeout=3000 install --no-cache-dir --upgrade pip
|
24 |
+
|
25 |
+
# Install dependecies
|
26 |
+
RUN pip --timeout=3000 install --no-cache-dir -r requirements.txt
|
27 |
+
|
28 |
+
# Make project directory
|
29 |
+
RUN mkdir -p /src/api/
|
30 |
+
|
31 |
+
# Set working directory
|
32 |
+
WORKDIR /src/api
|
33 |
+
|
34 |
+
# Copy API
|
35 |
+
COPY . .
|
36 |
+
|
37 |
+
# Expose app port
|
38 |
+
EXPOSE 7860
|
39 |
+
|
40 |
+
# Start application
|
41 |
CMD ["uvicorn", "main:app", "--host", "0.0.0.0", "--port", "7860"]
|