Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

test workflow #574

Merged
merged 1 commit into from
Oct 11, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions .github/workflows/dockerpublish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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}}
10 changes: 10 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -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 && \
Expand Down
16 changes: 10 additions & 6 deletions site/zenodo_rdm/decorators.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"):
Expand All @@ -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)

Expand Down