Skip to content

Commit bdc27a7

Browse files
committed
Updated dockerfile to support latest build of application.
1 parent 2e41ac3 commit bdc27a7

File tree

13 files changed

+303
-248
lines changed

13 files changed

+303
-248
lines changed

Dockerfile.api

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
11
FROM python:3.9
22
WORKDIR /amazon-clone-flask
3-
COPY ./server/* ./server
3+
COPY ./server/* ./server/
44
COPY ./requirements.txt .
55
RUN pip3 install -r ./requirements.txt
66
EXPOSE 5000
77
WORKDIR /amazon-clone-flask/server
8-
COPY ./entrypoint.sh .
8+
COPY entrypoint.sh .
9+
RUN chmod +x entrypoint.sh
910
ENTRYPOINT ["./entrypoint.sh"]

Dockerfile.nginx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
FROM nginx:1.19-alpine
22

33
RUN rm /etc/nginx/conf.d/default.conf
4-
COPY nginx.conf /etc/nginx/conf.d
4+
COPY nginx.conf /etc/nginx/conf.d/

README.md

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ This is an web application done using React and Flask.
1717
## To deploy the entire thing (via four integrated Docker containers):
1818
1. `docker-compose up`
1919

20-
20+
docker-compose up --build --force-recreate
2121
### How to install the needed dependencies
2222

2323
1. pip install virtualenv
@@ -36,7 +36,24 @@ docker run -e TWILIO_ACCOUNT_SID=<YOUR_ACCOUNT_SID> -e TWILIO_AUTH_TOKEN=<YOUR_A
3636
1. Follow tutorial on https://medium.com/@dan.chiniara/installing-postgresql-for-windows-7ec8145698e3#:~:text=Graphical%20Installer%3A%20Postgres.app,and%20database.&text=Mac%20users%2C%20you're%20all%20set!
3737
2. Rename env-example to .env, and fill in the values.
3838
3. To create the database, for example, on Ubuntu run "sudo -u postgres psql -c 'create database {db_name};'"
39+
4. If it throws error 'sudo: psql: command not found' then run 'sudo apt-get install postgresql-client'
40+
41+
sudo service postgresql status
42+
43+
$ sudo -u postgres createuser --interactive
44+
Enter name of role to add: myuser
45+
Shall the new role be a superuser? (y/n) n
46+
Shall the new role be allowed to create databases? (y/n) n
47+
Shall the new role be allowed to create more new roles? (y/n) n
48+
49+
$ sudo -u postgres createdb mydatabase
50+
$ sudo -u postgres psql
51+
psql (13.5)
52+
Type "help" for help.
53+
54+
postgres=# GRANT ALL PRIVILEGES ON DATABASE mydatabase TO myuser;
3955

56+
ALTER USER myuser WITH PASSWORD 'new_password';
4057

4158
## Getting Started with Create React App
4259

docker-compose.yml

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,12 @@ services:
44
context: .
55
dockerfile: Dockerfile.api
66
image: amazon-clone-flask-api
7-
command: gunicorn -b :5000 server:app
7+
command: bash -c "gunicorn server:create_app1"
88
environment:
9+
- GUNICORN_BIND=0.0.0.0:5000
10+
- GUNICORN_WORKERS=2
11+
- GUNICORN_THREADS=4
12+
- GUNICORN_TIMEOUT=0
913
- TWILIO_ACCOUNT_SID=${TWILIO_ACCOUNT_SID}
1014
- TWILIO_AUTH_TOKEN=${TWILIO_AUTH_TOKEN}
1115
- PGHOST=db
@@ -19,6 +23,8 @@ services:
1923
- "5000:5000"
2024
depends_on:
2125
- db
26+
volumes:
27+
- .:/app
2228
client:
2329
build:
2430
context: .

entrypoint.sh

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,10 @@ then
1111
echo "PostgreSQL started"
1212
fi
1313

14-
python3 manage.py create_db
15-
python3 manage.py create_test_user
16-
python3 manage.py create_test_product_and_order
14+
15+
python3 manage.py create_db
16+
python3 manage.py create_test_user
17+
python3 manage.py create_test_product_and_order
1718

1819

1920
exec "$@"

nginx.conf

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,15 @@
1-
upstream hello_flask {
2-
server api:5000;
3-
}
4-
51
server {
62
listen 80;
3+
server_name localhost;
74

85
location / {
9-
proxy_pass http://api;
10-
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
6+
proxy_pass http://api:5000;
117
proxy_set_header Host $host;
12-
proxy_redirect off;
8+
proxy_set_header X-Real-IP $remote_addr;
139
}
1410

1511
location /assets/ {
1612
alias /app/src/assets;
1713
}
1814
}
15+

0 commit comments

Comments
 (0)