Skip to content

Commit 58cf3ae

Browse files
committed
🚀 add deployment layers
1 parent f10d6ba commit 58cf3ae

File tree

7 files changed

+76
-8
lines changed

7 files changed

+76
-8
lines changed

Dockerfile

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,12 @@ WORKDIR /usr/src/app
66

77
RUN apk add --update --no-cache postgresql-client
88
RUN apk add --update --no-cache --virtual .tmp-build-deps \
9-
postgresql-dev gcc python3-dev musl-dev
9+
postgresql-dev gcc python3-dev musl-dev linux-headers
1010

1111
COPY requirements.txt ./
12-
RUN pip install --no-cache-dir -r requirements.txt
12+
COPY ./scripts /scripts
13+
14+
RUN pip install -r requirements.txt
1315

1416
RUN apk del .tmp-build-deps
1517

@@ -18,14 +20,20 @@ RUN adduser --disabled-password app-user
1820
RUN mkdir -p /usr/src/vol/web/static && \
1921
mkdir -p /usr/src/vol/web/media && \
2022
chown -R app-user:app-user /usr/src/vol && \
21-
chmod -R 755 /usr/src/vol
23+
chmod -R 755 /usr/src/vol && \
24+
chmod -R +x /scripts
2225

23-
USER app-user
26+
ENV PATH="/scripts:$PATH"
2427

2528
COPY messages ./messages/
2629

30+
WORKDIR /usr/src/app/messages/
31+
2732
EXPOSE 8000
2833

2934
COPY entrypoint.sh .
35+
RUN chmod +x entrypoint.sh
36+
37+
USER app-user
3038

31-
ENTRYPOINT ["sh", "entrypoint.sh"]
39+
CMD ["run.sh"]

docker-compose-deploy.yml

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
version: '3'
2+
services:
3+
web:
4+
build:
5+
context: .
6+
dockerfile: Dockerfile
7+
restart: always
8+
image: messages-web-image
9+
container_name: messages-web-container
10+
volumes:
11+
- static-data:/usr/src/vol/web
12+
environment:
13+
- DEBUG=${DEBUG}
14+
- DB_HOST=db
15+
- DB_NAME=${DB_NAME}
16+
- DB_USER=${DB_USER}
17+
- DB_PASSWORD=${DB_PASSWORD}
18+
- SECRET_KEY=${SECRET_KEY}
19+
- ALLOWED_HOSTS=${ALLOWED_HOSTS}
20+
depends_on:
21+
- db
22+
redis:
23+
image: redis:7
24+
restart: always
25+
container_name: messages-redis-container
26+
ports:
27+
- 6379:6379
28+
db:
29+
image: postgres:15
30+
restart: always
31+
volumes:
32+
- db_data:/var/lib/postgresql/data/
33+
environment:
34+
- POSTGRES_DB=${DB_NAME}
35+
- POSTGRES_USER=${DB_USER}
36+
- POSTGRES_PASSWORD=${DB_PASSWORD}
37+
proxy:
38+
build:
39+
context: ./proxy
40+
restart: always
41+
depends_on:
42+
- web
43+
ports:
44+
- 80:8000
45+
volumes:
46+
- static-data:/vol/static
47+
48+
volumes:
49+
static-data:
50+
db_data:

docker-compose.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ services:
44
build:
55
context: .
66
dockerfile: Dockerfile
7+
entrypoint: ./entrypoint.sh
78
image: messages-web-image
89
container_name: messages-web-container
910
ports:
@@ -13,7 +14,6 @@ services:
1314
- ./messages:/usr/src/app/messages
1415
- ./data/web:/usr/src/vol/web
1516
environment:
16-
- SECRET_KEY=this-is-a-dev-secret-key
1717
- DEBUG=${DEBUG}
1818
- DB_HOST=db
1919
- DB_NAME=${DB_NAME}

entrypoint.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
#!/bin/bash
1+
#!/bin/sh
22

33
python messages/manage.py wait_for_db
44
python messages/manage.py migrate --no-input

proxy/default.conf.tpl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ server {
22
listen ${LISTEN_PORT};
33

44
location /static {
5-
alias /usr/src/vol/web/static;
5+
alias /vol/static;
66
}
77

88
location / {

requirements.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ toml==0.10.2
4444
Twisted==22.10.0
4545
txaio==22.2.1
4646
typing_extensions==4.4.0
47+
uWSGI==2.0.21
4748
virtualenv==20.16.6
4849
wrapt==1.14.1
4950
zope.interface==5.5.1

scripts/run.sh

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
#!/bin/sh
2+
3+
set -e
4+
5+
python manage.py wait_for_db
6+
python manage.py collectstatic --noinput
7+
python manage.py migrate
8+
9+
uwsgi --socket :9000 --workers 4 --master --enable-threads --module messages.wsgi

0 commit comments

Comments
 (0)