Deploy Monitoring #20
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| name: Deploy Monitoring | |
| on: | |
| push: | |
| branches: [main] | |
| paths: | |
| - 'docker/monitoring/**' | |
| workflow_dispatch: | |
| jobs: | |
| deploy-monitoring: | |
| runs-on: ubuntu-latest | |
| steps: | |
| # 1. 코드 체크아웃 | |
| - name: Checkout app repository | |
| uses: actions/checkout@v3 | |
| - name: Checkout private config repository | |
| uses: actions/checkout@v3 | |
| with: | |
| repository: UruruLab/Ururu-Backend-Config | |
| token: ${{ secrets.PRIVATE_REPO_TOKEN }} | |
| path: config | |
| # 2. 환경변수 검증 | |
| - name: Validate environment variables | |
| run: | | |
| if [ ! -f config/.env ]; then | |
| echo "Error: .env file not found in config repository" | |
| exit 1 | |
| fi | |
| # 필수 환경변수 확인 | |
| source config/.env | |
| if [ -z "$PROD_HOST" ]; then | |
| echo "Error: PROD_HOST is not set in .env file" | |
| exit 1 | |
| fi | |
| if [ -z "$GRAFANA_ADMIN_PASSWORD" ]; then | |
| echo "Error: GRAFANA_ADMIN_PASSWORD is not set in .env file" | |
| exit 1 | |
| fi | |
| echo "Environment variables validation passed" | |
| # 3. 환경변수 처리 | |
| - name: Process environment variables | |
| run: | | |
| # Private Config Repository의 .env 파일에서 환경변수 로드 | |
| export $(grep -v '^#' config/.env | grep -v '^$' | xargs) | |
| # 환경변수 확인 | |
| echo "PROD_HOST: $PROD_HOST" | |
| echo "GRAFANA_ADMIN_USER: $GRAFANA_ADMIN_USER" | |
| # Prometheus 설정 파일에서 환경변수 처리 | |
| envsubst < docker/monitoring/prometheus/prometheus.yml > docker/monitoring/prometheus/prometheus.yml.tmp | |
| mv docker/monitoring/prometheus/prometheus.yml.tmp docker/monitoring/prometheus/prometheus.yml | |
| # 4. 모니터링 설정 파일 업로드 | |
| - name: Upload monitoring files to monitoring server | |
| uses: appleboy/scp-action@v1 | |
| with: | |
| host: ${{ secrets.MONITORING_EC2_HOST }} | |
| username: ${{ secrets.MONITORING_EC2_USER }} | |
| key: ${{ secrets.MONITORING_EC2_SSH_KEY }} | |
| source: "docker/docker-compose-monitoring.yml,config/.env,docker/monitoring/**" | |
| target: /home/ec2-user/monitoring/ | |
| strip_components: 1 | |
| overwrite: true | |
| # 5. 모니터링 서비스 배포 | |
| - name: Deploy monitoring services | |
| uses: appleboy/ssh-action@v0.1.6 | |
| with: | |
| host: ${{ secrets.MONITORING_EC2_HOST }} | |
| username: ${{ secrets.MONITORING_EC2_USER }} | |
| key: ${{ secrets.MONITORING_EC2_SSH_KEY }} | |
| script: | | |
| cd /home/ec2-user/monitoring | |
| # Docker Compose 명령어 확인 및 실행 | |
| if command -v docker-compose &> /dev/null; then | |
| docker-compose -f docker-compose-monitoring.yml down || true | |
| docker-compose -f docker-compose-monitoring.yml up -d | |
| elif command -v docker &> /dev/null && docker compose version &> /dev/null; then | |
| docker compose -f docker-compose-monitoring.yml down || true | |
| docker compose -f docker-compose-monitoring.yml up -d | |
| else | |
| echo "Error: Docker Compose is not installed" | |
| exit 1 | |
| fi | |
| # 6. 모니터링 서비스 헬스체크 | |
| - name: Health check monitoring services | |
| uses: appleboy/ssh-action@v0.1.6 | |
| with: | |
| host: ${{ secrets.MONITORING_EC2_HOST }} | |
| username: ${{ secrets.MONITORING_EC2_USER }} | |
| key: ${{ secrets.MONITORING_EC2_SSH_KEY }} | |
| script: | | |
| cd /home/ec2-user/monitoring | |
| # 컨테이너 상태 확인 | |
| echo "=== Docker 컨테이너 상태 확인 ===" | |
| docker ps -a | |
| echo "" | |
| # 포트 확인 | |
| echo "=== 포트 바인딩 확인 ===" | |
| netstat -tlnp | grep -E ':(9090|3000|3100|9080)' || echo "포트가 바인딩되지 않았습니다" | |
| echo "" | |
| # 서비스 헬스체크 | |
| echo "Checking Prometheus health..." | |
| sleep 15 | |
| curl -f http://localhost:9090/-/healthy || echo "Prometheus health check failed" | |
| echo "Prometheus is healthy" | |
| echo "Checking Grafana health..." | |
| sleep 10 | |
| curl -f http://localhost:3000/api/health || echo "Grafana health check failed" | |
| echo "Grafana is healthy" | |
| echo "Checking Promtail health..." | |
| sleep 10 | |
| curl -f http://localhost:9080/ready || echo "Promtail health check failed" | |
| echo "Promtail is healthy" | |
| echo "모니터링 서비스 배포 완료" |