Skip to content

Commit

Permalink
Merge pull request #30 from 2024-Techeer-Summer-Bootcamp-Team-D/chore/#…
Browse files Browse the repository at this point in the history
…29

[chore] green-blue 무중단 배포 적용
  • Loading branch information
GiHwan2 authored Jul 28, 2024
2 parents 16459e3 + f7e5f7d commit a492d4e
Show file tree
Hide file tree
Showing 11 changed files with 71 additions and 68 deletions.
2 changes: 1 addition & 1 deletion MVStudio-Backend
Submodule MVStudio-Backend updated 198 files
40 changes: 12 additions & 28 deletions docker-compose-dev.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,25 +24,25 @@ services:
networks:
- mvs

celery-worker-1:
celery:
build:
context: ./MVStudio-Backend
command: celery -A config worker --loglevel=info --concurrency=6 -Q celery,music_queue,video_queue,final_queue
depends_on:
- rabbitmq
- redis
networks:
- mvs

celery-worker-2:
build:
context: ./MVStudio-Backend
command: celery -A config worker --loglevel=info --concurrency=6 -Q celery,music_queue,video_queue,final_queue
ports:
- '5555:5555'
depends_on:
- rabbitmq
- redis
networks:
- mvs
command: >
sh -c "
celery -A config worker --loglevel=info --concurrency=2 -n worker_1_@%h &
celery -A config worker --loglevel=info --concurrency=2 -Q music_queue -n worker_2_@%h &
celery -A config worker --loglevel=info --concurrency=10 -Q video_queue -n worker_3_@%h &
celery -A config worker --loglevel=info --concurrency=2 -Q final_queue -n worker_4_@%h &
celery -A config flower --port=5555 --broker=$CELERY_BROKER_URL --broker-api=http://guest:guest@rabbitmq:15672/api/"
environment:
- CELERY_BROKER_URL=amqp://guest:guest@rabbitmq:5672/

celery-beat:
build:
Expand All @@ -54,22 +54,6 @@ services:
networks:
- mvs

flower:
image: mher/flower:0.9.7
build:
context: ./MVStudio-Backend
working_dir: /MVStudio-Backend
command: celery flower --port=5555 --broker=$CELERY_BROKER_URL --broker-api=http://guest:guest@rabbitmq:15672/api/
ports:
- '5555:5555'
depends_on:
rabbitmq:
condition: service_healthy
environment:
- CELERY_BROKER_URL=amqp://guest:guest@rabbitmq:5672/
networks:
- mvs

elasticsearch:
image: docker.elastic.co/elasticsearch/elasticsearch:7.10.1
environment:
Expand Down
82 changes: 48 additions & 34 deletions docker-compose-prod.yml
Original file line number Diff line number Diff line change
Expand Up @@ -40,25 +40,25 @@ services:
networks:
- mvs

celery-worker-1:
celery:
build:
context: ./MVStudio-Backend
command: celery -A config worker --loglevel=info --concurrency=2 -Q celery,music_queue,video_queue,final_queue
depends_on:
- rabbitmq
- redis
networks:
- mvs

celery-worker-2:
build:
context: ./MVStudio-Backend
command: celery -A config worker --loglevel=info --concurrency=2 -Q celery,music_queue,video_queue,final_queue
ports:
- '5555:5555'
depends_on:
- rabbitmq
- redis
networks:
- mvs
command: >
sh -c "
celery -A config worker --loglevel=info --concurrency=2 -n worker_1_@%h &
celery -A config worker --loglevel=info --concurrency=2 -Q music_queue -n worker_2_@%h &
celery -A config worker --loglevel=info --concurrency=10 -Q video_queue -n worker_3_@%h &
celery -A config worker --loglevel=info --concurrency=2 -Q final_queue -n worker_4_@%h &
celery -A config flower --port=5555 --broker=$CELERY_BROKER_URL --broker-api=http://guest:guest@rabbitmq:15672/api/"
environment:
- CELERY_BROKER_URL=amqp://guest:guest@rabbitmq:5672/

celery-beat:
build:
Expand All @@ -70,22 +70,6 @@ services:
networks:
- mvs

flower:
image: mher/flower:0.9.7
build:
context: ./MVStudio-Backend
working_dir: /MVStudio-Backend
command: celery flower --port=5555 --broker=$CELERY_BROKER_URL --broker-api=http://guest:guest@rabbitmq:15672/api/
ports:
- '5555:5555'
depends_on:
rabbitmq:
condition: service_healthy
environment:
- CELERY_BROKER_URL=amqp://guest:guest@rabbitmq:5672/
networks:
- mvs

