Skip to content

Commit

Permalink
Add build info
Browse files Browse the repository at this point in the history
  • Loading branch information
sylvain-morin committed Jun 13, 2024
1 parent be0cb14 commit 88fafe0
Show file tree
Hide file tree
Showing 5 changed files with 67 additions and 2 deletions.
15 changes: 14 additions & 1 deletion .github/workflows/CICD-dev.yml
Original file line number Diff line number Diff line change
Expand Up @@ -29,14 +29,22 @@ 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:
context: .
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
Expand All @@ -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
Expand Down
15 changes: 14 additions & 1 deletion .github/workflows/CICD-main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -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
Expand All @@ -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
Expand Down
15 changes: 15 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -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"]
15 changes: 15 additions & 0 deletions Dockerfile-cleanup
Original file line number Diff line number Diff line change
Expand Up @@ -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"]
9 changes: 9 additions & 0 deletions lib/inat_vision_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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.environ["GIT_BRANCH"],
"git_commit": os.environ["GIT_COMMIT"],
"image_tag": os.environ["IMAGE_TAG"],
"build_date": os.environ["BUILD_DATE"]
}

def index_route(self):
form = ImageForm()
if "observation_id" in request.args:
Expand Down

0 comments on commit 88fafe0

Please sign in to comment.