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: {}