Skip to content

Commit 3449c4d

Browse files
committed
fix(reporting): Updated Sentry reporting; implemented automated versioning for CI routines
1 parent c66e1f8 commit 3449c4d

16 files changed

+6545
-229
lines changed

.github/workflows/release.yml

+60
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
name: Release Build
2+
3+
on:
4+
push:
5+
branches: [ master, development ]
6+
workflow_dispatch:
7+
inputs:
8+
force:
9+
type: boolean
10+
default: false
11+
12+
jobs:
13+
test-image:
14+
uses: hms-dbmi/actions/.github/workflows/test-image-build.yml@main
15+
secrets:
16+
DOCKER_HUB_USERNAME: ${{ secrets.BLHMSDBMI_DOCKERHUB_USERNAME }}
17+
DOCKER_HUB_PASSWORD: ${{ secrets.BLHMSDBMI_DOCKERHUB_PASSWORD }}
18+
with:
19+
repository: ${{ github.repository }}
20+
commit: ${{ github.sha }}
21+
22+
scan-image:
23+
uses: hms-dbmi/actions/.github/workflows/scan.yml@main
24+
secrets:
25+
DOCKER_HUB_USERNAME: ${{ secrets.BLHMSDBMI_DOCKERHUB_USERNAME }}
26+
DOCKER_HUB_PASSWORD: ${{ secrets.BLHMSDBMI_DOCKERHUB_PASSWORD }}
27+
with:
28+
repository: ${{ github.repository }}
29+
commit: ${{ github.sha }}
30+
31+
metadata:
32+
runs-on: "ubuntu-latest"
33+
outputs:
34+
branch: ${{ steps.set_branch.outputs.branch }}
35+
force: ${{ steps.force.outputs.force }}
36+
steps:
37+
- name: Set the current branch name
38+
shell: bash
39+
run: echo "branch=${GITHUB_HEAD_REF:-${GITHUB_REF#refs/heads/}}" >> $GITHUB_OUTPUT
40+
id: set_branch
41+
- name: Manage force input
42+
id: force
43+
env:
44+
FORCE_INPUT: ${{ inputs.force }}
45+
run: echo "force=${FORCE_INPUT:=false}" >> $GITHUB_OUTPUT
46+
47+
deploy:
48+
uses: hms-dbmi/actions/.github/workflows/dbmisvc-app-deploy.yml@main
49+
needs:
50+
- "test-image"
51+
- "metadata"
52+
secrets:
53+
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
54+
with:
55+
filename: "${{ github.event.repository.name }}-${{ needs.metadata.outputs.branch }}.zip"
56+
app: ${{ github.event.repository.name }}
57+
role: ${{ vars[ format('BLHMSDBMI_DBMISVC_DEPLOYMENT_{0}_ROLE_ARN', needs.metadata.outputs.branch) ] }}
58+
bucket: ${{ vars[ format('BLHMSDBMI_DBMISVC_DEPLOYMENT_{0}_BUCKET', needs.metadata.outputs.branch) ] }}
59+
force: ${{ fromJson(needs.metadata.outputs.force) }}
60+
backmerge: development

.github/workflows/scan.yml

-2
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
name: Scan
22

33
on:
4-
push:
5-
branches: [ master, development ]
64
pull_request:
75
branches: [ master, development ]
86
schedule:

.github/workflows/test.yml

-2
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
name: Test Image Build
22

33
on:
4-
push:
5-
branches: [ master, development ]
64
pull_request:
75
branches: [ master, development ]
86
workflow_dispatch:

.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -7,3 +7,4 @@ app/db.sqlite3
77
app/hypatio/local_settings.py
88
.vscode/settings.json
99
backup
10+
node_modules

.pre-commit-config.yaml

+6-1
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,20 @@
11
repos:
22
- repo: https://github.com/pre-commit/pre-commit-hooks.git
3-
rev: v4.5.0
3+
rev: v4.6.0
44
hooks:
55
- id: trailing-whitespace
66
- id: mixed-line-ending
77
- id: check-byte-order-marker
88
- id: check-merge-conflict
99
- id: detect-aws-credentials
10+
args: [--allow-missing-credentials]
1011
- repo: https://github.com/jazzband/pip-tools
1112
rev: 7.4.1
1213
hooks:
14+
- id: pip-compile
15+
name: pip-compile test-requirements.in
16+
args: [test-requirements.in, --upgrade, --generate-hashes, --allow-unsafe, --output-file, test-requirements.txt]
17+
files: ^test-requirements\.(in|txt)$
1318
- id: pip-compile
1419
name: pip-compile dev-requirements.in
1520
args: [dev-requirements.in, --upgrade, --generate-hashes, --allow-unsafe, --output-file, dev-requirements.txt]

