From 3a803254376799bd1c487cfc61c12e5e6f8c8877 Mon Sep 17 00:00:00 2001 From: ssupecial <56429615+ssupecial@users.noreply.github.com> Date: Mon, 22 Jan 2024 15:01:47 +0900 Subject: [PATCH] fix(infra): add caddy container and update github actions (#10) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * fix(infra): add caddy container * fix(infra): update github actions and reorganize project structure github actions workflow 단계에 컨테이너들이 실행 중인지 확인하는 단계를 추가하였으며 Caddyfile에 변경이 있을 경우 Caddy 컨테이너 reload한다. Caddyfile과 docker-compose.yml 파일을 grafana 폴더에서 레포지토리의 루트 폴더로 이동한다. docker-compose.yml에 caddy 컨테이너를 추가한다. * fix(infra): modify logging service configuration to resolve prior push 이전의 푸쉬 중 잘못 작성한 코드를 수정함 caddy와 log(grafana+loki)로 docker compose profile을 나눔 sparse-checkout을 삭제함 * fix(infra): resolve typo --- .github/workflows/update-stage.yml | 33 ++++++++++++++++--- grafana/Caddyfile => Caddyfile | 0 .../docker-compose.yml => docker-compose.yml | 24 +++++++++++--- 3 files changed, 49 insertions(+), 8 deletions(-) rename grafana/Caddyfile => Caddyfile (100%) rename grafana/docker-compose.yml => docker-compose.yml (65%) diff --git a/.github/workflows/update-stage.yml b/.github/workflows/update-stage.yml index aea9468..7c54fce 100644 --- a/.github/workflows/update-stage.yml +++ b/.github/workflows/update-stage.yml @@ -11,17 +11,42 @@ jobs: - name: Checkout Repository uses: actions/checkout@v4 - - name: Set up Grafana Configuration + - name: Load dotenv from secret for Grafana Configuration run: | - cat < ./grafana/.env + cat < .env # Sensitive configurations from GitHub Secrets GF_SMTP_HOST = ${{ secrets.SMTP_HOST }} GF_SMTP_USER = ${{ secrets.SMTP_USER }} GF_SMTP_PASSWORD = ${{ secrets.SMTP_PASSWORD }} GF_SMTP_FROM_ADDRESS = ${{ secrets.FROM_ADDRESS }} EOF + + - name: Check if containers are running + id: check-container + run: | + { + echo 'stdout<> "$GITHUB_OUTPUT" + + - name: Initialize containers + if: steps.check-container.outputs.stdout == '' + run: | + docker compose --profile caddy up -d --no-recreate + docker compose --profile log up -d --no-recreate - name: Run Docker Compose run: | - cd ./grafana - docker compose up -d + docker compose --profile log up -d + + - name: Copy Caddyfile into Caddy Container + run: | + docker cp ./Caddyfile caddy:/etc/caddy/Caddyfile + + - name: Gracefully reload Caddy + run: | + docker exec -w /etc/caddy caddy caddy reload + + - name: Remove unused docker storages + run: docker system prune -a -f --volumes \ No newline at end of file diff --git a/grafana/Caddyfile b/Caddyfile similarity index 100% rename from grafana/Caddyfile rename to Caddyfile diff --git a/grafana/docker-compose.yml b/docker-compose.yml similarity index 65% rename from grafana/docker-compose.yml rename to docker-compose.yml index 0ccb44f..b965f0d 100644 --- a/grafana/docker-compose.yml +++ b/docker-compose.yml @@ -4,41 +4,55 @@ networks: loki: services: + caddy: + profiles: ['caddy'] + image: caddy:2.7.6-alpine + container_name: caddy + restart: always + ports: + - "80:80" + - "443:443" + network_mode: host + loki-test: + profiles: ['log'] image: grafana/loki:2.9.0 container_name: loki-test ports: - "3199:3100" volumes: - - '$PWD/loki-config-test.yml:/etc/loki/loki-config.yml' + - '$PWD/grafana/loki-config-test.yml:/etc/loki/loki-config.yml' command: -config.file=/etc/loki/loki-config.yml networks: - loki loki-stage: + profiles: ['log'] image: grafana/loki:2.9.0 container_name: loki-stage ports: - "3101:3100" volumes: - - '$PWD/loki-config-stage.yml:/etc/loki/loki-config.yml' + - '$PWD/grafana/loki-config-stage.yml:/etc/loki/loki-config.yml' command: -config.file=/etc/loki/loki-config.yml networks: - loki loki-aws: + profiles: ['log'] image: grafana/loki:2.9.0 container_name: loki-aws ports: - "3100:3100" volumes: - - '$PWD/loki-config-aws.yml:/etc/loki/loki-config.yml' + - '$PWD/grafana/loki-config-aws.yml:/etc/loki/loki-config.yml' command: -config.file=/etc/loki/loki-config.yml networks: - loki grafana: + profiles: ['log'] image: grafana/grafana:latest env_file: - .env @@ -51,8 +65,10 @@ services: - '3000:3000' volumes: - 'grafana_storage:/var/lib/grafana' - - '$PWD/grafana.ini:/etc/grafana/grafana.ini' + - '$PWD/grafana/grafana.ini:/etc/grafana/grafana.ini' networks: - loki + + volumes: grafana_storage: {}