-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathDockerfile
327 lines (252 loc) · 8.65 KB
/
Dockerfile
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
# # Use an official Python runtime as a parent image
# FROM python:3.9-alpine
# # Define build-time variables
# ARG DB_HOST
# ARG DB_PASSWORD
# ARG DB_NAME
# ARG admin_email
# ARG admin_password
# ARG STRIPE_SECRET_KEY
# ARG FRONTEND_BASE_URL
# ARG DB_USERNAME
# ARG DB_PORT
# # Set the working directory
# WORKDIR /app
# # Set environment variables
# ENV admin_email=${admin_email}
# ENV admin_password=${admin_password}
# ENV STRIPE_SECRET_KEY=${STRIPE_SECRET_KEY}
# ENV FRONTEND_BASE_URL=${FRONTEND_BASE_URL}
# ENV DB_HOST=${DB_HOST}
# ENV DB_PASSWORD=${DB_PASSWORD}
# ENV DB_NAME=${DB_NAME}
# ENV DB_USERNAME=${DB_USERNAME}
# ENV DB_PORT=${DB_PORT}
# # Copy the current directory contents into the container at /app
# COPY . /app
# # Create a virtual environment and install dependencies
# RUN python3 -m venv venv && \
# . venv/bin/activate && \
# pip install --upgrade pip && \
# pip install -r requirements.txt
# # # Run tests
# # RUN . venv/bin/activate && \
# # export PYTHONPATH=. && \
# # pytest tests/ -v
# # # Expose the port that the app runs on
# # EXPOSE 8000
# # Install wait-for-it.sh
# RUN apk add --no-cache bash curl
# ADD https://raw.githubusercontent.com/vishnubob/wait-for-it/master/wait-for-it.sh /wait-for-it.sh
# RUN chmod +x /wait-for-it.sh
# # Copy the built React app from the frontend stage
# COPY --from=frontend /frontend/.next /app/frontend/.next
# COPY --from=frontend /frontend/public /app/frontend/public
# COPY --from=frontend /frontend/node_modules /app/frontend/node_modules
# COPY --from=frontend /frontend/package*.json /app/frontend/
# # Install serve to serve the built React app
# RUN npm install -g serve
# # Expose the ports
# EXPOSE 8000
# EXPOSE 3000
# # Run the FastAPI and Next.js applications in the background and then run tests
# RUN . venv/bin/activate && \
# uvicorn main:app --host 0.0.0.0 --port 8000 & \
# serve -s frontend -l 3000 & \
# /wait-for-it.sh localhost:8000 -- /wait-for-it.sh localhost:3000 -- \
# pytest -v tests/ -v && \
# pkill -f "uvicorn" && \
# pkill -f "serve"
# # Run the application
# CMD ["sh", "-c", ". venv/bin/activate && uvicorn main:app --host 0.0.0.0 --port 8000"]
# Stage 1: Build React app
# FROM node:18-alpine AS frontend
# WORKDIR /frontend
# # Copy frontend code
# COPY roombooker/material-ui-nextjs/package*.json ./
# RUN npm install
# COPY roombooker/material-ui-nextjs .
# RUN chmod +x /frontend/run_frontend.sh
# RUN tr -d "\r" < /frontend/run_frontend.sh > /frontend/run_frontendnew.sh
# RUN chmod +x /frontend/run_frontendnew.sh
# # Run the tests
# RUN /frontend/run_frontendnew.shdd
# # Stage 2: Build FastAPI app
# # FROM python:3.9-alpine AS backend
# FROM python:3.9-slim-buster AS backend
# # Define build-time variables
# ARG DB_HOST
# ARG DB_PASSWORD
# ARG DB_NAME
# ARG admin_email
# ARG admin_password
# ARG STRIPE_SECRET_KEY
# ARG FRONTEND_BASE_URL
# ARG DB_USERNAME
# ARG DB_PORT
# # Set environment variables
# ENV admin_email=${admin_email}
# ENV admin_password=${admin_password}
# ENV STRIPE_SECRET_KEY=${STRIPE_SECRET_KEY}
# ENV FRONTEND_BASE_URL=${FRONTEND_BASE_URL}
# ENV DB_HOST=${DB_HOST}
# ENV DB_PASSWORD=${DB_PASSWORD}
# ENV DB_NAME=${DB_NAME}
# ENV DB_USERNAME=${DB_USERNAME}
# ENV DB_PORT=${DB_PORT}
# # Install system dependencies for playwright
# RUN apt-get update && apt-get install -y \
# chromium \
# libnss3 \
# libatk1.0-0 \
# libatk-bridge2.0-0 \
# libcups2 \
# libxkbcommon-x11-0 \
# libgbm-dev \
# libasound2 \
# libpangocairo-1.0-0 \
# wget \
# --no-install-recommends && \
# rm -rf /var/lib/apt/lists/*
# WORKDIR /frontend
# EXPOSE 3000
# # Copy frontend code
# # COPY roombooker/material-ui-nextjs/package*.json ./
# # RUN npm install
# COPY roombooker/material-ui-nextjs /frontend
# RUN chmod +x /frontend/run_frontend.sh
# RUN tr -d "\r" < /frontend/run_frontend.sh > /frontend/run_frontendnew.sh
# RUN chmod +x /frontend/run_frontendnew.sh
# # Run the tests
# RUN /frontend/run_frontendnew.sh
# # Set the working directory
# WORKDIR /app
# # Copy the backend directory contents into the container at /app
# COPY backend /app
# # Create a virtual environment and install dependencies
# RUN python3 -m venv venv && \
# . venv/bin/activate && \
# pip install --upgrade pip && \
# ls -l && \
# pip install -r /app/requirements.txt && \
# playwright install
# # Install wait-for-it.sh
# ADD https://raw.githubusercontent.com/vishnubob/wait-for-it/master/wait-for-it.sh /wait-for-it.sh
# RUN chmod +x /wait-for-it.sh
# Copy the built React app from the frontend stage
# COPY --from=frontend /frontend/.next /app/frontend/.next
# COPY --from=frontend /frontend/public /app/frontend/public
# COPY --from=frontend /frontend/node_modules /app/frontend/node_modules
# COPY --from=frontend /frontend/package*.json /app/frontend/
# Install serve to serve the built React app
# RUN npm install -g serve
# CMD ["sh", "-c", ". venv/bin/activate && uvicorn main:app --host 0.0.0.0 --port 8000 &"]
# CMD ["sh", "-c", "npm run dev &"]
# CMD ["sh", "-c", "echo FastAPI and Nextjs running?"]
# RUN . venv/bin/activate && uvicorn main:app --host 0.0.0.0 --port 8000 &
# RUN . venv/bin/activate && cd ../ && ls -l && npm run dev &
# Copy the test script
# Expose the ports
# EXPOSE 8000
# RUN chmod +x /app/run_test.sh
# RUN tr -d "\r" < /app/run_test.sh > /app/run_testnew.sh
# RUN chmod +x /app/run_testnew.sh
# # Run the tests
# RUN /app/run_testnew.sh
# Run the FastAPI and Next.js applications in the background and then run tests
# RUN . venv/bin/activate && \
# export PYTHONPATH=app && \
# ls -la && \
# # uvicorn main:app --host 0.0.0.0 --port 8000 & \
# # cd /frontend
# # && npm run dev & \
# /wait-for-it.sh localhost:8000 -- /wait-for-it.sh localhost:3000 -- && \
# pytest app/tests/ -v && \
# pkill -f "uvicorn" && \
# pkill -f "npm run dev"
# Stage 1: Build the frontend
FROM node:18-alpine AS frontend
WORKDIR /frontend
# Copy frontend code
# COPY roombooker/material-ui-nextjs/package*.json ./
# RUN npm install
COPY roombooker .
# Debug: List the contents of the frontend directory after copying
RUN echo "Listing contents of /frontend after copying source files:" && ls -la /frontend
RUN echo "Listing contents of /frontend/material-ui-nextjs after copying source files:" && ls -la /frontend/material-ui-nextjs
# Change to the material-ui-nextjs directory and install dependencies
WORKDIR /frontend/material-ui-nextjs
RUN npm install
RUN echo "Listing contents of /frontend/material-ui-nextjs after npm install:" && ls -la /frontend/material-ui-nextjs
# Stage 2: Build the backend
FROM python:3.9-slim-buster AS backend
# Install Node.js and npm from NodeSource
RUN apt-get update && apt-get install -y \
chromium \
libnss3 \
libatk1.0-0 \
libatk-bridge2.0-0 \
libcups2 \
libxkbcommon-x11-0 \
libgbm-dev \
libasound2 \
libpangocairo-1.0-0 \
wget \
curl \
bash \
--no-install-recommends && \
curl -fsSL https://deb.nodesource.com/setup_18.x | bash - && \
apt-get install -y nodejs && \
rm -rf /var/lib/apt/lists/*
# Set working directory for backend
WORKDIR /app
### Define build-time variables ###
# Backend env var
ARG DB_HOST
ARG DB_PASSWORD
ARG DB_NAME
ARG admin_email
ARG admin_password
ARG STRIPE_SECRET_KEY
ARG FRONTEND_BASE_URL
ARG DB_USERNAME
ARG DB_PORT
# Frontend env var
ARG NEXT_PUBLIC_STRIPE_PUBLISHABLE_KEY
ARG BACKEND_API_URL
ARG NEXT_PUBLIC_SESSION_PASSWORD
# ARG random_num=1
### Set environment variables ###
ENV admin_email=${admin_email}
ENV admin_password=${admin_password}
ENV STRIPE_SECRET_KEY=${STRIPE_SECRET_KEY}
ENV FRONTEND_BASE_URL=${FRONTEND_BASE_URL}
ENV DB_HOST=${DB_HOST}
ENV DB_PASSWORD=${DB_PASSWORD}
ENV DB_NAME=${DB_NAME}
ENV DB_USERNAME=${DB_USERNAME}
ENV DB_PORT=${DB_PORT}
ENV NEXT_PUBLIC_STRIPE_PUBLISHABLE_KEY=${NEXT_PUBLIC_STRIPE_PUBLISHABLE_KEY}
ENV BACKEND_API_URL='http://localhost:8000'
ENV NEXT_PUBLIC_SESSION_PASSWORD=${NEXT_PUBLIC_SESSION_PASSWORD}
# ENV random_num=${random_num}
# Copy backend code, including run_tests.sh
COPY backend .
# Copy the entire frontend directory from the frontend stage
COPY --from=frontend /frontend /app/frontend
# Create a virtual environment and install dependencies
RUN python3 -m venv venv && \
. venv/bin/activate && \
pip install --upgrade pip && \
pip install -r requirements.txt && \
playwright install
# Ensure run_tests.sh is executable
RUN chmod +x run_tests.sh
# Expose the ports
EXPOSE 8000
EXPOSE 3000
# Run the tests
RUN ./run_tests.sh
# RUN echo "Running tests - random_num ${random_num}" && ./run_tests.sh
# Run the applications
CMD ["sh", "-c", ". venv/bin/activate && uvicorn main:app --host 0.0.0.0 --port 8000"]