Skip to content

Commit

Permalink
fix(ci): Refactored deployment; added versioning; passes app version…
Browse files Browse the repository at this point in the history
… to Sentry initialization
  • Loading branch information
b32147 committed Jul 25, 2024
1 parent 0f37f27 commit 76f3c2e
Show file tree
Hide file tree
Showing 15 changed files with 6,375 additions and 64 deletions.
61 changes: 61 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
name: Release Build

on:
push:
branches: [ master, development ]
pull_request:
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_PPM_DEPLOYMENT_{0}_ROLE_ARN', needs.metadata.outputs.branch) ] }}
bucket: ${{ vars[ format('BLHMSDBMI_PPM_DEPLOYMENT_{0}_BUCKET', needs.metadata.outputs.branch) ] }}
force: ${{ fromJson(needs.metadata.outputs.force) }}
4 changes: 0 additions & 4 deletions .github/workflows/scan.yml
Original file line number Diff line number Diff line change
@@ -1,10 +1,6 @@
name: Scan

on:
push:
branches: [ master, development ]
pull_request:
branches: [ master, development ]
schedule:
- cron: '0 12 * * 1' # runs at 12:00 UTC on Mondays
workflow_dispatch:
Expand Down
4 changes: 0 additions & 4 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
@@ -1,10 +1,6 @@
name: Test Image Build

on:
push:
branches: [ master, development ]
pull_request:
branches: [ master, development ]
workflow_dispatch:

jobs:
Expand Down
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -340,5 +340,7 @@ $RECYCLE.BIN/
# Windows shortcuts
*.lnk

# Node modules
node_modules

# End of https://www.gitignore.io/api/osx,linux,django,python,windows,pycharm,pycharm+iml,pycharm+all
6 changes: 5 additions & 1 deletion .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
minimum_pre_commit_version: "2.13.0"
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
Expand All @@ -11,6 +11,10 @@ repos:
- 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
25 changes: 25 additions & 0 deletions .releaserc
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
{
"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"
],
"preset": "angular"
}
22 changes: 21 additions & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,24 @@ RUN pip install -U wheel \

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

ARG APP_NAME="ppm-questionnaire"
ARG APP_CODENAME="fhirquestionnaire"
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="PPM questionnaire service" \
org.label-schema.url="https://github.com/hms-dbmi/fhirquestionnaire" \
org.label-schema.vcs-url="https://github.com/hms-dbmi/fhirquestionnaire" \
org.label-schema.vcf-ref=${COMMIT}

# Copy PhantomJS binary
COPY --from=builder /tmp/phantomjs-2.1.1-linux-x86_64/bin/phantomjs /usr/local/bin/phantomjs
COPY --from=builder /tmp/phantomjs-2.1.1-arm64/bin/phantomjs /usr/local/bin/phantomjs

# Copy Python wheels from builder
COPY --from=builder /root/wheels /root/wheels
Expand Down Expand Up @@ -62,6 +78,10 @@ ENV DBMI_PARAMETER_STORE_PREFIX=ppm.questionnaire.${DBMI_ENV}
ENV DBMI_PARAMETER_STORE_PRIORITY=true
ENV DBMI_AWS_REGION=us-east-1

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=fhirquestionnaire
ENV DBMI_APP_ROOT=/app
ENV DBMI_APP_DOMAIN=p2m2.dbmi.hms.harvard.edu
Expand Down
2 changes: 2 additions & 0 deletions app/fhirquestionnaire/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -224,6 +224,8 @@
# Configure Sentry
reporting.sentry(
sentry_dsn=get_str("SENTRY_DSN", required=True),
release=get_str("DBMI_APP_VERSION"),
environment=get_str("DBMI_ENV", "prod"),
sentry_trace_rate=get_float("SENTRY_TRACES_RATE", default=0.0),
sentry_profile_rate=get_float("SENTRY_PROFILES_RATE", default=0.0),
)
Expand Down
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 --build-arg PIP_ARGS="${PIP_ARGS:=-U}" .
- 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 76f3c2e

Please sign in to comment.