.releaserc

+29
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
{
2+
"branches": [
3+
"master",
4+
"main",
5+
"+([0-9])?(.{+([0-9]),x}).x",
6+
{"name": "development", "channel": "pre/rc", "prerelease": "rc"},
7+
{"name": "beta", "prerelease": true},
8+
{"name": "alpha", "prerelease": true}
9+
],
10+
"plugins": [
11+
"@semantic-release/commit-analyzer",
12+
"@semantic-release/release-notes-generator",
13+
["@semantic-release/changelog", {
14+
"changelogFile": "CHANGELOG.md"
15+
}],
16+
["@semantic-release/exec", {
17+
"prepareCmd": "sed -ie \"s/^version.*/version = \\x22${nextRelease.version}\\x22/g\" pyproject.toml"
18+
}],
19+
["@semantic-release/git", {
20+
"assets": ["pyproject.toml", "CHANGELOG.md"]
21+
}],
22+
["@semantic-release/github", {
23+
"successComment": false,
24+
"failComment": false,
25+
"failTitle": false
26+
}]
27+
],
28+
"preset": "angular"
29+
}

Dockerfile

+22-2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
FROM hmsdbmitc/dbmisvc:debian12-slim-python3.11-0.6.1 AS builder
1+
FROM hmsdbmitc/dbmisvc:debian12-slim-python3.11-0.6.2 AS builder
22

33
# Install requirements
44
RUN apt-get update \
@@ -20,7 +20,23 @@ RUN pip install -U wheel \
2020
&& pip wheel -r /requirements.txt \
2121
--wheel-dir=/root/wheels
2222

23-
FROM hmsdbmitc/dbmisvc:debian12-slim-python3.11-0.6.1
23+
FROM hmsdbmitc/dbmisvc:debian12-slim-python3.11-0.6.2
24+
25+
ARG APP_NAME="dbmi-data-portal"
26+
ARG APP_CODENAME="hypatio"
27+
ARG VERSION
28+
ARG COMMIT
29+
ARG DATE
30+
31+
LABEL org.label-schema.schema-version=1.0 \
32+
org.label-schema.vendor="HMS-DBMI" \
33+
org.label-schema.version=${VERSION} \
34+
org.label-schema.name=${APP_NAME} \
35+
org.label-schema.build-date=${DATE} \
36+
org.label-schema.description="DBMI Data Portal" \
37+
org.label-schema.url="https://github.com/hms-dbmi/hypatio-app" \
38+
org.label-schema.vcs-url="https://github.com/hms-dbmi/hypatio-app" \
39+
org.label-schema.vcf-ref=${COMMIT}
2440

2541
# Copy Python wheels from builder
2642
COPY --from=builder /root/wheels /root/wheels
@@ -59,6 +75,10 @@ ENV DBMI_PARAMETER_STORE_PRIORITY=true
5975
ENV DBMI_AWS_REGION=us-east-1
6076

6177
# App config
78+
ENV DBMI_APP_NAME=${APP_NAME}
79+
ENV DBMI_APP_CODENAME=${APP_CODENAME}
80+
ENV DBMI_APP_VERSION=${VERSION}
81+
ENV DBMI_APP_COMMIT=${COMMIT}
6282
ENV DBMI_APP_WSGI=hypatio
6383
ENV DBMI_APP_ROOT=/app
6484
ENV DBMI_APP_DB=true

app/hypatio/settings.py

+43-60
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@
1616

1717
from os.path import normpath, join, dirname, abspath
1818
from dbmi_client import environment
19+
from dbmi_client import reporting
20+
from dbmi_client.logging import config
1921

2022
# Build paths inside the project like this: os.path.join(BASE_DIR, ...)
2123
BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
@@ -301,68 +303,49 @@
301303

302304
#####################################################################################
303305

