diff --git a/.github/workflows/CICD-dev.yml b/.github/workflows/CICD-dev.yml index bfc5570..625db2d 100644 --- a/.github/workflows/CICD-dev.yml +++ b/.github/workflows/CICD-dev.yml @@ -29,7 +29,10 @@ jobs: - name: Set up Docker Buildx uses: docker/setup-buildx-action@v3 - + + - name: Set build date + run: echo "BUILD_DATE=$(date -u +"%Y-%m-%dT%H:%M:%SZ")" >> $GITHUB_ENV + - name: Build/Push Dev inatvisionapi uses: docker/build-push-action@v5 with: @@ -37,6 +40,11 @@ jobs: file: ./Dockerfile push: true tags: ${{ secrets.DOCKERHUB_USERNAME }}/inatvisionapi:${{ github.ref_name }} + build-args: | + GIT_BRANCH=${{ github.ref_name }} + GIT_COMMIT=${{ github.sha }} + IMAGE_TAG=${{ secrets.DOCKERHUB_USERNAME }}/inatvisionapi:${{ github.ref_name }} + BUILD_DATE=${{ env.BUILD_DATE }} - name: Build/Push Dev inatvisionapi-cleanup uses: docker/build-push-action@v5 @@ -45,6 +53,11 @@ jobs: file: ./Dockerfile-cleanup push: true tags: ${{ secrets.DOCKERHUB_USERNAME }}/inatvisionapi-cleanup:${{ github.ref_name }} + build-args: | + GIT_BRANCH=${{ github.ref_name }} + GIT_COMMIT=${{ github.sha }} + IMAGE_TAG=${{ secrets.DOCKERHUB_USERNAME }}/inatvisionapi-cleanup:${{ github.ref_name }} + BUILD_DATE=${{ env.BUILD_DATE }} refresh-dev-staging-deployment: name: Refresh Dev Staging Deployment diff --git a/.github/workflows/CICD-main.yml b/.github/workflows/CICD-main.yml index f687765..5c65a95 100644 --- a/.github/workflows/CICD-main.yml +++ b/.github/workflows/CICD-main.yml @@ -28,7 +28,10 @@ jobs: - name: Set up Docker Buildx uses: docker/setup-buildx-action@v3 - + + - name: Set build date + run: echo "BUILD_DATE=$(date -u +"%Y-%m-%dT%H:%M:%SZ")" >> $GITHUB_ENV + - name: Build/Push Main inatvisionapi uses: docker/build-push-action@v5 with: @@ -38,6 +41,11 @@ jobs: tags: | ${{ secrets.DOCKERHUB_USERNAME }}/inatvisionapi:${{ github.sha }} ${{ secrets.DOCKERHUB_USERNAME }}/inatvisionapi:latest + build-args: | + GIT_BRANCH=${{ github.ref_name }} + GIT_COMMIT=${{ github.sha }} + IMAGE_TAG=${{ secrets.DOCKERHUB_USERNAME }}/inatvisionapi:latest + BUILD_DATE=${{ env.BUILD_DATE }} - name: Build/Push Main inatvisionapi-cleanup uses: docker/build-push-action@v5 @@ -48,6 +56,11 @@ jobs: tags: | ${{ secrets.DOCKERHUB_USERNAME }}/inatvisionapi-cleanup:${{ github.sha }} ${{ secrets.DOCKERHUB_USERNAME }}/inatvisionapi-cleanup:latest + build-args: | + GIT_BRANCH=${{ github.ref_name }} + GIT_COMMIT=${{ github.sha }} + IMAGE_TAG=${{ secrets.DOCKERHUB_USERNAME }}/inatvisionapi-cleanup:latest + BUILD_DATE=${{ env.BUILD_DATE }} refresh-main-staging-deployment: name: Refresh Main Staging Deployment diff --git a/Dockerfile b/Dockerfile index 683b0c4..ad19023 100644 --- a/Dockerfile +++ b/Dockerfile @@ -40,5 +40,20 @@ ENV UWSGI_PLUGIN_DIR /usr/lib/uwsgi/plugins RUN mkdir /home/inaturalist/vision/uwsgi COPY docker/uwsgi.ini /home/inaturalist/vision/uwsgi.ini +ARG GIT_BRANCH +ARG GIT_COMMIT +ARG IMAGE_TAG +ARG BUILD_DATE + +ENV GIT_BRANCH=${GIT_BRANCH} +ENV GIT_COMMIT=${GIT_COMMIT} +ENV IMAGE_TAG=${IMAGE_TAG} +ENV BUILD_DATE=${BUILD_DATE} + +RUN echo "GIT_BRANCH=${GIT_BRANCH}" > /home/inaturalist/vision/build_info +RUN echo "GIT_COMMIT=${GIT_COMMIT}" >> /home/inaturalist/vision/build_info +RUN echo "IMAGE_TAG=${IMAGE_TAG}" >> /home/inaturalist/vision/build_info +RUN echo "BUILD_DATE=${BUILD_DATE}" >> /home/inaturalist/vision/build_info + # Run with uwsgi CMD ["uwsgi", "--ini", "/home/inaturalist/vision/uwsgi.ini", "--stats", ":1717", "--stats-http"] diff --git a/Dockerfile-cleanup b/Dockerfile-cleanup index 3c1e916..50d4f88 100644 --- a/Dockerfile-cleanup +++ b/Dockerfile-cleanup @@ -16,5 +16,20 @@ RUN crontab -l | { cat; echo "0 * * * * sh /var/vision/script/logrotate-cron.sh" COPY docker/clean-static-cron.sh /var/vision/script/clean-static-cron.sh RUN crontab -l | { cat; echo "*/10 * * * * sh /var/vision/script/clean-static-cron.sh"; } | crontab - +ARG GIT_BRANCH +ARG GIT_COMMIT +ARG IMAGE_TAG +ARG BUILD_DATE + +ENV GIT_BRANCH=${GIT_BRANCH} +ENV GIT_COMMIT=${GIT_COMMIT} +ENV IMAGE_TAG=${IMAGE_TAG} +ENV BUILD_DATE=${BUILD_DATE} + +RUN echo "GIT_BRANCH=${GIT_BRANCH}" > /var/vision/build_info +RUN echo "GIT_COMMIT=${GIT_COMMIT}" >> /var/vision/build_info +RUN echo "IMAGE_TAG=${IMAGE_TAG}" >> /var/vision/build_info +RUN echo "BUILD_DATE=${BUILD_DATE}" >> /var/vision/build_info + # Run cron CMD ["/bin/sh", "-c", "crond -f"] diff --git a/lib/inat_vision_api.py b/lib/inat_vision_api.py index 58de092..a590484 100644 --- a/lib/inat_vision_api.py +++ b/lib/inat_vision_api.py @@ -28,6 +28,7 @@ def __init__(self, config): self.h3_04_taxon_range_comparison_route, methods=["GET"]) self.app.add_url_rule("/h3_04_bounds", "h3_04_bounds", self.h3_04_bounds_route, methods=["GET"]) + self.app.add_url_rule("/build_info", "build_info", self.build_info_route, methods=["GET"]) def setup_inferrer(self, config): self.inferrer = InatInferrer(config) @@ -77,6 +78,14 @@ def h3_04_bounds_route(self): return f"Unknown taxon_id {taxon_id}", 422 return results_dict + def build_info_route(self): + return { + "git_branch": os.getenv("GIT_BRANCH", ""), + "git_commit": os.getenv("GIT_COMMIT", ""), + "image_tag": os.getenv("IMAGE_TAG", ""), + "build_date": os.getenv("BUILD_DATE", "") + } + def index_route(self): form = ImageForm() if "observation_id" in request.args: