-
Notifications
You must be signed in to change notification settings - Fork 0
[FEATURE] 테라폼 기반 배포 구현 #203
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 5 commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
c9f03c1
chore:#202 terraform aws ec2 배포 기반 추가
gdbs1107 f35c0b6
feat:#202 caddy https 및 nginx 프록시 구성 추가
gdbs1107 e193abb
feat:#202 경량 모니터링 스택 추가
gdbs1107 d27803f
fix:#202 모니터링 자산 재사용 및 배포 시크릿 제거
gdbs1107 48926a7
fix:#202 운영 모니터링 https 스크랩 수정
gdbs1107 c82ad00
fix:#202 PR 리뷰 유효 지적 반영
gdbs1107 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,4 @@ | ||
| __SERVER_NAME__ { | ||
| encode zstd gzip | ||
| reverse_proxy 127.0.0.1:8088 | ||
| } |
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,37 @@ | ||
| #!/usr/bin/env bash | ||
| set -euo pipefail | ||
|
|
||
| SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" | ||
| SERVER_NAME="${SERVER_NAME:?SERVER_NAME is required}" | ||
| DEPLOY_USER="${DEPLOY_USER:-${SUDO_USER:-ubuntu}}" | ||
| NGINX_INTERNAL_ONLY="${NGINX_INTERNAL_ONLY:-true}" | ||
|
|
||
| if ! command -v caddy >/dev/null 2>&1; then | ||
| sudo apt-get update | ||
| sudo apt-get install -y debian-keyring debian-archive-keyring apt-transport-https curl | ||
| curl -1sLf 'https://dl.cloudsmith.io/public/caddy/stable/gpg.key' | sudo gpg --dearmor -o /usr/share/keyrings/caddy-stable-archive-keyring.gpg | ||
| curl -1sLf 'https://dl.cloudsmith.io/public/caddy/stable/debian.deb.txt' | sudo tee /etc/apt/sources.list.d/caddy-stable.list >/dev/null | ||
| sudo apt-get update | ||
| sudo apt-get install -y caddy | ||
| fi | ||
|
|
||
| if [[ "${NGINX_INTERNAL_ONLY}" == "true" ]]; then | ||
| sudo APP_CONFIG_SOURCE="/opt/ssd/config/application-dev.yml" \ | ||
| NGINX_ENABLE_SSL=false \ | ||
| NGINX_INTERNAL_ONLY=true \ | ||
| NGINX_SERVER_NAME="_" \ | ||
| "${SCRIPT_DIR}/install_infra.sh" | ||
| fi | ||
|
|
||
| rendered_caddyfile="$(mktemp)" | ||
| trap 'rm -f "${rendered_caddyfile}"' EXIT | ||
|
|
||
| sed \ | ||
| -e "s#__SERVER_NAME__#${SERVER_NAME}#g" \ | ||
| "${SCRIPT_DIR}/caddy/Caddyfile.template" > "${rendered_caddyfile}" | ||
|
|
||
| sudo install -d -m 755 /etc/caddy | ||
| sudo install -m 644 "${rendered_caddyfile}" /etc/caddy/Caddyfile | ||
| sudo systemctl enable --now caddy | ||
| sudo systemctl restart caddy | ||
| sudo systemctl status caddy --no-pager | ||
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,52 @@ | ||
| #!/usr/bin/env bash | ||
| set -euo pipefail | ||
|
|
||
| SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" | ||
| APP_NAME="${APP_NAME:-ssd}" | ||
| DEPLOY_USER="${DEPLOY_USER:-${SUDO_USER:-ubuntu}}" | ||
| MONITORING_SOURCE_DIR="${MONITORING_SOURCE_DIR:-${SCRIPT_DIR}/monitoring-lite}" | ||
| MONITORING_DIR="${MONITORING_DIR:-/opt/${APP_NAME}/monitoring-prod-lite}" | ||
| APP_CONFIG_FILE="${APP_CONFIG_FILE:-/opt/${APP_NAME}/config/application-dev.yml}" | ||
| DISCORD_WEBHOOK_FILE="${DISCORD_WEBHOOK_FILE:-${MONITORING_DIR}/alertmanager/secrets/discord_webhook_url}" | ||
| ENV_FILE="${ENV_FILE:-${MONITORING_DIR}/.env}" | ||
|
|
||
| install -d -m 755 -o "${DEPLOY_USER}" -g "${DEPLOY_USER}" "${MONITORING_DIR}" | ||
|
|
||
| tmp_dir="$(mktemp -d)" | ||
| trap 'rm -rf "${tmp_dir}"' EXIT | ||
| cp -a "${MONITORING_SOURCE_DIR}/." "${tmp_dir}/" | ||
| rm -f "${tmp_dir}/.env" "${tmp_dir}/alertmanager/secrets/discord_webhook_url" | ||
| cp -a "${tmp_dir}/." "${MONITORING_DIR}/" | ||
| chown -R "${DEPLOY_USER}:${DEPLOY_USER}" "${MONITORING_DIR}" | ||
|
coderabbitai[bot] marked this conversation as resolved.
|
||
|
|
||
| install -d -m 750 -o "${DEPLOY_USER}" -g 65534 "$(dirname "${DISCORD_WEBHOOK_FILE}")" | ||
| if [[ ! -s "${DISCORD_WEBHOOK_FILE}" ]]; then | ||
| webhook_url="$(awk ' | ||
| /^discord:/ {in_discord=1; next} | ||
| in_discord && /^[^[:space:]]/ {in_discord=0} | ||
| in_discord && /webhook-url:/ {sub(/^[[:space:]]*webhook-url:[[:space:]]*/, ""); print; exit} | ||
| ' "${APP_CONFIG_FILE}" | tr -d '"' | tr -d "'")" | ||
| printf '%s' "${webhook_url}" > "${DISCORD_WEBHOOK_FILE}" | ||
| chmod 600 "${DISCORD_WEBHOOK_FILE}" | ||
| fi | ||
|
coderabbitai[bot] marked this conversation as resolved.
|
||
|
|
||
| chown "${DEPLOY_USER}:65534" "$(dirname "${DISCORD_WEBHOOK_FILE}")" | ||
| chmod 750 "$(dirname "${DISCORD_WEBHOOK_FILE}")" | ||
| chown 65534:65534 "${DISCORD_WEBHOOK_FILE}" | ||
| chmod 600 "${DISCORD_WEBHOOK_FILE}" | ||
|
|
||
| if [[ ! -f "${ENV_FILE}" ]]; then | ||
| grafana_password="$(openssl rand -base64 24 | tr -d '\n')" | ||
| { | ||
| echo 'GRAFANA_ADMIN_USER=admin' | ||
| echo "GRAFANA_ADMIN_PASSWORD=${grafana_password}" | ||
| } > "${ENV_FILE}" | ||
| chmod 600 "${ENV_FILE}" | ||
| chown "${DEPLOY_USER}:${DEPLOY_USER}" "${ENV_FILE}" | ||
| fi | ||
|
|
||
| cd "${MONITORING_DIR}" | ||
| docker compose -f docker-compose.monitoring-lite.yml config >/dev/null | ||
| docker compose -f docker-compose.monitoring-lite.yml up -d | ||
|
|
||
| echo "[INFO] SSD lightweight monitoring is running" | ||
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,19 @@ | ||
| global: | ||
| resolve_timeout: 5m | ||
|
|
||
| route: | ||
| receiver: discord | ||
| group_by: ["alertname", "service"] | ||
| group_wait: 30s | ||
| group_interval: 5m | ||
| repeat_interval: 3h | ||
|
|
||
| receivers: | ||
| - name: discord | ||
| discord_configs: | ||
| - webhook_url_file: /etc/alertmanager/secrets/discord_webhook_url | ||
| title: '{{ template "ssd.discord.title" . }}' | ||
| message: '{{ template "ssd.discord.message" . }}' | ||
|
|
||
| templates: | ||
| - /etc/alertmanager/templates/*.tmpl |
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
|
|
11 changes: 11 additions & 0 deletions
11
deploy/ec2/monitoring-lite/alertmanager/templates/discord.tmpl
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,11 @@ | ||
| {{ define "ssd.discord.title" -}} | ||
| [{{ .Status | toUpper }}] {{ .CommonLabels.alertname }} | ||
| {{- end }} | ||
|
|
||
| {{ define "ssd.discord.message" -}} | ||
| {{ range .Alerts -}} | ||
| - service={{ .Labels.service }} severity={{ .Labels.severity }} | ||
| summary={{ .Annotations.summary }} | ||
| description={{ .Annotations.description }} | ||
| {{ end -}} | ||
| {{- end }} |
85 changes: 85 additions & 0 deletions
85
deploy/ec2/monitoring-lite/docker-compose.monitoring-lite.yml
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,85 @@ | ||
| name: ssd-prod-monitoring-lite | ||
|
|
||
| services: | ||
| prometheus: | ||
| image: prom/prometheus:v2.54.1 | ||
| container_name: ssd-prod-prometheus | ||
| restart: unless-stopped | ||
| command: | ||
| - --config.file=/etc/prometheus/prometheus.yml | ||
| - --storage.tsdb.retention.time=7d | ||
| - --storage.tsdb.retention.size=1GB | ||
| - --web.enable-lifecycle | ||
| ports: | ||
| - "127.0.0.1:9091:9090" | ||
| volumes: | ||
| - ./prometheus/prometheus.yml:/etc/prometheus/prometheus.yml:ro | ||
| - ./prometheus/rules:/etc/prometheus/rules:ro | ||
| - prometheus_data:/prometheus | ||
| networks: | ||
| - monitoring | ||
| - ssd-net | ||
|
|
||
| alertmanager: | ||
| image: prom/alertmanager:v0.28.1 | ||
| container_name: ssd-prod-alertmanager | ||
| restart: unless-stopped | ||
| command: | ||
| - --config.file=/etc/alertmanager/alertmanager.yml | ||
| - --storage.path=/alertmanager | ||
| ports: | ||
| - "127.0.0.1:9093:9093" | ||
| volumes: | ||
| - ./alertmanager/alertmanager.yml:/etc/alertmanager/alertmanager.yml:ro | ||
| - ./alertmanager/templates:/etc/alertmanager/templates:ro | ||
| - ./alertmanager/secrets:/etc/alertmanager/secrets:ro | ||
| - alertmanager_data:/alertmanager | ||
| networks: | ||
| - monitoring | ||
|
|
||
| grafana: | ||
| image: grafana/grafana:11.1.4 | ||
| container_name: ssd-prod-grafana | ||
| restart: unless-stopped | ||
| depends_on: | ||
| - prometheus | ||
| env_file: | ||
| - .env | ||
| environment: | ||
| GF_USERS_ALLOW_SIGN_UP: "false" | ||
| GF_AUTH_ANONYMOUS_ENABLED: "false" | ||
| GF_SERVER_ROOT_URL: "https://dev-api.simsaimdang.shop/grafana/" | ||
| GF_SERVER_SERVE_FROM_SUB_PATH: "true" | ||
| ports: | ||
| - "127.0.0.1:3001:3000" | ||
| volumes: | ||
| - ../monitoring/grafana/provisioning/datasources/prometheus.yml:/etc/grafana/provisioning/datasources/prometheus.yml:ro | ||
| - ../monitoring/grafana/provisioning/dashboards/dashboard.yml:/etc/grafana/provisioning/dashboards/dashboard.yml:ro | ||
| - ../monitoring/grafana/dashboards/ssd-production-overview.json:/var/lib/grafana/dashboards/ssd-production-overview.json:ro | ||
| - grafana_data:/var/lib/grafana | ||
| networks: | ||
| - monitoring | ||
|
|
||
| node-exporter: | ||
| image: prom/node-exporter:v1.8.2 | ||
| container_name: ssd-prod-node-exporter | ||
| restart: unless-stopped | ||
| command: | ||
| - --path.rootfs=/host | ||
| pid: host | ||
| volumes: | ||
| - /:/host:ro,rslave | ||
| networks: | ||
| - monitoring | ||
|
|
||
| networks: | ||
| monitoring: | ||
| name: ssd-prod-monitoring | ||
| ssd-net: | ||
| external: true | ||
| name: ssd-net | ||
|
|
||
| volumes: | ||
| prometheus_data: | ||
| alertmanager_data: | ||
| grafana_data: |
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,25 @@ | ||
| global: | ||
| scrape_interval: 15s | ||
| evaluation_interval: 15s | ||
|
|
||
| alerting: | ||
| alertmanagers: | ||
| - static_configs: | ||
| - targets: | ||
| - alertmanager:9093 | ||
|
|
||
| rule_files: | ||
| - /etc/prometheus/rules/*.yml | ||
|
|
||
| scrape_configs: | ||
| - job_name: ssd-api | ||
| metrics_path: /actuator/prometheus | ||
| scheme: https | ||
| static_configs: | ||
| - targets: | ||
| - dev-api.simsaimdang.shop | ||
|
|
||
| - job_name: node-exporter | ||
| static_configs: | ||
| - targets: | ||
| - node-exporter:9100 |
51 changes: 51 additions & 0 deletions
51
deploy/ec2/monitoring-lite/prometheus/rules/ssd-alerts.yml
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,51 @@ | ||
| groups: | ||
| - name: ssd-operational-alerts | ||
| rules: | ||
| - alert: SsdApiScrapeDown | ||
| expr: sum(up{job="ssd-api"}) < 1 | ||
| for: 1m | ||
| labels: | ||
| severity: critical | ||
| service: ssd-api | ||
| annotations: | ||
| summary: "SSD API 서버 메트릭 수집 실패" | ||
| description: "Prometheus가 1분 이상 SSD API /actuator/prometheus를 수집하지 못했습니다." | ||
|
|
||
| - alert: HighHostCpuUsage | ||
| expr: 1 - avg(rate(node_cpu_seconds_total{mode="idle"}[5m])) > 0.8 | ||
| for: 5m | ||
| labels: | ||
| severity: warning | ||
| service: host | ||
| annotations: | ||
| summary: "EC2 CPU 사용률 높음" | ||
| description: "호스트 CPU 사용률이 5분 이상 80%를 초과했습니다." | ||
|
|
||
| - alert: HighHostDiskUsage | ||
| expr: | | ||
| 1 - ( | ||
| node_filesystem_avail_bytes{mountpoint="/",fstype!~"tmpfs|overlay"} | ||
| / | ||
| node_filesystem_size_bytes{mountpoint="/",fstype!~"tmpfs|overlay"} | ||
| ) > 0.85 | ||
| for: 5m | ||
| labels: | ||
| severity: warning | ||
| service: host | ||
| annotations: | ||
| summary: "EC2 Disk 사용률 높음" | ||
| description: "루트 디스크 사용률이 5분 이상 85%를 초과했습니다." | ||
|
|
||
| - alert: HighJvmHeapUsage | ||
| expr: | | ||
| sum(jvm_memory_used_bytes{job="ssd-api", area="heap"}) | ||
| / | ||
| sum(jvm_memory_max_bytes{job="ssd-api", area="heap"}) | ||
| > 0.8 | ||
| for: 3m | ||
| labels: | ||
| severity: warning | ||
| service: ssd-api | ||
| annotations: | ||
| summary: "JVM Heap 사용률 높음" | ||
| description: "JVM Heap 사용률이 3분 이상 80%를 초과했습니다." |
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
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.