Skip to content

Commit

Permalink
fix(reporting): Updated Sentry reporting; implemented automated versi…
Browse files Browse the repository at this point in the history
…oning for CI routines
  • Loading branch information
b32147 committed Jul 31, 2024
1 parent c66e1f8 commit 3449c4d
Show file tree
Hide file tree
Showing 16 changed files with 6,545 additions and 229 deletions.
60 changes: 60 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
name: Release Build

on:
push:
branches: [ master, development ]
workflow_dispatch:
inputs:
force:
type: boolean
default: false

jobs:
test-image:
uses: hms-dbmi/actions/.github/workflows/test-image-build.yml@main
secrets:
DOCKER_HUB_USERNAME: ${{ secrets.BLHMSDBMI_DOCKERHUB_USERNAME }}
DOCKER_HUB_PASSWORD: ${{ secrets.BLHMSDBMI_DOCKERHUB_PASSWORD }}
with:
repository: ${{ github.repository }}
commit: ${{ github.sha }}

scan-image:
uses: hms-dbmi/actions/.github/workflows/scan.yml@main
secrets:
DOCKER_HUB_USERNAME: ${{ secrets.BLHMSDBMI_DOCKERHUB_USERNAME }}
DOCKER_HUB_PASSWORD: ${{ secrets.BLHMSDBMI_DOCKERHUB_PASSWORD }}
with:
repository: ${{ github.repository }}
commit: ${{ github.sha }}

metadata:
runs-on: "ubuntu-latest"
outputs:
branch: ${{ steps.set_branch.outputs.branch }}
force: ${{ steps.force.outputs.force }}
steps:
- name: Set the current branch name
shell: bash
run: echo "branch=${GITHUB_HEAD_REF:-${GITHUB_REF#refs/heads/}}" >> $GITHUB_OUTPUT
id: set_branch
- name: Manage force input
id: force
env:
FORCE_INPUT: ${{ inputs.force }}
run: echo "force=${FORCE_INPUT:=false}" >> $GITHUB_OUTPUT

deploy:
uses: hms-dbmi/actions/.github/workflows/dbmisvc-app-deploy.yml@main
needs:
- "test-image"
- "metadata"
secrets:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
filename: "${{ github.event.repository.name }}-${{ needs.metadata.outputs.branch }}.zip"
app: ${{ github.event.repository.name }}
role: ${{ vars[ format('BLHMSDBMI_DBMISVC_DEPLOYMENT_{0}_ROLE_ARN', needs.metadata.outputs.branch) ] }}
bucket: ${{ vars[ format('BLHMSDBMI_DBMISVC_DEPLOYMENT_{0}_BUCKET', needs.metadata.outputs.branch) ] }}
force: ${{ fromJson(needs.metadata.outputs.force) }}
backmerge: development
2 changes: 0 additions & 2 deletions .github/workflows/scan.yml
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
name: Scan

on:
push:
branches: [ master, development ]
pull_request:
branches: [ master, development ]
schedule:
Expand Down
2 changes: 0 additions & 2 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
name: Test Image Build

on:
push:
branches: [ master, development ]
pull_request:
branches: [ master, development ]
workflow_dispatch:
Expand Down
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,4 @@ app/db.sqlite3
app/hypatio/local_settings.py
.vscode/settings.json
backup
node_modules
7 changes: 6 additions & 1 deletion .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -1,15 +1,20 @@
repos:
- repo: https://github.com/pre-commit/pre-commit-hooks.git
rev: v4.5.0
rev: v4.6.0
hooks:
- id: trailing-whitespace
- id: mixed-line-ending
- id: check-byte-order-marker
- id: check-merge-conflict
- id: detect-aws-credentials
args: [--allow-missing-credentials]
- repo: https://github.com/jazzband/pip-tools
rev: 7.4.1
hooks:
- id: pip-compile
name: pip-compile test-requirements.in
args: [test-requirements.in, --upgrade, --generate-hashes, --allow-unsafe, --output-file, test-requirements.txt]
files: ^test-requirements\.(in|txt)$
- id: pip-compile
name: pip-compile dev-requirements.in
args: [dev-requirements.in, --upgrade, --generate-hashes, --allow-unsafe, --output-file, dev-requirements.txt]
Expand Down
29 changes: 29 additions & 0 deletions .releaserc
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
{
"branches": [
"master",
"main",
"+([0-9])?(.{+([0-9]),x}).x",
{"name": "development", "channel": "pre/rc", "prerelease": "rc"},
{"name": "beta", "prerelease": true},
{"name": "alpha", "prerelease": true}
],
"plugins": [
"@semantic-release/commit-analyzer",
"@semantic-release/release-notes-generator",
["@semantic-release/changelog", {
"changelogFile": "CHANGELOG.md"
}],
["@semantic-release/exec", {
"prepareCmd": "sed -ie \"s/^version.*/version = \\x22${nextRelease.version}\\x22/g\" pyproject.toml"
}],
["@semantic-release/git", {
"assets": ["pyproject.toml", "CHANGELOG.md"]
}],
["@semantic-release/github", {
"successComment": false,
"failComment": false,
"failTitle": false
}]
],
"preset": "angular"
}
24 changes: 22 additions & 2 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
FROM hmsdbmitc/dbmisvc:debian12-slim-python3.11-0.6.1 AS builder
FROM hmsdbmitc/dbmisvc:debian12-slim-python3.11-0.6.2 AS builder

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

