Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit88b814d

Browse files
authored
Merge pull requestalexmojaki#13 from alexmojaki/tidy-docker
Tidy docker
2 parents077b7e3 +7fcfe95 commit88b814d

File tree

11 files changed

+61
-133
lines changed

11 files changed

+61
-133
lines changed

‎Dockerfile‎

Lines changed: 11 additions & 18 deletions
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‎

Lines changed: 0 additions & 2 deletions
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‎

Lines changed: 7 additions & 8 deletions
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‎

Lines changed: 0 additions & 25 deletions
This file was deleted.

‎backend/gunicorn_config_web.py‎

Lines changed: 4 additions & 0 deletions
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‎

Lines changed: 5 additions & 0 deletions
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‎

Lines changed: 2 additions & 1 deletion
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‎

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ def __init__(self):
2323
self.result_queue=Queue()
2424
self.awaiting_input=False
2525
self.process=None
26+
self.fresh_process=True
2627
self.start_process()
2728

2829
@atexit.register
@@ -31,6 +32,7 @@ def cleanup():
3132
self.process.terminate()
3233

3334
defstart_process(self):
35+
self.fresh_process=True
3436
self.process=Process(
3537
target=worker_loop_in_thread,
3638
args=(self.task_queue,self.input_queue,self.result_queue),
@@ -62,12 +64,11 @@ def await_result(self):
6264
def_await_result(self):
6365
# TODO cancel if result was cancelled by a newer handle_entry
6466
result=None
65-
# TODO handle initial timeout better
66-
timeout=10
6767
whileresultisNone:
68+
timeout=10ifself.fresh_processelse3
6869
try:
6970
result=self.result_queue.get(timeout=timeout)
70-
timeout=3
71+
assert (resultisNone)==self.fresh_process
7172
exceptqueue.Empty:
7273
alive=self.process.is_alive()
7374
print(f"Process{alive=}")
@@ -82,14 +83,19 @@ def _await_result(self):
8283
],
8384
output='The process died.',
8485
)
86+
self.fresh_process=False
8587
returnresult
8688

8789

8890
user_processes=defaultdict(UserProcess)
8991

9092
app=flask.Flask(__name__)
9193

92-
multiprocessing.set_start_method("spawn")
94+
try:
95+
multiprocessing.set_start_method("spawn")
96+
exceptRuntimeError:
97+
# noinspection PyArgumentList
98+
assertmultiprocessing.get_start_method()=="spawn"
9399

94100

95101
@app.route("/run",methods=["POST"])
@@ -112,9 +118,6 @@ def run_server():
112118
app.run(host="0.0.0.0")
113119

114120

115-
master_url="http://localhost:5000/"
116-
117-
118121
@lru_cache()
119122
defmaster_session():
120123
importrequests
@@ -130,7 +133,7 @@ def master_session():
130133
# Wait until alive
131134
whileTrue:
132135
try:
133-
session.get(master_url+"health")
136+
session.get(simple_settings.MASTER_URL+"health")
134137
break
135138
exceptrequests.exceptions.ConnectionError:
136139
sleep(1)
@@ -140,7 +143,7 @@ def master_session():
140143

141144
defworker_result(entry):
142145
session=master_session()
143-
returnsession.post(master_url+"run",json=entry).json()
146+
returnsession.post(simple_settings.MASTER_URL+"run",json=entry).json()
144147

145148

146149
if__name__=='__main__':

‎backend/master_server.sh‎

Lines changed: 9 additions & 0 deletions
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‎

Lines changed: 0 additions & 61 deletions
This file was deleted.

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp