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