diff --git a/.github/workflows/cicd.yml b/.github/workflows/cicd.yml new file mode 100644 index 0000000..a5442dc --- /dev/null +++ b/.github/workflows/cicd.yml @@ -0,0 +1,40 @@ +name: CI/CD Pipeline + +on: + push: + branches: [ "성현준/main", "main", "성현준/8주차" ] + pull_request: + branches: [ "성현준/main", "main", "성현준/8주차" ] + +jobs: + build-and-deploy: + runs-on: ubuntu-latest + + steps: + # 1. 코드 체크아웃 + - name: Checkout code + uses: actions/checkout@v3 + + # 2. application.yml 파일 생성 (Secret에서) + - name: Create application.yml from secret + run: | + echo "${{ secrets.APPLICATION_YML }}" > blog_manage/src/main/resources/application.yml + + # 3. Docker Compose로 빌드 및 실행 (cd 명령어 필수!) + - name: Run docker-compose + run: | + cd ${{ github.workspace }}/blog_manage + docker compose up -d --build + + # 4. 애플리케이션 헬스 체크 + - name: Health check + run: | + sleep 30 + curl -f http://localhost:8080/actuator/health || echo "Health check failed" + + # 5. 로그 확인 + - name: Show logs + if: always() + run: | + cd ${{ github.workspace }}/blog_manage + docker compose logs \ No newline at end of file diff --git a/blog_manage/docker-compose.yml b/blog_manage/docker-compose.yml new file mode 100644 index 0000000..1b21634 --- /dev/null +++ b/blog_manage/docker-compose.yml @@ -0,0 +1,47 @@ +services: + # MySQL 데이터베이스 + mysql: + image: mysql:8.0 + container_name: blog_mysql + environment: + MYSQL_ROOT_PASSWORD: 2323 + MYSQL_DATABASE: leetsBlog + TZ: Asia/Seoul + ports: + - "3307:3306" + volumes: + - mysql_data:/var/lib/mysql + networks: + - blog_network + healthcheck: + test: ["CMD", "mysqladmin", "ping", "-h", "localhost"] + interval: 10s + timeout: 5s + retries: 5 + + # Spring Boot 애플리케이션 (Dockerfile로 빌드) + app: + build: + context: . + dockerfile: Dockerfile + container_name: blog_app + ports: + - "8080:8080" + environment: + SPRING_DATASOURCE_URL: jdbc:mysql://mysql:3306/leetsBlog?serverTimezone=Asia/Seoul + SPRING_DATASOURCE_USERNAME: root + SPRING_DATASOURCE_PASSWORD: 2323 + depends_on: + mysql: + condition: service_healthy + networks: + - blog_network + restart: unless-stopped + +volumes: + mysql_data: + +networks: + blog_network: + driver: bridge +