304-
LOGGING = {
305-
'version': 1,
306-
'disable_existing_loggers': False,
307-
'formatters': {
308-
'console': {
309-
'format': '[HYPATIO] - [%(asctime)s][%(levelname)s][%(name)s.%(funcName)s:%(lineno)d] - %(message)s',
310-
},
306+
#####################################################################################
307+
# Logging settings
308+
#####################################################################################
309+
310+
# Configure Sentry
311+
reporting.sentry(
312+
sentry_dsn=environment.get_str("SENTRY_DSN", required=True),
313+
release=f'{environment.get_str("DBMI_APP_NAME")}@{environment.get_str("DBMI_APP_VERSION")}',
314+
environment=environment.get_str("DBMI_ENV", "prod"),
315+
sentry_trace_rate=environment.get_float("SENTRY_TRACES_RATE", default=0.0),
316+
sentry_profile_rate=environment.get_float("SENTRY_PROFILES_RATE", default=0.0),
317+
)
318+
319+
# Output the standard logging configuration
320+
LOGGING = config('HYPATIO', root_level=logging.DEBUG)
321+
322+
# Disable warning level for 4xx request logging
323+
LOGGING['loggers'].update({
324+
'django.request': {
325+
'handlers': ['console'],
326+
'level': 'ERROR',
327+
'propagate': True,
311328
},
312-
'handlers': {
313-
'sentry': {
314-
'level': 'ERROR',
315-
'class': 'raven.contrib.django.raven_compat.handlers.SentryHandler',
316-
},
317-
'console': {
318-
'level': 'DEBUG',
319-
'class': 'logging.StreamHandler',
320-
'formatter': 'console',
321-
'stream': sys.stdout,
322-
},
329+
'boto3': {
330+
'handlers': ['console'],
331+
'level': 'INFO',
332+
'propagate': True,
323333
},
324-
'root': {
325-
'handlers': ['console', ],
326-
'level': 'DEBUG'
334+
'botocore': {
335+
'handlers': ['console'],
336+
'level': 'INFO',
337+
'propagate': True,
327338
},
328-
'loggers': {
329-
'django': {
330-
'handlers': ['console', ],
331-
'level': 'INFO',
332-
'propagate': True,
333-
},
334-
'raven': {
335-
'level': 'WARNING',
336-
'handlers': ['console'],
337-
'propagate': False,
338-
},
339-
'sentry.errors': {
340-
'level': 'WARNING',
341-
'handlers': ['console'],
342-
'propagate': False,
343-
},
344-
'botocore': {
345-
'level': 'WARNING',
346-
'handlers': ['console'],
347-
'propagate': True,
348-
},
349-
'boto3': {
350-
'level': 'WARNING',
351-
'handlers': ['console'],
352-
'propagate': True,
353-
},
354-
's3transfer': {
355-
'level': 'WARNING',
356-
'handlers': ['console'],
357-
'propagate': True,
358-
},
339+
's3transfer': {
340+
'handlers': ['console'],
341+
'level': 'INFO',
342+
'propagate': True,
359343
},
360-
}
344+
'urllib3': {
345+
'handlers': ['console'],
346+
'level': 'INFO',
347+
'propagate': True,
348+
},
349+
})
361350

362-
RAVEN_CONFIG = {
363-
'dsn': environment.get_str("RAVEN_URL", required=True),
364-
# If you are using git, you can also automatically configure the
365-
# release based on the git info.
366-
'release': '1',
367-
'site': 'HYPATIO'
368-
}
351+
#####################################################################################

buildspec.yml

+4-1
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,9 @@ env:
55
DOCKER_HUB_USERNAME: "/dbmi/codebuild/docker/username"
66
DOCKER_HUB_PASSWORD: "/dbmi/codebuild/docker/password"
77
phases:
8+
install:
9+
commands:
10+
- pip3 install toml-cli
811
pre_build:
912
commands:
1013
- echo Logging in to Amazon ECR...
@@ -13,7 +16,7 @@ phases:
1316
- docker login -u ${DOCKER_HUB_USERNAME} -p ${DOCKER_HUB_PASSWORD}
1417
build:
1518
commands:
16-
- docker build -t $IMAGE_REPO_NAME:$IMAGE_TAG .
19+
- docker build --build-arg "VERSION=`toml get project.version --toml-path pyproject.toml`" --build-arg "COMMIT=`cat ./COMMIT`" --build-arg "DATE=`date +'%Y-%m-%dT%H:%M:%S%z'`" -t $IMAGE_REPO_NAME:$IMAGE_TAG .
1720
- docker tag $IMAGE_REPO_NAME:$IMAGE_TAG $AWS_ACCOUNT_ID.dkr.ecr.$AWS_DEFAULT_REGION.amazonaws.com/$IMAGE_REPO_NAME:$IMAGE_TAG
1821
post_build:
1922
commands:

0 commit comments

Comments
 (0)