Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
58 changes: 58 additions & 0 deletions .github/workflows/deploy-monitoring.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
name: Deploy Monitoring To EC2
on:
push:
branches:
- main
- deploy
# paths:
# - "docker-compose.yml"
# - "prometheus/**"
# - "grafana/**"
# - ".github/workflows/deploy-monitoring.yml"
# - "deploy/**"

jobs:
deploy:
runs-on: ubuntu-latest
steps:
- name: GitHub Repository 가져오기
uses: actions/checkout@v4

- name: AWS Resource에 접근할 수 있게 AWS credentials 설정
uses: aws-actions/configure-aws-credentials@v4
with:
aws-region: ap-northeast-2
aws-access-key-id: ${{secrets.AWS_ACCESS_KEY}}
aws-secret-access-key: ${{secrets.AWS_SECRET_KEY}}

- name: .env 파일 생성
run: |
cat > .env << EOF
RUN_UID=${{secrets.RUN_UID}}
RUN_GID=${{secrets.RUN_GID}}
GRAFANA_ADMIN_USER=${{secrets.GRAFANA_ADMIN_USER}}
GRAFANA_ADMIN_PASSWORD=${{secrets.GRAFANA_ADMIN_PASSWORD}}
EOF

- name: 압축하기
run: |
cp deploy/monitoring/appspec.yml ./appspec.yml
cp -r deploy/monitoring/scripts ./scripts
tar -czvf $GITHUB_SHA.tar.gz \
appspec.yml \
.env \
scripts \
docker-compose.yml \
prometheus \
grafana

- name: S3에 프로젝트 폴더 업로드 하기
run: aws s3 cp --region ap-northeast-2 ./$GITHUB_SHA.tar.gz s3://mopl-deploy-4/monitoring/$GITHUB_SHA.tar.gz

- name: CodeDeploy 배포 트리거
run: |
aws deploy create-deployment \
--application-name mopl-monitoring \
--deployment-config-name CodeDeployDefault.AllAtOnce \
--deployment-group-name mopl-deploy-group-monitoring \
--s3-location bucket=mopl-deploy-4,key=monitoring/$GITHUB_SHA.tar.gz,bundleType=tgz
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
# monitoring
# monitoring

17 changes: 17 additions & 0 deletions deploy/monitoring/appspec.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
version: 0.0
os: linux
files:
- source: /
destination: /home/ubuntu/monitoring
file_exists_behavior: OVERWRITE

permissions:
- object: /
owner: ubuntu
group: ubuntu

hooks:
ApplicationStart:
- location: scripts/starts.sh
timeout: 120
runas: ubuntu
29 changes: 29 additions & 0 deletions deploy/monitoring/scripts/starts.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
#!/bin/bash

echo "--------------- monitoring 시작 -----------------"

cd /home/ubuntu/monitoring

# 기존 컨테이너 중지 및 삭제
docker compose down --remove-orphans 2>/dev/null || true

# data 디렉토리 생성 (소유권 설정)
mkdir -p data/prometheus data/grafana

# 환경 변수에서 UID/GID 읽기
source .env

# prometheus 데이터 디렉토리 권한 설정
chown -R ${RUN_UID}:${RUN_GID} data/prometheus

# grafana 데이터 디렉토리 권한 설정 (grafana는 472:472 고정)
chown -R 472:472 data/grafana

# docker-compose로 컨테이너 시작
docker compose up -d

echo "--------------- monitoring 끝 ------------------"

# 컨테이너 상태 확인
sleep 5
docker ps | grep monitoring