gabcares commited on
Commit
3e986da
·
verified ·
1 Parent(s): 07eac76

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

Files changed (1) hide show
  1. Dockerfile +40 -24
Dockerfile CHANGED
@@ -1,25 +1,41 @@
1
- FROM python:3.11.9-slim
2
-
3
- # Copy requirements file
4
- COPY requirements.txt .
5
-
6
- # Update pip
7
- RUN pip --timeout=3000 install --no-cache-dir --upgrade pip
8
-
9
- # Install dependecies
10
- RUN pip --timeout=3000 install --no-cache-dir -r requirements.txt
11
-
12
- # Make project directory
13
- RUN mkdir -p /src/api/
14
-
15
- # Set working directory
16
- WORKDIR /src/api
17
-
18
- # Copy API
19
- COPY . .
20
-
21
- # Expose app port
22
- EXPOSE 7860
23
-
24
- # Start application
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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"]