elasticsearch:
image: docker.elastic.co/elasticsearch/elasticsearch:7.10.1
environment:
Expand Down Expand Up @@ -115,8 +99,8 @@ services:
networks:
- mvs

backend:
container_name: MVStudio-Backend
backend-blue:
container_name: MVStudio-Backend-blue
build:
context: ./MVStudio-Backend
volumes:
Expand All @@ -142,7 +126,40 @@ services:
python manage.py makemigrations member &&
python manage.py makemigrations music_videos &&
python manage.py migrate &&
python manage.py search_index --create &&
if [ '$$INIT_INDEX' = 'false' ]; then
python manage.py search_index --create &&
export INIT_INDEX=true
fi &&
python manage.py search_index --rebuild -f&&
gunicorn --bind 0.0.0.0:8000 config.wsgi:application -w 2"
backend-green:
container_name: MVStudio-Backend-green
build:
context: ./MVStudio-Backend
volumes:
- static_volume:/MVStudio-Backend/static
- ./MVStudio-Backend:/MVStudio-Backend
ports:
- '8001:8000'
depends_on:
redis:
condition: service_started
rabbitmq:
condition: service_started
elasticsearch:
condition: service_healthy
# db:
# condition: service_started
networks:
- mvs
restart: always
command: >
sh -c "
python manage.py makemigrations &&
python manage.py makemigrations member &&
python manage.py makemigrations music_videos &&
python manage.py migrate &&
python manage.py search_index --rebuild -f&&
gunicorn --bind 0.0.0.0:8000 config.wsgi:application -w 2"
Expand All @@ -155,8 +172,6 @@ services:
- ./MVStudio-Frontend/:/MVStudio-Frontend
- build_folder:/MVStudio-Frontend/dist
- ./MVStudio-Frontend/node_modules/:/MVStudio-Frontend/node_modules
depends_on:
- backend
tty: true

nginx:
Expand All @@ -173,7 +188,6 @@ services:
- ./certbot/www:/var/www/certbot
depends_on:
- frontend
- backend
networks:
- mvs

Expand Down
4 changes: 2 additions & 2 deletions docker-compose.prod.yml
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ services:
networks:
- mvs

celery-worker:
celery:
build:
context: ./MVStudio-Backend
ports:
Expand All @@ -53,7 +53,7 @@ services:
- mvs
command: >
sh -c "
celery -A config worker --loglevel=info --concurrency=2 -Q celery -n worker_1_@%h &
celery -A config worker --loglevel=info --concurrency=2 -n worker_1_@%h &
celery -A config worker --loglevel=info --concurrency=2 -Q music_queue -n worker_2_@%h &
celery -A config worker --loglevel=info --concurrency=10 -Q video_queue -n worker_3_@%h &
celery -A config worker --loglevel=info --concurrency=2 -Q final_queue -n worker_4_@%h &
Expand Down
1 change: 1 addition & 0 deletions nginx/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,6 @@ FROM nginx:latest

RUN rm /etc/nginx/conf.d/default.conf
COPY nginx.conf /etc/nginx/conf.d
COPY app /etc/nginx/conf.d/app

CMD [ "nginx", "-g", "daemon off;" ]
1 change: 1 addition & 0 deletions nginx/app/service-url-blue.inc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
set $service_url "http://backend-blue:8000";
1 change: 1 addition & 0 deletions nginx/app/service-url-green.inc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
set $service_url "http://backend-green:8001";
1 change: 1 addition & 0 deletions nginx/app/service-url.inc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
set $service_url "http://backend-blue:8000";
3 changes: 2 additions & 1 deletion nginx/nginx.conf
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ server {
}

server{
include /etc/nginx/conf.d/app/service-url.inc;
listen 443 ssl;
server_name mvstudio.pro;
charset utf-8;
Expand All @@ -30,7 +31,7 @@ server{
ssl_dhparam /etc/letsencrypt/ssl-dhparams.pem;

location /api {
proxy_pass http://backend:8000;
proxy_pass $service_url;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
Expand Down
2 changes: 1 addition & 1 deletion prometheus/prometheus.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ scrape_configs:
- targets: [ 'nginx-exporter:9113' ] #<서비스_이름>:<포트>
- job_name: 'celery-data' #job 이름
static_configs:
- targets: [ 'celery-worker:5555' ] #<서비스_이름>:<포트>
- targets: [ 'celery:5555' ] #<서비스_이름>:<포트>
- job_name: 'rabbitmq-data' #job 이름
static_configs:
- targets: [ 'rabbitmq:15692' ] #<서비스_이름>:<포트>
Expand Down

0 comments on commit a492d4e

Please sign in to comment.