diff --git a/.github/workflows/dockerpublish.yml b/.github/workflows/dockerpublish.yml index 7a65f493..eafea935 100644 --- a/.github/workflows/dockerpublish.yml +++ b/.github/workflows/dockerpublish.yml @@ -49,9 +49,24 @@ jobs: username: ${{ github.actor }} password: ${{ secrets.GITHUB_TOKEN }} + - name: Populate image build timestamp + id: date + run: echo "IMAGE_BUILD_TIMESTAMP=$(date +'%Y%m%d_%H%M%S')" >> $GITHUB_ENV + + - name: Populate sentry release tag for development + run: echo "SENTRY_RELEASE=${{github.sha}} >> $GITHUB_ENV + if: ${{steps.meta.outputs.tags == 'latest'}} + + - name: Populate sentry release tag for prod/sandbox + run: echo "SENTRY_RELEASE=${{steps.meta.outputs.tags}} >> $GITHUB_ENV + if: ${{steps.meta.outputs.tags != 'latest'}} + - name: Build and publish image uses: docker/build-push-action@v3 with: push: true tags: ${{ steps.meta.outputs.tags }} labels: ${{ steps.meta.outputs.labels }} + build-args: | + IMAGE_BUILD_TIMESTAMP=${{env.IMAGE_BUILD_TIMESTAMP}} + SENTRY_RELEASE=${{env.SENTRY_RELEASE}} diff --git a/Dockerfile b/Dockerfile index 3ca72e4c..f80b1c6f 100644 --- a/Dockerfile +++ b/Dockerfile @@ -32,6 +32,16 @@ COPY ./app_data/ ${INVENIO_INSTANCE_PATH}/app_data/ COPY ./translations ${INVENIO_INSTANCE_PATH}/translations COPY ./ . +# application build args to be exposed as environment variables +ARG IMAGE_BUILD_TIMESTAMP +ARG SENTRY_RELEASE + +# Expose random sha to uniquely identify this build +ENV INVENIO_IMAGE_BUILD_TIMESTAMP=${IMAGE_BUILD_TIMESTAMP} +ENV SENTRY_RELEASE=${SENTRY_RELEASE} + +RUN echo "Image build timestamp $INVENIO_IMAGE_BUILD_TIMESTAMP" + RUN cp -r ./static/. ${INVENIO_INSTANCE_PATH}/static/ && \ cp -r ./assets/. ${INVENIO_INSTANCE_PATH}/assets/ && \ invenio collect --verbose && \ diff --git a/site/zenodo_rdm/decorators.py b/site/zenodo_rdm/decorators.py index e6b3a572..6cc29c13 100644 --- a/site/zenodo_rdm/decorators.py +++ b/site/zenodo_rdm/decorators.py @@ -9,14 +9,14 @@ from functools import wraps -from flask import session +from flask import current_app, session from flask_login import current_user from invenio_cache import current_cache -def has_flashes_or_authenticated_user(): - """Return True if there are pending flashes or user is authenticated.""" - return "_flashes" in session or current_user.is_authenticated +def has_flashes_or_authenticated_user_or_development(): + """Return True if there are pending flashes or user is authenticated or dev.""" + return "_flashes" in session or current_user.is_authenticated or current_app.debug def cached_unless_authenticated_or_flashes(timeout=50, key_prefix="default"): @@ -25,10 +25,14 @@ def cached_unless_authenticated_or_flashes(timeout=50, key_prefix="default"): def caching(f): @wraps(f) def wrapper(*args, **kwargs): + # we compute the cache key based on the `Dockerfile.IMAGE_BUILD_TIMESTAMP` + cache_prefix = ( + f"{key_prefix}_{current_app.config.get('IMAGE_BUILD_TIMESTAMP', '')}" + ) cache_fun = current_cache.cached( timeout=timeout, - key_prefix=key_prefix, - unless=has_flashes_or_authenticated_user, + key_prefix=cache_prefix, + unless=has_flashes_or_authenticated_user_or_development, ) return cache_fun(f)(*args, **kwargs)