Skip to content

Commit 471831c

Browse files
authored
Merge pull request #59 from codeguru42/50-deploy
50 deploy
2 parents 05191ec + 1f673ee commit 471831c

File tree

6 files changed

+53
-18
lines changed

6 files changed

+53
-18
lines changed

.gitignore

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
.idea
2-
.env
2+
*.env
33

44
*.png
55
*.jpg

Dockerfile

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
FROM python:3.11-slim-buster
22

3-
RUN apt update
4-
RUN apt install libgl1 libglib2.0-0 -y
3+
RUN apt update && apt install libgl1 libglib2.0-0 -y
54

65
RUN useradd -ms /bin/bash api
76
USER api
@@ -12,5 +11,3 @@ ENV PATH=/home/api/.local/bin:${PATH}
1211
COPY pyproject.toml poetry.lock ./
1312
RUN poetry install
1413
COPY . ./
15-
16-
CMD poetry run gunicorn go_capture.wsgi:application --bind 0.0.0.0:8000 -t 60

deploy.sh

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
#!/bin/bash
2-
export image_hash=$1
3-
export account_id=$(aws sts get-caller-identity --query Account --output text)
4-
aws ecr get-login-password | docker login --username AWS --password-stdin ${account_id}.dkr.ecr.us-west-1.amazonaws.com \
5-
&& docker compose down \
6-
&& docker compose up -d
2+
export IMAGE=$1
3+
export TAG=$2
4+
echo echo "Take down old api version..." \
5+
&& docker compose -f docker-compose-prod.yml down \
6+
&& echo "Bring up new api version..." \
7+
&& docker compose -f docker-compose-prod.yml -p go-capture-api up -d

docker-compose-dev.yml

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,15 @@ services:
33
build: .
44
command: "poetry run python3 /api/manage.py runserver 0.0.0.0:8000"
55
env_file:
6-
- .env
6+
- env/dev.env
77
environment:
88
- CELERY_BROKER_URL=amqp://guest:guest@broker:5672
9+
- FIREBASE_CREDENTIALS_FILE=/run/secrets/firebase-credentials
10+
- MEDIA_ROOT=/api/media
911
ports:
1012
- 8000:8000
13+
secrets:
14+
- firebase-credentials
1115
volumes:
1216
- .:/api
1317
worker:
@@ -18,12 +22,20 @@ services:
1822
environment:
1923
- CELERY_BROKER_URL=amqp://guest:guest@broker:5672
2024
- CELERY_RESULT_BACKEND=rpc
25+
- FIREBASE_CREDENTIALS_FILE=/run/secrets/firebase-credentials
26+
- MEDIA_ROOT=/api/media
2127
env_file:
22-
- .env
28+
- env/dev.env
29+
secrets:
30+
- firebase-credentials
2331
volumes:
2432
- .:/api
2533
broker:
2634
image: rabbitmq:3-management
2735
ports:
2836
- 5672:5672
2937
- 15672:15672
38+
39+
secrets:
40+
firebase-credentials:
41+
file: $FIREBASE_CREDENTIALS_FILE

docker-compose-prod.yml

Lines changed: 30 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,49 @@
11
services:
22
api:
3-
image: ${image}:${tag}
4-
env_file:
5-
- .env
3+
command: "poetry run gunicorn go_capture.wsgi:application --bind 0.0.0.0:8000 -t 60"
64
environment:
75
- CELERY_BROKER_URL=amqp://guest:guest@broker:5672
6+
- FIREBASE_CREDENTIALS_FILE=/run/secrets/firebase-credentials
7+
- MEDIA_ROOT=/api/media
8+
env_file:
9+
- env/prod.env
10+
image: ${IMAGE}:${TAG}
811
ports:
912
- 8000:8000
13+
secrets:
14+
- firebase-credentials
15+
volumes:
16+
- media:/api/media
1017
worker:
11-
image: ${image}:${tag}
1218
command: "poetry run celery -A go_capture.tasks worker"
1319
depends_on:
1420
- broker
1521
environment:
1622
- CELERY_BROKER_URL=amqp://guest:guest@broker:5672
1723
- CELERY_RESULT_BACKEND=rpc
24+
- FIREBASE_CREDENTIALS_FILE=/run/secrets/firebase-credentials
25+
- MEDIA_ROOT=/api/media
1826
env_file:
19-
- .env
27+
- env/prod.env
28+
image: ${IMAGE}:${TAG}
29+
secrets:
30+
- firebase-credentials
31+
volumes:
32+
- media:/api/media
2033
broker:
2134
image: rabbitmq:3-management
2235
ports:
2336
- 5672:5672
2437
- 15672:15672
38+
39+
volumes:
40+
media:
41+
driver: local
42+
driver_opts:
43+
type: none
44+
o: bind
45+
device: $MEDIA_ROOT
46+
47+
secrets:
48+
firebase-credentials:
49+
file: $FIREBASE_CREDENTIALS_FILE

go_capture/settings.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,7 @@
125125
DEFAULT_AUTO_FIELD = "django.db.models.BigAutoField"
126126

127127
MEDIA_URL = "media/"
128-
MEDIA_ROOT = BASE_DIR / "media"
128+
MEDIA_ROOT = env.path("MEDIA_ROOT")
129129
MEDIA_ROOT.mkdir(exist_ok=True)
130130

131131
IMAGES_DIR = MEDIA_ROOT / "images"

0 commit comments

Comments
 (0)