From af03f4b572e13f64e581afc138c0c14fe48568a0 Mon Sep 17 00:00:00 2001 From: sylvain-morin Date: Thu, 20 Jun 2024 22:54:29 +0200 Subject: [PATCH 1/2] Export K8S logs for API --- .github/workflows/CICD-dev.yml | 8 ++++++++ .github/workflows/CICD-main.yml | 10 ++++++++++ Dockerfile-cleanup | 15 +++++++++++++++ docker/logrotate-cron.sh | 2 ++ docker/logrotate.conf | 10 ++++++++++ 5 files changed, 45 insertions(+) create mode 100644 Dockerfile-cleanup create mode 100644 docker/logrotate-cron.sh create mode 100644 docker/logrotate.conf diff --git a/.github/workflows/CICD-dev.yml b/.github/workflows/CICD-dev.yml index 384bd184..ce82c306 100644 --- a/.github/workflows/CICD-dev.yml +++ b/.github/workflows/CICD-dev.yml @@ -38,6 +38,14 @@ jobs: push: true tags: ${{ secrets.DOCKERHUB_USERNAME }}/inaturalistapi:${{ github.ref_name }} + - name: Build/Push Dev inaturalistapi-cleanup + uses: docker/build-push-action@v5 + with: + context: . + file: ./Dockerfile-cleanup + push: true + tags: ${{ secrets.DOCKERHUB_USERNAME }}/inaturalistapi-cleanup:${{ github.ref_name }} + refresh-dev-staging-deployment: name: Refresh Dev Staging Deployment needs: build-and-push-dev-docker-image diff --git a/.github/workflows/CICD-main.yml b/.github/workflows/CICD-main.yml index 3e7284da..ed892c2d 100644 --- a/.github/workflows/CICD-main.yml +++ b/.github/workflows/CICD-main.yml @@ -39,6 +39,16 @@ jobs: ${{ secrets.DOCKERHUB_USERNAME }}/inaturalistapi:${{ github.sha }} ${{ secrets.DOCKERHUB_USERNAME }}/inaturalistapi:latest + - name: Build/Push Main inaturalistapi-cleanup + uses: docker/build-push-action@v5 + with: + context: . + file: ./Dockerfile-cleanup + push: true + tags: | + ${{ secrets.DOCKERHUB_USERNAME }}/inaturalistapi-cleanup:${{ github.sha }} + ${{ secrets.DOCKERHUB_USERNAME }}/inaturalistapi-cleanup:latest + refresh-main-staging-deployment: name: Refresh Main Staging Deployment needs: build-and-push-main-docker-image diff --git a/Dockerfile-cleanup b/Dockerfile-cleanup new file mode 100644 index 00000000..1747a014 --- /dev/null +++ b/Dockerfile-cleanup @@ -0,0 +1,15 @@ +FROM alpine:latest + +RUN apk add --no-cache logrotate + +RUN mkdir -p /var/api/log +RUN mkdir -p /var/api/script + +# Configure logrotate hourly +COPY docker/logrotate.conf /var/api/script/logrotate.conf +COPY docker/logrotate-cron.sh /var/api/script/logrotate-cron.sh +RUN chmod 400 /var/api/script/logrotate.conf +RUN crontab -l | { cat; echo "0 * * * * sh /var/api/script/logrotate-cron.sh"; } | crontab - + +# Run cron +CMD ["/bin/sh", "-c", "crond -f"] diff --git a/docker/logrotate-cron.sh b/docker/logrotate-cron.sh new file mode 100644 index 00000000..125320a5 --- /dev/null +++ b/docker/logrotate-cron.sh @@ -0,0 +1,2 @@ +#!/bin/sh +/usr/sbin/logrotate -s /var/api/script/logrotate.status /var/api/script/logrotate.conf \ No newline at end of file diff --git a/docker/logrotate.conf b/docker/logrotate.conf new file mode 100644 index 00000000..40e8318b --- /dev/null +++ b/docker/logrotate.conf @@ -0,0 +1,10 @@ +/var/api/log/logstash.log { + hourly + rotate 5 + size 10M + missingok + compress + delaycompress + notifempty + copytruncate +} \ No newline at end of file From d22d2ce4ee87bbffee15844f476788db3eb1759e Mon Sep 17 00:00:00 2001 From: sylvain-morin Date: Fri, 21 Jun 2024 16:51:33 +0200 Subject: [PATCH 2/2] Export K8S logs for API --- docker/logrotate.conf | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docker/logrotate.conf b/docker/logrotate.conf index 40e8318b..71c849bb 100644 --- a/docker/logrotate.conf +++ b/docker/logrotate.conf @@ -1,4 +1,4 @@ -/var/api/log/logstash.log { +/var/api/log/inaturalist_api.4000.log { hourly rotate 5 size 10M