|
| 1 | +name: docsa-stg |
| 2 | + |
| 3 | +services: |
| 4 | + app: |
| 5 | + image: ghcr.io/prgrms-web-devcourse-final-project/docsa-backend:dev |
| 6 | + container_name: docsa-app-stg |
| 7 | + restart: unless-stopped |
| 8 | + env_file: .env |
| 9 | + environment: |
| 10 | + SPRING_DATA_MONGODB_URI: ${SPRING_DATA_MONGODB_URI} |
| 11 | + SPRING_MAIL_USERNAME: ${SPRING_MAIL_USERNAME} |
| 12 | + SPRING_MAIL_PASSWORD: ${SPRING_MAIL_PASSWORD} |
| 13 | + SPRING_DATASOURCE_URL: ${SPRING_DATASOURCE_URL} |
| 14 | + SPRING_DATASOURCE_USERNAME: ${SPRING_DATASOURCE_USERNAME} |
| 15 | + SPRING_DATASOURCE_PASSWORD: ${SPRING_DATASOURCE_PASSWORD} |
| 16 | + SERVER_SERVLET_SESSION_COOKIE_NAME: ${SESSION_COOKIE_NAME} |
| 17 | + SERVER_SERVLET_SESSION_COOKIE_DOMAIN: ${SESSION_COOKIE_DOMAIN} |
| 18 | + SPRINGDOC_SWAGGER-UI_SERVERS_URL: ${SWAGGER_SERVER_URL} |
| 19 | + depends_on: |
| 20 | + mysql: |
| 21 | + condition: service_healthy |
| 22 | + networks: |
| 23 | + - docsa_stg_net |
| 24 | + healthcheck: |
| 25 | + test: ["CMD", "wget", "-qO-", "http://localhost:9091/actuator/health"] |
| 26 | + interval: 30s |
| 27 | + timeout: 5s |
| 28 | + retries: 3 |
| 29 | + |
| 30 | + mysql: |
| 31 | + image: mysql:9.4.0 |
| 32 | + container_name: docsa-mysql-stg |
| 33 | + restart: unless-stopped |
| 34 | + env_file: .env |
| 35 | + volumes: |
| 36 | + - stg_mysql_data:/var/lib/mysql |
| 37 | + - ./mysql/my.cnf:/etc/mysql/conf.d/my.cnf:ro |
| 38 | + - ./mysql/logs:/var/log/mysql |
| 39 | + networks: |
| 40 | + - docsa_stg_net |
| 41 | + healthcheck: |
| 42 | + test: ["CMD", "mysqladmin", "ping", "-h", "127.0.0.1", "-u", "docsa-stg", "-p${SPRING_DATASOURCE_PASSWORD}"] |
| 43 | + interval: 10s |
| 44 | + timeout: 5s |
| 45 | + retries: 3 |
| 46 | + |
| 47 | + mysqld-exporter: |
| 48 | + image: prom/mysqld-exporter:latest |
| 49 | + container_name: mysqld-exporter-stg |
| 50 | + restart: unless-stopped |
| 51 | + volumes: |
| 52 | + - ./mysql/exporter.cnf:/etc/.mysqld_exporter.cnf:ro |
| 53 | + command: |
| 54 | + - '--web.listen-address=:9104' |
| 55 | + - '--config.my-cnf=/etc/.mysqld_exporter.cnf' |
| 56 | + - '--mysqld.address=docsa-mysql-stg:3306' |
| 57 | + - '--collect.global_status' |
| 58 | + - '--collect.global_variables' |
| 59 | + - '--collect.engine_innodb_status' |
| 60 | + - '--collect.info_schema.tablestats' |
| 61 | + - '--collect.info_schema.processlist' |
| 62 | + # - '--collect.perf_schema.eventsstatements' |
| 63 | + # - '--collect.perf_schema.eventswaits' |
| 64 | + depends_on: |
| 65 | + mysql: |
| 66 | + condition: service_healthy |
| 67 | + networks: |
| 68 | + - docsa_stg_net |
| 69 | + |
| 70 | + nginx: |
| 71 | + image: nginx:stable-alpine-slim |
| 72 | + container_name: docsa-nginx-stg |
| 73 | + restart: unless-stopped |
| 74 | + volumes: |
| 75 | + - ./nginx/nginx.conf:/etc/nginx/nginx.conf:ro |
| 76 | + - ./certbot/etc:/etc/letsencrypt:ro |
| 77 | + - ./certbot/www:/var/www/certbot:ro |
| 78 | + ports: |
| 79 | + - "80:80" |
| 80 | + - "443:443" |
| 81 | + depends_on: |
| 82 | + app: |
| 83 | + condition: service_started |
| 84 | + networks: |
| 85 | + - docsa_stg_net |
| 86 | + |
| 87 | + # 최초 발급용(수동실행) |
| 88 | + certbot_init: |
| 89 | + image: certbot/certbot:latest |
| 90 | + container_name: docsa-certbot-init-stg |
| 91 | + profiles: |
| 92 | + - "init" |
| 93 | + depends_on: |
| 94 | + - nginx |
| 95 | + volumes: |
| 96 | + - ./certbot/www:/var/www/certbot:rw |
| 97 | + - ./certbot/etc:/etc/letsencrypt:rw |
| 98 | + - ./certbot/logs:/var/log/letsencrypt:rw |
| 99 | + command: > |
| 100 | + certonly --webroot |
| 101 | + --webroot-path /var/www/certbot |
| 102 | + -d stg.api.docsa.o-r.kr |
| 103 | + |
| 104 | + --agree-tos --non-interactive |
| 105 | + --no-eff-email |
| 106 | +
|
| 107 | + # 자동 갱신 데몬(하루마다 확인, 갱신되면 nginx 리로드) |
| 108 | + certbot_renew: |
| 109 | + image: certbot/certbot:latest |
| 110 | + container_name: docsa-certbot-renew-stg |
| 111 | + depends_on: |
| 112 | + - nginx |
| 113 | + volumes: |
| 114 | + - ./certbot/www:/var/www/certbot:rw |
| 115 | + - ./certbot/etc:/etc/letsencrypt:rw |
| 116 | + - ./certbot/logs:/var/log/letsencrypt:rw |
| 117 | + - /var/run/docker.sock:/var/run/docker.sock:rw |
| 118 | + entrypoint: > |
| 119 | + sh -c 'while :; do |
| 120 | + certbot renew --webroot -w /var/www/certbot --quiet |
| 121 | + if [ $$? -eq 0 ]; then |
| 122 | + # Docker Engine HTTP API로 nginx에 HUP 보내기 (무중단 리로드) |
| 123 | + wget -qO- \ |
| 124 | + --header="Content-Type: application/json" \ |
| 125 | + --method=POST \ |
| 126 | + --body-data="" \ |
| 127 | + --unix-socket /var/run/docker.sock \ |
| 128 | + http://localhost/v1.41/containers/docsa-nginx-stg/kill?signal=HUP >/dev/null 2>&1 || true |
| 129 | + fi |
| 130 | + sleep 24h; |
| 131 | + done' |
| 132 | +
|
| 133 | + # ===== METRICS ===== |
| 134 | + cadvisor: |
| 135 | + image: gcr.io/cadvisor/cadvisor:latest |
| 136 | + container_name: cadvisor-stg |
| 137 | + restart: unless-stopped |
| 138 | + privileged: true |
| 139 | + volumes: |
| 140 | + - /:/rootfs:ro |
| 141 | + - /var/run:/var/run:ro |
| 142 | + - /sys:/sys:ro |
| 143 | + - /var/lib/docker/:/var/lib/docker:ro |
| 144 | + networks: |
| 145 | + - docsa_stg_net |
| 146 | + |
| 147 | + node_exporter: |
| 148 | + image: prom/node-exporter:latest |
| 149 | + container_name: node-exporter-stg |
| 150 | + restart: unless-stopped |
| 151 | + pid: host |
| 152 | + command: ['--path.rootfs=/host'] |
| 153 | + volumes: |
| 154 | + - /:/host:ro,rslave |
| 155 | + networks: |
| 156 | + - docsa_stg_net |
| 157 | + |
| 158 | + prometheus: |
| 159 | + image: prom/prometheus:latest |
| 160 | + container_name: prometheus-stg |
| 161 | + restart: unless-stopped |
| 162 | + depends_on: |
| 163 | + - cadvisor |
| 164 | + volumes: |
| 165 | + - ./prometheus/prometheus.yml:/etc/prometheus/prometheus.yml:ro |
| 166 | + - stg_prom_data:/prometheus |
| 167 | + networks: |
| 168 | + - docsa_stg_net |
| 169 | + |
| 170 | +# ===== LOGS ===== |
| 171 | + loki: |
| 172 | + image: grafana/loki:3.5.5 |
| 173 | + container_name: loki-stg |
| 174 | + restart: unless-stopped |
| 175 | + command: ["-config.file=/etc/loki/config.yml"] |
| 176 | + volumes: |
| 177 | + - ./loki/config.yml:/etc/loki/config.yml:ro |
| 178 | + - stg_loki_data:/loki |
| 179 | + networks: |
| 180 | + - docsa_stg_net |
| 181 | + |
| 182 | + promtail: |
| 183 | + image: grafana/promtail:3.5 |
| 184 | + container_name: promtail-stg |
| 185 | + restart: unless-stopped |
| 186 | + command: ["-config.file=/etc/promtail/config.yml"] |
| 187 | + volumes: |
| 188 | + - ./promtail/config.yml:/etc/promtail/config.yml:ro |
| 189 | + - /var/log:/var/log:ro |
| 190 | + - /var/lib/docker/containers:/var/lib/docker/containers:ro |
| 191 | + - /var/run/docker.sock:/var/run/docker.sock:ro |
| 192 | + - ./mysql/logs:/mnt/mysql-logs:ro |
| 193 | + networks: [docsa_stg_net] |
| 194 | + |
| 195 | +# ===== DASHBOARD ===== |
| 196 | + grafana: |
| 197 | + image: grafana/grafana-oss:latest |
| 198 | + container_name: grafana-stg |
| 199 | + restart: unless-stopped |
| 200 | + depends_on: [prometheus, loki] |
| 201 | + volumes: |
| 202 | + - stg_grafana_data:/var/lib/grafana |
| 203 | + - ./grafana/provisioning/datasources/datasources.yaml:/etc/grafana/provisioning/datasources/datasources.yaml:ro |
| 204 | + environment: |
| 205 | + GF_SECURITY_ADMIN_USER: ${GRAFANA_ADMIN} |
| 206 | + GF_SECURITY_ADMIN_PASSWORD: ${GRAFANA_PASSWORD} |
| 207 | + GF_SERVER_ROOT_URL: 'https://stg.api.docsa.o-r.kr/grafana/' |
| 208 | + GF_SERVER_SERVE_FROM_SUB_PATH: 'true' |
| 209 | + networks: [docsa_stg_net] |
| 210 | + |
| 211 | + |
| 212 | +volumes: |
| 213 | + stg_mysql_data: |
| 214 | + stg_prom_data: |
| 215 | + stg_loki_data: |
| 216 | + stg_grafana_data: |
| 217 | + |
| 218 | +networks: |
| 219 | + docsa_stg_net: |
0 commit comments