Skip to content

Commit

Permalink
chore-be: prod 환경 docker-compose.prod.yml 수정 (#858)
Browse files Browse the repository at this point in the history
Co-authored-by: Do Yeop Kim <113661364+Dobby-Kim@users.noreply.github.com>
Co-authored-by: Leetaehoon <66353672+xogns1514@users.noreply.github.com>
  • Loading branch information
3 people committed Oct 21, 2024
1 parent 65de64b commit c135aed
Show file tree
Hide file tree
Showing 2 changed files with 203 additions and 41 deletions.
188 changes: 162 additions & 26 deletions .github/workflows/be-cd_prod-docker.yml
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,82 @@ jobs:
run:
working-directory: backend
steps:

- name: Set reviewer and sender variables
run: |
ASSIGNEE_LOGIN=${{ github.event.sender }}
echo "SENDER_SLACK_ID=${ASSIGNEE_LOGIN@L}" >> ${GITHUB_ENV}
- name: 배포시작 알림
uses: slackapi/slack-github-action@v1.26.0
with:
channel-id: C07S8K0PHTQ
payload: |
{
"blocks": [
{
"type": "divider"
},
{
"type": "header",
"text": {
"type": "plain_text",
"text": "🚀 운영 배포 시작 🚀",
"emoji": true
}
},
{
"type": "section",
"fields": [
{
"type": "mrkdwn",
"text": "*배포자:*\n <@${{ env.SENDER_SLACK_ID }}>"
}
]
},
{
"type": "section",
"fields": [
{
"type": "mrkdwn",
"text": "🚀 *배포 버전:*\n${{ inputs.release-ver }}"
}
]
},
{
"type": "section",
"fields": [
{
"type": "mrkdwn",
"text": "🚀 *롤백 버전:*\n${{ inputs.rollback-ver }}"
}
]
},
{
"type": "actions",
"elements": [
{
"type": "button",
"text": {
"type": "plain_text",
"text": "🕹️ Action 실행 현황 🕹️",
"emoji": true
},
"value": "PR_LINK",
"url": "${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}",
"action_id": "actionId-1"
}
]
},
{
"type": "divider"
}
]
}
env:
SLACK_BOT_TOKEN: ${{ secrets.SLACK_BOT_TOKEN }}

- name: Set docker-compose YAML script to runner
uses: actions/download-artifact@v4
with:
Expand All @@ -98,14 +174,15 @@ jobs:
# DB server configuration secrets info from Github Secrets
APP_IP_ADDRESS=${{ secrets.APP_IP_ADDRESS }}
SERVER_BINDING_PORT=${{ secrets.SERVER_BINDING_PORT }}
SERVER_PORT=${{ secrets.SERVER_PORT }}
SUBNET=${{ secrets.SUBNET }}
BLUE_SERVER_BINDING_PORT=${{ secrets.BLUE_SERVER_BINDING_PORT }}
GREEN_SERVER_BINDING_PORT=${{ secrets.GREEN_SERVER_BINDING_PORT }}
BLUE_SERVER_PORT=${{ secrets.BLUE_SERVER_PORT }}
GREEN_SERVER_PORT=${{ secrets.GREEN_SERVER_PORT }}
# Monitoring configuration server info from Github secrets
MONITORING_INSTANCE_ADDR_LOKI_PORT=${{ secrets.MONITORING_INSTANCE_ADDR_LOKI_PORT }}
MONITORING_BINDING_PORT=${{ secrets.MONITORING_BINDING_PORT }}
MONITORING_PORT=${{ secrets.MONITORING_PORT }}
BLUE_MONITORING_BINDING_PORT=${{ secrets.BLUE_MONITORING_BINDING_PORT }}
GREEN_MONITORING_BINDING_PORT=${{ secrets.GREEN_MONITORING_BINDING_PORT }}
MONITORING_BASE_PATH=${{ secrets.MONITORING_BASE_PATH }}
MONITORING_PROFILE=${{ secrets.MONITORING_PROFILE }}
Expand Down Expand Up @@ -139,16 +216,45 @@ jobs:
REDIS_PASSWORD=${{ secrets.REDIS_PASSWORD }}
EOF
- name: Stop and remove existing containers
- name: Run zero down time Deploy Script
run: |
sudo docker-compose -f docker-compose.prod.yml down --rmi all
chmod +x ../deploy.sh
../deploy.sh
- name: Deploy docker container
run: |
sudo docker-compose --env-file .env -f docker-compose.prod.yml up -d
- name: Run server status check script with timeout
run: ../check_server_status_with_timeout.sh
- name: 배포시작 알림
uses: slackapi/slack-github-action@v1.26.0
with:
channel-id: C07S8K0PHTQ
payload: |
{
"blocks": [
{
"type": "divider"
},
{
"type": "header",
"text": {
"type": "plain_text",
"text": "👍🏻 운영 배포 완료 👍🏻",
"emoji": true
}
},
{
"type": "section",
"fields": [
{
"type": "mrkdwn",
"text": "🚀 *배포 버전:*\n${{ inputs.release-ver }}"
}
]
},
{
"type": "divider"
}
]
}
env:
SLACK_BOT_TOKEN: ${{ secrets.SLACK_BOT_TOKEN }}

roll-back-on-fail:
environment: prod
Expand Down Expand Up @@ -182,14 +288,15 @@ jobs:
# DB server configuration secrets info from Github Secrets
APP_IP_ADDRESS=${{ secrets.APP_IP_ADDRESS }}
SERVER_BINDING_PORT=${{ secrets.SERVER_BINDING_PORT }}
SERVER_PORT=${{ secrets.SERVER_PORT }}
SUBNET=${{ secrets.SUBNET }}
BLUE_SERVER_BINDING_PORT=${{ secrets.BLUE_SERVER_BINDING_PORT }}
GREEN_SERVER_BINDING_PORT=${{ secrets.GREEN_SERVER_BINDING_PORT }}
BLUE_SERVER_PORT=${{ secrets.BLUE_SERVER_PORT }}
GREEN_SERVER_PORT=${{ secrets.GREEN_SERVER_PORT }}

# Monitoring configuration server info from Github secrets
MONITORING_INSTANCE_ADDR_LOKI_PORT=${{ secrets.MONITORING_INSTANCE_ADDR_LOKI_PORT }}
MONITORING_BINDING_PORT=${{ secrets.MONITORING_BINDING_PORT }}
MONITORING_PORT=${{ secrets.MONITORING_PORT }}
BLUE_MONITORING_BINDING_PORT=${{ secrets.BLUE_MONITORING_BINDING_PORT }}
GREEN_MONITORING_BINDING_PORT=${{ secrets.GREEN_MONITORING_BINDING_PORT }}
MONITORING_BASE_PATH=${{ secrets.MONITORING_BASE_PATH }}
MONITORING_PROFILE=${{ secrets.MONITORING_PROFILE }}

Expand Down Expand Up @@ -218,13 +325,42 @@ jobs:
COOKIE_MAX_AGE=${{ secrets.COOKIE_MAX_AGE }}
EOF

- name: Stop and remove existing containers
run: |
sudo docker-compose -f docker-compose.prod.yml down --rmi all
- name: Deploy docker container
- name: Run zero down time Deploy Script
run: |
sudo docker-compose --env-file .env -f docker-compose.prod.yml up -d
chmod +x ../deploy.sh
../deploy.sh
- name: Run server status check script with timeout
run: ../check_server_status_with_timeout.sh
- name: 배포시작 알림
uses: slackapi/slack-github-action@v1.26.0
with:
channel-id: C07S8K0PHTQ
payload: |
{
"blocks": [
{
"type": "divider"
},
{
"type": "header",
"text": {
"type": "plain_text",
"text": "❌ 운영 배포 실패 및 롤백 ❌",
"emoji": true
}
},
{
"type": "section",
"fields": [
{
"type": "mrkdwn",
"text": "🚀 *롤백 버전:*\n${{ inputs.rollback-ver }}"
}
]
},
{
"type": "divider"
}
]
}
env:
SLACK_BOT_TOKEN: ${{ secrets.SLACK_BOT_TOKEN }}
56 changes: 41 additions & 15 deletions backend/docker-compose.prod.yml
Original file line number Diff line number Diff line change
@@ -1,24 +1,54 @@
version: '3.8'

services:
application:
container_name: app_container
app_container-blue:
container_name: app_container-blue
platform: linux/arm64
restart: always
image: ${DOCKER_REPO_NAME}/cruru:${DOCKER_IMAGE_VERSION_TAG}
image: cruru/cruru:${DOCKER_IMAGE_VERSION_TAG}
ports:
- ${SERVER_BINDING_PORT}
- ${MONITORING_BINDING_PORT}
- ${BLUE_SERVER_BINDING_PORT}
- ${BLUE_MONITORING_BINDING_PORT}
env_file:
- .env
environment:
PROFILE: prod
SERVER_PORT: ${BLUE_SERVER_PORT}
PROFILE: test
TZ: Asia/Seoul
volumes:
- "./log:/log"
networks:
cruru_network:
ipv4_address: ${APP_IP_ADDRESS}
- cruru_network

app_container-green:
container_name: app_container-green
platform: linux/arm64
restart: always
image: cruru/cruru:${DOCKER_IMAGE_VERSION_TAG}
ports:
- ${GREEN_SERVER_BINDING_PORT}
- ${GREEN_MONITORING_BINDING_PORT}
env_file:
- .env
environment:
SERVER_PORT: ${GREEN_SERVER_PORT}
PROFILE: test
TZ: Asia/Seoul
volumes:
- "./log:/log"
networks:
- cruru_network

nginx_container:
image: nginx:latest
container_name: nginx_container
restart: always
ports:
- "80:80"
volumes:
- ./nginx-conf:/etc/nginx/conf.d
- ./html:/usr/share/nginx/html
networks:
- cruru_network

promtail:
environment:
Expand All @@ -32,12 +62,8 @@ services:
- "./log:/log"
command: -config.expand-env=true -config.file=/etc/promtail/config.yml
networks:
cruru_network:
ipv4_address: 172.18.0.4
- cruru_network

networks:
cruru_network:
driver: bridge
ipam:
config:
- subnet: ${SUBNET}
external: true

0 comments on commit c135aed

Please sign in to comment.