FROM hmsdbmitc/dbmisvc:debian12-slim-python3.11-0.6.1
FROM hmsdbmitc/dbmisvc:debian12-slim-python3.11-0.6.2

ARG APP_NAME="dbmi-data-portal"
ARG APP_CODENAME="hypatio"
ARG VERSION
ARG COMMIT
ARG DATE

LABEL org.label-schema.schema-version=1.0 \
org.label-schema.vendor="HMS-DBMI" \
org.label-schema.version=${VERSION} \
org.label-schema.name=${APP_NAME} \
org.label-schema.build-date=${DATE} \
org.label-schema.description="DBMI Data Portal" \
org.label-schema.url="https://github.com/hms-dbmi/hypatio-app" \
org.label-schema.vcs-url="https://github.com/hms-dbmi/hypatio-app" \
org.label-schema.vcf-ref=${COMMIT}

# Copy Python wheels from builder
COPY --from=builder /root/wheels /root/wheels
Expand Down Expand Up @@ -59,6 +75,10 @@ ENV DBMI_PARAMETER_STORE_PRIORITY=true
ENV DBMI_AWS_REGION=us-east-1

# App config
ENV DBMI_APP_NAME=${APP_NAME}
ENV DBMI_APP_CODENAME=${APP_CODENAME}
ENV DBMI_APP_VERSION=${VERSION}
ENV DBMI_APP_COMMIT=${COMMIT}
ENV DBMI_APP_WSGI=hypatio
ENV DBMI_APP_ROOT=/app
ENV DBMI_APP_DB=true
Expand Down
103 changes: 43 additions & 60 deletions app/hypatio/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@

from os.path import normpath, join, dirname, abspath
from dbmi_client import environment
from dbmi_client import reporting
from dbmi_client.logging import config

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

#####################################################################################

LOGGING = {
'version': 1,
'disable_existing_loggers': False,
'formatters': {
'console': {
'format': '[HYPATIO] - [%(asctime)s][%(levelname)s][%(name)s.%(funcName)s:%(lineno)d] - %(message)s',
},
#####################################################################################
# Logging settings
#####################################################################################

# Configure Sentry
reporting.sentry(
sentry_dsn=environment.get_str("SENTRY_DSN", required=True),
release=f'{environment.get_str("DBMI_APP_NAME")}@{environment.get_str("DBMI_APP_VERSION")}',
environment=environment.get_str("DBMI_ENV", "prod"),
sentry_trace_rate=environment.get_float("SENTRY_TRACES_RATE", default=0.0),
sentry_profile_rate=environment.get_float("SENTRY_PROFILES_RATE", default=0.0),
)

# Output the standard logging configuration
LOGGING = config('HYPATIO', root_level=logging.DEBUG)

# Disable warning level for 4xx request logging
LOGGING['loggers'].update({
'django.request': {
'handlers': ['console'],
'level': 'ERROR',
'propagate': True,
},
'handlers': {
'sentry': {
'level': 'ERROR',
'class': 'raven.contrib.django.raven_compat.handlers.SentryHandler',
},
'console': {
'level': 'DEBUG',
'class': 'logging.StreamHandler',
'formatter': 'console',
'stream': sys.stdout,
},
'boto3': {
'handlers': ['console'],
'level': 'INFO',
'propagate': True,
},
'root': {
'handlers': ['console', ],
'level': 'DEBUG'
'botocore': {
'handlers': ['console'],
'level': 'INFO',
'propagate': True,
},
'loggers': {
'django': {
'handlers': ['console', ],
'level': 'INFO',
'propagate': True,
},
'raven': {
'level': 'WARNING',
'handlers': ['console'],
'propagate': False,
},
'sentry.errors': {
'level': 'WARNING',
'handlers': ['console'],
'propagate': False,
},
'botocore': {
'level': 'WARNING',
'handlers': ['console'],
'propagate': True,
},
'boto3': {
'level': 'WARNING',
'handlers': ['console'],
'propagate': True,
},
's3transfer': {
'level': 'WARNING',
'handlers': ['console'],
'propagate': True,
},
's3transfer': {
'handlers': ['console'],
'level': 'INFO',
'propagate': True,
},
}
'urllib3': {
'handlers': ['console'],
'level': 'INFO',
'propagate': True,
},
})

RAVEN_CONFIG = {
'dsn': environment.get_str("RAVEN_URL", required=True),
# If you are using git, you can also automatically configure the
# release based on the git info.
'release': '1',
'site': 'HYPATIO'
}
#####################################################################################
5 changes: 4 additions & 1 deletion buildspec.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@ env:
DOCKER_HUB_USERNAME: "/dbmi/codebuild/docker/username"
DOCKER_HUB_PASSWORD: "/dbmi/codebuild/docker/password"
phases:
install:
commands:
- pip3 install toml-cli
pre_build:
commands:
- echo Logging in to Amazon ECR...
Expand All @@ -13,7 +16,7 @@ phases:
- docker login -u ${DOCKER_HUB_USERNAME} -p ${DOCKER_HUB_PASSWORD}
build:
commands:
- docker build -t $IMAGE_REPO_NAME:$IMAGE_TAG .
- 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 .
- docker tag $IMAGE_REPO_NAME:$IMAGE_TAG $AWS_ACCOUNT_ID.dkr.ecr.$AWS_DEFAULT_REGION.amazonaws.com/$IMAGE_REPO_NAME:$IMAGE_TAG
post_build:
commands:
Expand Down
Loading

0 comments on commit 3449c4d

Please sign in to comment.