Skip to content

Commit

Permalink
feat(release): support for proper sentry release propagation
Browse files Browse the repository at this point in the history
  • Loading branch information
thejoeejoee committed Nov 17, 2023
1 parent 05ae808 commit 7346992
Show file tree
Hide file tree
Showing 9 changed files with 119 additions and 69 deletions.
44 changes: 34 additions & 10 deletions .github/workflows/deploy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand All @@ -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:
Expand All @@ -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:
Expand Down Expand Up @@ -189,21 +210,24 @@ 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 }}
SENTRY_ORG: ${{ secrets.SENTRY_ORG }}
SENTRY_PROJECT: ${{ secrets.SENTRY_PROJECT }}
with:
environment: production
finalize: true
version: ${{ needs.build.outputs.release_name }}
3 changes: 3 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -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"

Expand Down
21 changes: 21 additions & 0 deletions fiesta/apps/utils/templatetags/release.py
Original file line number Diff line number Diff line change
@@ -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
11 changes: 0 additions & 11 deletions fiesta/apps/utils/templatetags/sentry.py

This file was deleted.

2 changes: 2 additions & 0 deletions fiesta/fiesta/settings/logging.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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,
)
1 change: 1 addition & 0 deletions fiesta/fiesta/settings/project.py
Original file line number Diff line number Diff line change
Expand Up @@ -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")
2 changes: 1 addition & 1 deletion fiesta/templates/fiesta/base.html
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{% load sentry %}
{% load release %}
{% load utils %}
{% load breadcrumbs %}
{% load static %}
Expand Down
100 changes: 53 additions & 47 deletions fiesta/templates/fiesta/parts/footer.html
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
{% load release %}
{% load static %}
<footer class="bg-gray-100 dark:bg-gray-900 text-base-content">
<div class="container px-5 py-6 mx-auto flex items-center sm:flex-row flex-col">
Expand All @@ -22,52 +23,57 @@
rel="nofollow,noreferer,noopener"
target="_blank">Support</a>
</span>
<span class="inline-flex sm:ml-auto sm:mt-0 mt-4 justify-center sm:justify-start">
<a>
<svg fill="currentColor"
stroke-linecap="round"
stroke-linejoin="round"
stroke-width="2"
class="w-5 h-5"
viewBox="0 0 24 24">
<path d="M18 2h-3a5 5 0 00-5 5v3H7v4h3v8h4v-8h3l1-4h-4V7a1 1 0 011-1h3z"></path>
</svg>
</a>
<a class="ml-3">
<svg fill="currentColor"
stroke-linecap="round"
stroke-linejoin="round"
stroke-width="2"
class="w-5 h-5"
viewBox="0 0 24 24">
<path d="M23 3a10.9 10.9 0 01-3.14 1.53 4.48 4.48 0 00-7.86 3v1A10.66 10.66 0 013 4s-4 9 5 13a11.64 11.64 0 01-7 2c9 5 20 0 20-11.5a4.5 4.5 0 00-.08-.83A7.72 7.72 0 0023 3z">
</path>
</svg>
</a>
<a class="ml-3">
<svg fill="none"
stroke="currentColor"
stroke-linecap="round"
stroke-linejoin="round"
stroke-width="2"
class="w-5 h-5"
viewBox="0 0 24 24">
<rect width="20" height="20" x="2" y="2" rx="5" ry="5"></rect>
<path d="M16 11.37A4 4 0 1112.63 8 4 4 0 0116 11.37zm1.5-4.87h.01"></path>
</svg>
</a>
<a class="ml-3">
<svg fill="currentColor"
stroke="currentColor"
stroke-linecap="round"
stroke-linejoin="round"
stroke-width="0"
class="w-5 h-5"
viewBox="0 0 24 24">
<path stroke="none" d="M16 8a6 6 0 016 6v7h-4v-7a2 2 0 00-2-2 2 2 0 00-2 2v7h-4v-7a6 6 0 016-6zM2 9h4v12H2z"></path>
<circle cx="4" cy="4" r="2" stroke="none"></circle>
</svg>
</a>
</span>
<div class="mx-auto text-xs">
<pre>{% release_name %}</pre>
</div>
{% if False %}
<span class="inline-flex sm:ml-auto sm:mt-0 mt-4 justify-center sm:justify-start">
<a>
<svg fill="currentColor"
stroke-linecap="round"
stroke-linejoin="round"
stroke-width="2"
class="w-5 h-5"
viewBox="0 0 24 24">
<path d="M18 2h-3a5 5 0 00-5 5v3H7v4h3v8h4v-8h3l1-4h-4V7a1 1 0 011-1h3z"></path>
</svg>
</a>
<a class="ml-3">
<svg fill="currentColor"
stroke-linecap="round"
stroke-linejoin="round"
stroke-width="2"
class="w-5 h-5"
viewBox="0 0 24 24">
<path d="M23 3a10.9 10.9 0 01-3.14 1.53 4.48 4.48 0 00-7.86 3v1A10.66 10.66 0 013 4s-4 9 5 13a11.64 11.64 0 01-7 2c9 5 20 0 20-11.5a4.5 4.5 0 00-.08-.83A7.72 7.72 0 0023 3z">
</path>
</svg>
</a>
<a class="ml-3">
<svg fill="none"
stroke="currentColor"
stroke-linecap="round"
stroke-linejoin="round"
stroke-width="2"
class="w-5 h-5"
viewBox="0 0 24 24">
<rect width="20" height="20" x="2" y="2" rx="5" ry="5"></rect>
<path d="M16 11.37A4 4 0 1112.63 8 4 4 0 0116 11.37zm1.5-4.87h.01"></path>
</svg>
</a>
<a class="ml-3">
<svg fill="currentColor"
stroke="currentColor"
stroke-linecap="round"
stroke-linejoin="round"
stroke-width="0"
class="w-5 h-5"
viewBox="0 0 24 24">
<path stroke="none" d="M16 8a6 6 0 016 6v7h-4v-7a2 2 0 00-2-2 2 2 0 00-2 2v7h-4v-7a6 6 0 016-6zM2 9h4v12H2z"></path>
<circle cx="4" cy="4" r="2" stroke="none"></circle>
</svg>
</a>
</span>
{% endif %}
</div>
</footer>
4 changes: 4 additions & 0 deletions webpack/webpack.prod.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -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,
},
})
);

Expand Down

0 comments on commit 7346992

Please sign in to comment.