forked from masnottuh/Group-Project
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathDockerfile
56 lines (43 loc) · 1.78 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
###########################
# This is a "builder" pattern in Docker.
# We need to process our React code into
# static files that we can serve (npm run build).
# You could also skip this part and just run
# "npm run build" and copy over the output manually
# like some kind of barbarian
###########################
FROM node:lts-alpine as builder
WORKDIR /frontend
# These two lines will allow us to pass in an environment
# variable when the image is *built* (not run). For local
# development, localhost; for production, your EC2's IP address
ARG REACT_APP_BASE_URL=localhost
ENV REACT_APP_BASE_URL=$REACT_APP_BASE_URL
ENV REACT_APP_BOOKS_API_KEY=sP13SdYySeTOurk238E2fN8uwM8pTHF3
ENV REACT_APP_GOOGLE_API_KEY=AIzaSyCqi37mzRrzkBrDZDb0BX9_IarX5iMOT88
COPY ./frontend/package.json .
RUN npm install
COPY ./frontend .
RUN npm run build
###########################
# This is the final image we want.
# First, it sets up the DRF application.
# Then, it copies over a config file which basically says:
# "if any requests come in whose uri starts with /api/,
# then hand them off to the gunicorn (Django) server,
# otherwise, serve up the React static files."
# Finally, it copies over the React static files to the place
# where nginx expects them to be.
###########################
FROM nginx:alpine
RUN apk add --update --no-cache python3 && ln -sf python3 /usr/bin/python
RUN python3 -m ensurepip
RUN pip3 install --no-cache --upgrade pip setuptools
COPY ./backend/requirements.txt .
RUN pip3 install -r requirements.txt
COPY ./backend .
RUN python manage.py makemigrations
RUN python manage.py migrate
COPY ./default.conf /etc/nginx/conf.d/default.conf
COPY --from=builder /frontend/build /usr/share/nginx/html
CMD nohup gunicorn --bind=0.0.0.0:8000 bookclub.wsgi:application & nginx -g 'daemon off;'