dev-wonny / coopang

물류 관리 및 배송 시스템을 위한 MSA, Spring boot project
5 stars 2 forks source link

[CICD] Coopang Project 배포 과정 #165

Open jiminchur opened 1 month ago

jiminchur commented 1 month ago

Todo

jiminchur commented 1 month ago

path 설정을 통한 서버별 독립적으로 배포하기

name: Deploy to EC2

on:
  push:
    branches:
      - #DEV-cicd # 배포할 브랜치 설정.
    paths:
      - ./BOOT/gateway/**
      - ./BOOT/user/**
      - ./BOOT/hub/**
      - ./BOOT/delivery/**
      - ./BOOT/order/**
      - ./BOOT/product/**
      - ./CLOUD/eureka/**
      - ./BOOT/ainoti/**
jobs:
  build:
    runs-on: ubuntu-latest
jiminchur commented 1 month ago

배포용 application.yml파일 설정하기

jiminchur commented 1 month ago

도커에 이미지 빌드하기

- name: Build and Push Docker Images to Docker Hub
        run: |
          for service in "gateway" "user" "hub" "delivery" "order" "product" "eureka" "ainoti"; do
            if [[ "${{ github.event.head_commit.message }}" == *"$service"* ]]; then
              # Gradle 빌드
              ./gradlew BOOT:$service:build -x test
              # Docker 이미지 빌드
              docker build -t ${{ docker_username}}/$service:latest ./BOOT/$service
              # Docker 이미지 푸시
              docker push ${{ docker_username}}/$service:latest
            fi
          done
jiminchur commented 1 month ago

EC2에서 변화가 일어난 부분만 중지, 이미지 풀, 시작하기

      - name: Manage Docker Compose on EC2
        run: |
          echo "${{ secrets.EC2_SSH_KEY }}" > foodtogo.pem
          chmod 600 foodtogo.pem
          ssh -i foodtogo.pem ${{ secrets.EC2_USER }}@${{ secrets.EC2_HOST }} << 'EOF'
            for service in "gateway" "user" "hub" "delivery" "order" "product" "eureka" "ainoti"; do
              if [[ "${{ github.event.head_commit.message }}" == *"$service"* ]]; then
                echo "Stopping and removing containers for $service"
                docker-compose -f "/server/$service/docker-compose.yml" down
                echo "Pulling the latest image for $service"
                docker-compose -f "/server/$service/docker-compose.yml" pull
                echo "Starting containers for $service"
                docker-compose -f "/server/$service/docker-compose.yml" up -d
              fi
            done
          EOF
jiminchur commented 1 month ago

❗️ARM 아키텍처와 AMD 아키텍처 간의 플랫폼 불일치 이슈

jiminchur commented 1 month ago

DockerHub에 이미지 빌드 완료

스크린샷 2024-10-22 오전 12 40 07

jiminchur commented 1 month ago

❗️loki와의 연결 이슈 (해결)

jiminchur commented 1 month ago

배포 완료

스크린샷 2024-10-22 오전 1 35 10