Skip to content

Commit 7fcfe95

Browse files
committed
Tidy up docker setup
1 parent 0fe0199 commit 7fcfe95

11 files changed

+51
-129
lines changed

Dockerfile

+11-18
Original file line numberDiff line numberDiff line change
@@ -11,31 +11,26 @@ RUN npm run build
1111
# Stage 2 - Setup server
1212
FROM ubuntu:18.04
1313

14-
RUN apt-get update \
15-
&& DEBIAN_FRONTEND=noninteractive apt-get install -y \
14+
RUN apt-get update
15+
16+
RUN apt-get install -y software-properties-common curl
17+
RUN (cd /etc/apt/trusted.gpg.d/ && curl -O https://www.postgresql.org/media/keys/ACCC4CF8.asc)
18+
RUN echo "deb http://apt.postgresql.org/pub/repos/apt/ $(lsb_release -cs)"-pgdg main > /etc/apt/sources.list.d/pgdg.list
19+
RUN apt-get update
20+
21+
RUN DEBIAN_FRONTEND=noninteractive apt-get install -y \
1622
python3.8-dev \
17-
unzip \
18-
nginx \
19-
curl \
2023
vim \
2124
python3.8-distutils \
22-
gcc
25+
gcc \
26+
postgresql-client-12 \
27+
libpq-dev
2328

2429
RUN ln -s /usr/bin/python3.8 /usr/local/bin/python
25-
RUN python --version
2630
RUN curl https://bootstrap.pypa.io/get-pip.py -o get-pip.py
2731
RUN python get-pip.py
28-
RUN pip --version
2932
RUN pip install poetry
3033

31-
RUN apt-get install -y software-properties-common
32-
RUN (cd /etc/apt/trusted.gpg.d/ && curl -O https://www.postgresql.org/media/keys/ACCC4CF8.asc)
33-
RUN echo "deb http://apt.postgresql.org/pub/repos/apt/ $(lsb_release -cs)"-pgdg main > /etc/apt/sources.list.d/pgdg.list
34-
RUN apt-get update -y
35-
RUN apt-get install -y postgresql-client-12 libpq-dev
36-
37-
#RUN curl -s https://packagecloud.io/install/repositories/rabbitmq/rabbitmq-server/script.deb.sh | bash
38-
3934
WORKDIR /usr/src/app
4035
COPY poetry.lock pyproject.toml ./
4136
RUN poetry config virtualenvs.create false
@@ -46,8 +41,6 @@ COPY ./backend ./backend
4641
WORKDIR /usr/src/app/backend
4742
RUN ./manage.py collectstatic --noinput
4843

49-
COPY ./backend/nginx.conf /etc/nginx
50-
5144
EXPOSE 3000
5245

5346
CMD ["bash", "./entrypoint.sh"]

backend/book/settings.py

-2
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,6 @@
3333

3434
GITHUB_TOKEN = os.environ.get('GITHUB_TOKEN')
3535

36-
SEPARATE_WORKER_PROCESS = os.environ.get('SEPARATE_WORKER_PROCESS', 'False')[0].upper() == 'T'
37-
3836
ALLOWED_HOSTS = [
3937
'alexmojaki.pythonanywhere.com',
4038
os.environ.get('HEROKU_APP_NAME', '') + '.herokuapp.com',

backend/entrypoint.sh

+7-8
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,16 @@
11
#!/usr/bin/env bash
2-
set -ex
32

4-
#nginx
3+
set -eux
54

65
# We probably don't want this to be automatic but it makes life a lot easier
76
# For setting up the cloud
87
python manage.py migrate
98
python manage.py init_db
109

11-
# Prevent outdated from making http requests
12-
echo '["0.2.0", "2099-01-01 00:00:00"]' > /tmp/outdated_cache_outdated
13-
echo '["0.8.3", "2099-01-01 00:00:00"]' > /tmp/outdated_cache_birdseye
10+
# If no MASTER_URL is set, start a server in this container,
11+
# which the web server will contact by default
12+
if [ -z ${MASTER_URL+x} ]; then
13+
./master_server.sh &
14+
fi
1415

15-
gunicorn --bind 127.0.0.1:5000 main.workers.master:app --access-logfile - --error-log - --threads 10 --worker-class gthread &
16-
17-
gunicorn -c gunicorn_config.py book.wsgi:application --bind 0.0.0.0:${PORT:-3000}
16+
gunicorn -c gunicorn_config_web.py book.wsgi:application --bind 0.0.0.0:${PORT:-3000}

backend/gunicorn_config.py

-25
This file was deleted.

backend/gunicorn_config_web.py

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
worker_class = 'gevent'
2+
keepalive = 60
3+
accesslog = '-'
4+
errorlog = '-'

backend/gunicorn_config_worker.py

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
bind = "0.0.0.0:5000"
2+
threads = 10
3+
worker_class = "gthread"
4+
accesslog = '-'
5+
errorlog = '-'

backend/main/simple_settings.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -12,5 +12,6 @@
1212
send_default_pii=True
1313
)
1414

15-
CLOUDAMQP_URL = os.environ.get('CLOUDAMQP_URL')
1615
SEPARATE_WORKER_PROCESS = os.environ.get('SEPARATE_WORKER_PROCESS', 'False')[0].upper() == 'T'
16+
17+
MASTER_URL = os.environ.get('MASTER_URL', "http://localhost:5000/")

backend/main/workers/master.py

+2-5
Original file line numberDiff line numberDiff line change
@@ -118,9 +118,6 @@ def run_server():
118118
app.run(host="0.0.0.0")
119119

120120

121-
master_url = "http://localhost:5000/"
122-
123-
124121
@lru_cache()
125122
def master_session():
126123
import requests
@@ -136,7 +133,7 @@ def master_session():
136133
# Wait until alive
137134
while True:
138135
try:
139-
session.get(master_url + "health")
136+
session.get(simple_settings.MASTER_URL + "health")
140137
break
141138
except requests.exceptions.ConnectionError:
142139
sleep(1)
@@ -146,7 +143,7 @@ def master_session():
146143

147144
def worker_result(entry):
148145
session = master_session()
149-
return session.post(master_url + "run", json=entry).json()
146+
return session.post(simple_settings.MASTER_URL + "run", json=entry).json()
150147

151148

152149
if __name__ == '__main__':

backend/master_server.sh

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
#!/usr/bin/env bash
2+
3+
set -eux
4+
5+
# Prevent outdated from making http requests
6+
echo '["0.2.0", "2099-01-01 00:00:00"]' >/tmp/outdated_cache_outdated
7+
echo '["0.8.3", "2099-01-01 00:00:00"]' >/tmp/outdated_cache_birdseye
8+
9+
gunicorn -c gunicorn_config_worker.py main.workers.master:app

backend/nginx.conf

-61
This file was deleted.

docker-compose.yml

+11-9
Original file line numberDiff line numberDiff line change
@@ -13,17 +13,19 @@ services:
1313
environment:
1414
SEPARATE_WORKER_PROCESS: 'True'
1515
DATABASE_URL: postgres://postgres:pass@database/postgres
16+
DEBUG: 'False'
17+
MASTER_URL: http://master:5000/
1618
stdin_open: true
1719
tty: true
18-
# worker:
19-
# image: python-init
20-
# build: .
21-
# env_file: .env
22-
# stdin_open: true
23-
# tty: true
24-
# entrypoint: gunicorn --threads 10 --bind 0.0.0.0:5000 main.workers.master:app
25-
# ports:
26-
# - 5000:5000
20+
master:
21+
image: python-init
22+
build: .
23+
env_file: .env
24+
stdin_open: true
25+
tty: true
26+
entrypoint: ./master_server.sh
27+
ports:
28+
- 5000:5000
2729
database:
2830
image: postgres:12
2931
volumes:

0 commit comments

Comments
 (0)