diff --git a/.github/workflows/deploy.yml b/.github/workflows/deploy.yml index 13d9f27d..0ad17a9e 100644 --- a/.github/workflows/deploy.yml +++ b/.github/workflows/deploy.yml @@ -14,13 +14,31 @@ jobs: build: name: Build images runs-on: ubuntu-latest + outputs: + image_tag: ${{ steps.meta.outputs.image_tag }} + release_name: ${{ steps.meta.outputs.release_name }} + steps: - name: Checkout uses: actions/checkout@v3 - - name: Prepare image reference - run: echo "image_tag=sha-`echo ${GITHUB_SHA} | cut -c1-7`" >> $GITHUB_ENV + - name: Prepare references and release + id: meta + run: | + echo "image_tag=sha-`echo ${GITHUB_SHA} | cut -c1-7`" >> $GITHUB_OUTPUT + echo "release_name=fiesta-plus@`echo ${GITHUB_SHA}` " >> $GITHUB_OUTPUT + + - name: Prepare Sentry release + uses: getsentry/action-release@v1 + env: + SENTRY_AUTH_TOKEN: ${{ secrets.SENTRY_AUTH_TOKEN }} + SENTRY_ORG: ${{ secrets.SENTRY_ORG }} + SENTRY_PROJECT: ${{ secrets.SENTRY_PROJECT }} + with: + environment: production + finalize: false + version: ${{ steps.meta.outputs.release_name }} - name: Set up QEMU uses: docker/setup-qemu-action@v2 @@ -66,10 +84,13 @@ jobs: cache-to: type=gha,mode=max tags: ${{ steps.webMeta.outputs.tags }} labels: ${{ steps.webMeta.outputs.labels }} + build-args: | + DJANGO_RELEASE_NAME: ${{ steps.meta.outputs.release_name }} secrets: | SENTRY_ORG=${{ secrets.SENTRY_ORG }} SENTRY_PROJECT=${{ secrets.SENTRY_PROJECT }} SENTRY_WEBPACK_AUTH_TOKEN=${{ secrets.SENTRY_WEBPACK_AUTH_TOKEN }} + SENTRY_RELEASE_NAME=${{ steps.meta.outputs.release_name }} - name: Prepare image metadata id: proxyMeta @@ -106,6 +127,7 @@ jobs: SENTRY_ORG=${{ secrets.SENTRY_ORG }} SENTRY_PROJECT=${{ secrets.SENTRY_PROJECT }} SENTRY_WEBPACK_AUTH_TOKEN=${{ secrets.SENTRY_WEBPACK_AUTH_TOKEN }} + SENTRY_RELEASE_NAME=${{ steps.meta.outputs.release_name }} deploy: name: Deploy to cluster @@ -123,9 +145,6 @@ jobs: run: | echo "${{ secrets.KUBECONFIG }}" > kubeconfig.yaml - - name: Prepare image reference - run: echo "image_tag=sha-`echo ${GITHUB_SHA} | cut -c1-7`" >> $GITHUB_ENV - - name: Deploy uses: 'vimeda/helm@v1.7.0' with: @@ -137,12 +156,14 @@ jobs: values: >- web: repository: ${{ secrets.SCW_REGISTRY_ENDPOINT }}/web - tag: ${{ env.image_tag }} + tag: ${{ needs.build.outputs.image_tag }} proxy: repository: ${{ secrets.SCW_REGISTRY_ENDPOINT }}/proxy - tag: ${{ env.image_tag }} + tag: ${{ needs.build.outputs.image_tag }} ingress: certContactEmail: ${{ secrets.CERT_CONTACT_EMAIL }} + release: + name: ${{ needs.build.outputs.release_name }} secrets: databaseUrl: ${{ secrets.DATABASE_URL }} s3: @@ -189,17 +210,18 @@ jobs: --data-urlencode "disable_web_page_preview=true" \ --data-urlencode "parse_mode=MarkdownV2" - announce-to-sentry: - name: Announce Deploy To Sentry + finalize-sentry-release: + name: Finalize Sentry deploy runs-on: ubuntu-latest needs: + - build - deploy steps: - uses: actions/checkout@v3 with: fetch-depth: 0 - - name: Create Sentry release + - name: Finalize Sentry release uses: getsentry/action-release@v1 env: SENTRY_AUTH_TOKEN: ${{ secrets.SENTRY_AUTH_TOKEN }} @@ -207,3 +229,5 @@ jobs: SENTRY_PROJECT: ${{ secrets.SENTRY_PROJECT }} with: environment: production + finalize: true + version: ${{ needs.build.outputs.release_name }} diff --git a/Dockerfile b/Dockerfile index 324a8114..24467df9 100644 --- a/Dockerfile +++ b/Dockerfile @@ -114,6 +114,9 @@ ENV DJANGO_MEDIA_ROOT=${DJANGO_MEDIA_ROOT} ARG DJANGO_BUILD_DIR=/usr/src/build/ ENV DJANGO_BUILD_DIR=${DJANGO_BUILD_DIR} +ARG DJANGO_RELASE_NAME +ENV DJANGO_RELASE_NAME=${DJANGO_RELASE_NAME} + # need production configuration, but not all values are ready in env RUN bash -c "DJANGO_SECRET_KEY=\$RANDOM DJANGO_CONFIGURATION=LocalProduction python manage.py collectstatic --no-input" diff --git a/fiesta/apps/utils/templatetags/release.py b/fiesta/apps/utils/templatetags/release.py new file mode 100644 index 00000000..a7486b7a --- /dev/null +++ b/fiesta/apps/utils/templatetags/release.py @@ -0,0 +1,21 @@ +from __future__ import annotations + +from django import template +from django.conf import settings + +register = template.Library() + + +@register.simple_tag +def sentry_js_loader_url(): + return getattr(settings, "SENTRY_JS_LOADER_URL", None) + + +@register.simple_tag +def release_name(): + release = getattr(settings, "RELEASE_NAME", None) or "" + try: + parts = release.partition("@") + return f"{parts[0]}@{parts[2][:7]}" + except (IndexError, ValueError): + return release diff --git a/fiesta/apps/utils/templatetags/sentry.py b/fiesta/apps/utils/templatetags/sentry.py deleted file mode 100644 index 36ee2ab8..00000000 --- a/fiesta/apps/utils/templatetags/sentry.py +++ /dev/null @@ -1,11 +0,0 @@ -from __future__ import annotations - -from django import template -from django.conf import settings - -register = template.Library() - - -@register.simple_tag -def sentry_js_loader_url(): - return getattr(settings, "SENTRY_JS_LOADER_URL", None) diff --git a/fiesta/fiesta/settings/logging.py b/fiesta/fiesta/settings/logging.py index 619ed907..7d5a92f1 100644 --- a/fiesta/fiesta/settings/logging.py +++ b/fiesta/fiesta/settings/logging.py @@ -62,6 +62,7 @@ def LOGGING(self): class SentryConfigMixin: + RELEASE_NAME: str ENVIRONMENT_NAME: str # from base SENTRY_JS_LOADER_URL = SecretValue(environ_required=False) SENTRY_DSN: str = SecretValue(environ_required=False) @@ -83,4 +84,5 @@ def post_setup(cls): # We recommend adjusting this value in production. profiles_sample_rate=1.0, environment=cls.ENVIRONMENT_NAME, + release=cls.RELEASE_NAME, ) diff --git a/fiesta/fiesta/settings/project.py b/fiesta/fiesta/settings/project.py index 4d910460..653a843d 100644 --- a/fiesta/fiesta/settings/project.py +++ b/fiesta/fiesta/settings/project.py @@ -137,3 +137,4 @@ def ALLOWED_HOSTS(self): ENVIRONMENT_NAME: str = Value(environ_required=False) ENVIRONMENT_COLOR: str = Value(environ_required=False) + RELEASE_NAME: str = Value(environ_required=False, default="fiesta-plus@dev") diff --git a/fiesta/templates/fiesta/base.html b/fiesta/templates/fiesta/base.html index 27554dda..09ab7765 100644 --- a/fiesta/templates/fiesta/base.html +++ b/fiesta/templates/fiesta/base.html @@ -1,4 +1,4 @@ -{% load sentry %} +{% load release %} {% load utils %} {% load breadcrumbs %} {% load static %} diff --git a/fiesta/templates/fiesta/parts/footer.html b/fiesta/templates/fiesta/parts/footer.html index 928a269a..900030be 100644 --- a/fiesta/templates/fiesta/parts/footer.html +++ b/fiesta/templates/fiesta/parts/footer.html @@ -1,3 +1,4 @@ +{% load release %} {% load static %} diff --git a/webpack/webpack.prod.config.js b/webpack/webpack.prod.config.js index 12525504..85ea98ad 100644 --- a/webpack/webpack.prod.config.js +++ b/webpack/webpack.prod.config.js @@ -12,6 +12,10 @@ config.plugins.push( authToken: process.env.SENTRY_WEBPACK_AUTH_TOKEN, org: process.env.SENTRY_ORG, project: process.env.SENTRY_PROJECT, + release: { + name: process.env.SENTRY_RELEASE_NAME, + finalize: false, + }, }) );