Skip to content

Commit

Permalink
Add Sentry to Whisper (#33)
Browse files Browse the repository at this point in the history
  • Loading branch information
bbengfort authored Jun 9, 2023
1 parent 8042543 commit 831f705
Show file tree
Hide file tree
Showing 29 changed files with 1,002 additions and 16,275 deletions.
18 changes: 9 additions & 9 deletions .github/workflows/build.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -93,20 +93,20 @@ jobs:
uses: actions/setup-node@v3
with:
node-version: 16.x.x
cache: "npm"
cache-dependency-path: ./web/package-lock.json
cache: "yarn"
cache-dependency-path: ./web/yarn.lock

- name: Install Dependencies
working-directory: ./web
run: npm install
run: yarn

- name: Lint React Code
working-directory: ./web
run: npm run lint
run: yarn lint

- name: Run React Tests
working-directory: ./web
run: npm run test
run: yarn test

web_build:
name: Web Build
Expand All @@ -119,13 +119,13 @@ jobs:
uses: actions/setup-node@v3
with:
node-version: 16.x.x
cache: "npm"
cache-dependency-path: ./web/package-lock.json
cache: "yarn"
cache-dependency-path: ./web/yarn.lock

- name: Install Dependencies
working-directory: ./web
run: npm install
run: yarn

- name: Build React Bundle
working-directory: ./web
run: npm run build
run: yarn build
19 changes: 18 additions & 1 deletion .github/workflows/deploy.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,9 @@ jobs:
name: Deploy API
runs-on: ubuntu-latest
env:
SENTRY_DSN: ${{ secrets.WHISPER_API_SENTRY_DSN }}
IMAGE_NAME: gcr.io/${{ secrets.GCP_PROJECT_ID }}/whisper-api

steps:
- name: Login to Google
uses: google-github-actions/setup-gcloud@master
Expand All @@ -27,8 +29,16 @@ jobs:
- name: Get Version Tag
run: echo "RELEASE_VERSION=${GITHUB_REF#refs/*/}" >> $GITHUB_ENV

- name: Get Git Revision
run: echo "GIT_REVISION=$(git rev-parse --shorte HEAD)" >> $GITHUB_ENV

- name: Build Docker Image
run: docker build -t $IMAGE_NAME:$RELEASE_VERSION -f containers/api/Dockerfile .
run: |
docker build \
-f containers/api/Dockerfile \
--build-arg GIT_REVISION=$GIT_REVISION \
--build-arg SENTRY_DSN=$SENTRY_DSN \
-t $IMAGE_NAME:$RELEASE_VERSION .
- name: Push Docker Image
run: docker push $IMAGE_NAME:$RELEASE_VERSION
Expand All @@ -47,6 +57,7 @@ jobs:
runs-on: ubuntu-latest
env:
IMAGE_NAME: gcr.io/${{ secrets.GCP_PROJECT_ID }}/whisper-ui
SENTRY_DSN: ${{ secrets.WHISPER_WEB_SENTRY_DSN }}
steps:
- name: Login to Google
uses: google-github-actions/setup-gcloud@master
Expand All @@ -64,12 +75,18 @@ jobs:
- name: Get Version Tag
run: echo "RELEASE_VERSION=${GITHUB_REF#refs/*/}" >> $GITHUB_ENV

- name: Get Git Revision
run: echo "GIT_REVISION=$(git rev-parse --shorte HEAD)" >> $GITHUB_ENV

- name: Build Docker Image
run: |
docker build \
-f containers/web/Dockerfile \
--build-arg REACT_APP_API_BASE_URL=https://api.whisper.rotational.dev/v1 \
--build-arg REACT_APP_UI_BASE_URL=https://whisper.rotational.dev \
--build-arg REACT_APP_GIT_REVISION=$GIT_REVISION \
--build-arg REACT_APP_SENTRY_DSN=$SENTRY_DSN \
--build-arg REACT_APP_RELEASE_VERSION=$RELEASE_VERSION \
--build-arg NODE_ENV=production \
-t $IMAGE_NAME:$RELEASE_VERSION .
Expand Down
8 changes: 8 additions & 0 deletions containers/api/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ FROM ${BUILDER_IMAGE} as builder

# Build Args
ARG GIT_REVISION=""
ARG SENTRY_DSN=""

# Ensure ca-certificates are up to date on the image
RUN update-ca-certificates
Expand Down Expand Up @@ -35,6 +36,10 @@ RUN go build -v -o /go/bin/whisper -ldflags="-X 'github.com/rotationalio/whisper
# https://hub.docker.com/_/debian
FROM ${FINAL_IMAGE} AS final

# Build Args
ARG GIT_REVISION=""
ARG SENTRY_DSN=""

LABEL maintainer="Rotational Labs <support@rotational.io>"
LABEL description="Whisper, a secret management utility"

Expand All @@ -51,6 +56,9 @@ ENV WHISPER_MAINTENANCE=false
ENV WHISPER_MODE=release
ENV WHISPER_LOG_LEVEL=info
ENV WHISPER_CONSOLE_LOG=false
ENV WHISPER_SENTRY_SERVER_NAME=cloudrun
ENV WHISPER_SENTRY_ENVIRONMENT=production
ENV WHISPER_SENTRY_DSN=${SENTRY_DSN}

# Run the web service on container startup.
CMD [ "/usr/local/bin/whisper", "serve" ]
72 changes: 61 additions & 11 deletions containers/build.sh
Original file line number Diff line number Diff line change
@@ -1,4 +1,25 @@
#!/bin/bash
# A helper script for building docker images

# Print usage and exit
show_help() {
cat << EOF
Usage: ${0##*/} [-h] [-t TAG] [-p PLATFORM]
A helper script for building whisper docker images
Flags are as follows (getopt required):
-h display this help and exit
-t the tag to tag the images with
-p the target platform to build the docker images for
Unless otherwise specified TAG is the git hash and PLATFORM is
linux/amd64 when deploying to ensure the correct images are deployed.
NOTE: realpath is required; you can install it on OS X with
$ brew install coreutils
EOF
}

ask() {
local prompt default reply
Expand Down Expand Up @@ -36,28 +57,57 @@ ask() {
done
}

# Helpful variables
DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null 2>&1 && pwd )"
REPO=$(realpath "$DIR/..")
DOTENV="$REPO/.env"

# Set environment variables for the build process
export GIT_REVISION=$(git rev-parse --short HEAD)

if [ -z "$1" ]; then
TAG=$(git rev-parse --short HEAD)
else
TAG=$1
# Load .env file from project root if it exists
if [ -f $DOTENV ]; then
set -o allexport
source $DOTENV
set +o allexport
fi

# Parse command line options with getopt
OPTIND=1
TAG=${GIT_REVISION}
PLATFORM="linux/amd64"

while getopts htp: opt; do
case $opt in
h)
show_help
exit 0
;;
t) TAG=$OPTARG
;;
p) PLATFORM=$OPTARG
;;
*)
show_help >&2
exit 2
;;
esac
done
shift "$((OPTIND-1))"


if ! ask "Continue with tag $TAG?" N; then
exit 1
fi

DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null 2>&1 && pwd )"
REPO=$(realpath "$DIR/..")

docker build -t rotationalio/whisper-api:$TAG -f $DIR/api/Dockerfile $REPO
docker build -t rotationalio/whisper-ui:$TAG -f $DIR/web/Dockerfile $REPO
# Build the images
docker buildx build --platform $PLATFORM -t rotationalio/whisper-api:$TAG -f $DIR/api/Dockerfile --build-arg GIT_REVISION=${GIT_REVISION} $REPO
docker buildx build --platform $PLATFORM -t rotationalio/whisper-ui:$TAG -f $DIR/web/Dockerfile --build-arg GIT_REVISION=${GIT_REVISION} $REPO

docker tag rotationalio/whisper-api:$TAG gcr.io/rotationalio-habanero/whisper-api:$TAG
docker tag rotationalio/whisper-ui:$TAG gcr.io/rotationalio-habanero/whisper-ui:$TAG

docker push rotationalio/whisper-api:$TAG
docker push rotationalio/whisper-ui:$TAG
docker push gcr.io/rotationalio-habanero/whisper-api:$TA
docker push gcr.io/rotationalio-habanero/whisper-ui:$TA
docker push gcr.io/rotationalio-habanero/whisper-api:$TAG
docker push gcr.io/rotationalio-habanero/whisper-ui:$TAG
4 changes: 4 additions & 0 deletions containers/web/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,10 @@ RUN yarn
# Set production environment variable for build context
ARG REACT_APP_API_BASE_URL "https://api.whisper.rotational.dev/v1"
ARG REACT_APP_UI_BASE_URL "https://whisper.rotational.dev"
ARG REACT_APP_GIT_REVISION=""
ARG REACT_APP_RELEASE_VERSION=""
ARG REACT_APP_SENTRY_DSN=""
ARG REACT_APP_SENTRY_ENVIRONMENT="production"
ARG NODE_ENV "production"

# Build app with browserify
Expand Down
31 changes: 22 additions & 9 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,23 @@ services:
ports:
- "8318:8318"
environment:
WHISPER_BIND_ADDR: ":8318"
WHISPER_MAINTENANCE: "false"
WHISPER_MODE: "debug"
WHISPER_LOG_LEVEL: "debug"
WHISPER_CONSOLE_LOG: "true"
GOOGLE_APPLICATION_CREDENTIALS: "/run/secret/whisper_sa"
GOOGLE_PROJECT_NAME: "rotationalio-habanero"
WHISPER_GOOGLE_TESTING: "true"
- WHISPER_BIND_ADDR=:8318
- WHISPER_MAINTENANCE=false
- WHISPER_MODE=debug
- WHISPER_LOG_LEVEL=debug
- WHISPER_CONSOLE_LOG=true
- GOOGLE_APPLICATION_CREDENTIALS=/run/secret/whisper_sa
- GOOGLE_PROJECT_NAME=rotationalio-habanero
- WHISPER_GOOGLE_TESTING=true
- WHISPER_SENTRY_DSN
- WHISPER_SENTRY_SERVER_NAME=localhost
- WHISPER_SENTRY_ENVIRONMENT=development
- WHISPER_SENTRY_RELEASE=v1.2.0-dev
- WHISPER_SENTRY_TRACK_PERFORMANCE=true
- WHISPER_SENTRY_SAMPLE_RATE=1.0
- WHISPER_SENTRY_REPORT_ERRORS=true
- WHISPER_SENTRY_REPANIC=true
- WHISPER_SENTRY_DEBUG=false
secrets:
- whisper_sa
profiles:
Expand All @@ -29,7 +38,11 @@ services:
args:
- "REACT_APP_API_BASE_URL=http://localhost:8318/v1"
- "REACT_APP_UI_BASE_URL=http://localhost:3000"
- "NODE_ENV=production"
- "REACT_APP_GIT_REVISION"
- "REACT_APP_RELEASE_VERSION=1.2.0-dev"
- "REACT_APP_SENTRY_DSN"
- "REACT_APP_SENTRY_ENVIRONMENT=staging"
- "NODE_ENV=staging"
image: rotationalio/whisper-ui:local
ports:
- "3000:80"
Expand Down
3 changes: 2 additions & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,13 @@ go 1.20

require (
cloud.google.com/go/secretmanager v1.11.0
github.com/dn365/gin-zerolog v0.0.0-20171227063204-b43714b00db1
github.com/getsentry/sentry-go v0.21.0
github.com/gin-contrib/cors v1.4.0
github.com/gin-gonic/gin v1.9.1
github.com/googleapis/gax-go v1.0.3
github.com/joho/godotenv v1.5.1
github.com/kelseyhightower/envconfig v1.4.0
github.com/oklog/ulid/v2 v2.1.0
github.com/rs/zerolog v1.29.1
github.com/stretchr/testify v1.8.4
github.com/urfave/cli/v2 v2.25.5
Expand Down
10 changes: 8 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,6 @@ github.com/creack/pty v1.1.9/go.mod h1:oKZEueFk5CKHvIhNR5MUki03XCEU+Q6VDXinZuGJ3
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/dn365/gin-zerolog v0.0.0-20171227063204-b43714b00db1 h1:qwfOp+dwJnhdRFWsXkRMb+EZz0BgMQ8VD77OgBjuRUQ=
github.com/dn365/gin-zerolog v0.0.0-20171227063204-b43714b00db1/go.mod h1:AAlcXL9Ejp3TUsJRWJtjbIpK3p1L9z987raCTYL17j4=
github.com/envoyproxy/go-control-plane v0.9.0/go.mod h1:YTl/9mNaCwkRvm6d1a2C3ymFceY/DCBVvsKhRF0iEA4=
github.com/envoyproxy/go-control-plane v0.9.1-0.20191026205805-5f8ba28d4473/go.mod h1:YTl/9mNaCwkRvm6d1a2C3ymFceY/DCBVvsKhRF0iEA4=
github.com/envoyproxy/go-control-plane v0.9.4/go.mod h1:6rpuAdCZL397s3pYoYcLgu1mIlRU8Am5FuJP05cCM98=
Expand All @@ -45,6 +43,8 @@ github.com/envoyproxy/go-control-plane v0.9.10-0.20210907150352-cf90f659a021/go.
github.com/envoyproxy/protoc-gen-validate v0.1.0/go.mod h1:iSmxcyjqTsJpI2R4NaDN7+kN2VEUnK/pcBlmesArF7c=
github.com/gabriel-vasile/mimetype v1.4.2 h1:w5qFW6JKBz9Y393Y4q372O9A7cUSequkh1Q7OhCmWKU=
github.com/gabriel-vasile/mimetype v1.4.2/go.mod h1:zApsH/mKG4w07erKIaJPFiX0Tsq9BFQgN3qGY5GnNgA=
github.com/getsentry/sentry-go v0.21.0 h1:c9l5F1nPF30JIppulk4veau90PK6Smu3abgVtVQWon4=
github.com/getsentry/sentry-go v0.21.0/go.mod h1:lc76E2QywIyW8WuBnwl8Lc4bkmQH4+w1gwTf25trprY=
github.com/ghodss/yaml v1.0.0/go.mod h1:4dBDuWmgqj2HViK6kFavaiC9ZROes6MMH2rRYeMEF04=
github.com/gin-contrib/cors v1.4.0 h1:oJ6gwtUl3lqV0WEIwM/LxPF1QZ5qe2lGWdY2+bz7y0g=
github.com/gin-contrib/cors v1.4.0/go.mod h1:bs9pNM0x/UsmHPBWT2xZz9ROh8xYjYkiURUfmBoMlcs=
Expand All @@ -53,6 +53,7 @@ github.com/gin-contrib/sse v0.1.0/go.mod h1:RHrZQHXnP2xjPF+u1gW/2HnVO7nvIa9PG3Gm
github.com/gin-gonic/gin v1.8.1/go.mod h1:ji8BvRH1azfM+SYow9zQ6SZMvR8qOMZHmsCuWR9tTTk=
github.com/gin-gonic/gin v1.9.1 h1:4idEAncQnU5cB7BeOkPtxjfCSye0AAm1R0RVIqJ+Jmg=
github.com/gin-gonic/gin v1.9.1/go.mod h1:hPrL7YrpYKXt5YId3A/Tnip5kqbEAP+KLuI3SUcPTeU=
github.com/go-errors/errors v1.4.2 h1:J6MZopCL4uSllY1OfXM374weqZFFItUbrImctkmUxIA=
github.com/go-playground/assert/v2 v2.0.1/go.mod h1:VDjEfimB/XKnb+ZQfWdccd7VUvScMdVu0Titje2rxJ4=
github.com/go-playground/assert/v2 v2.2.0 h1:JvknZsQTYeFEAhQwI4qEt9cyV5ONwRHC+lYKSsYSR8s=
github.com/go-playground/locales v0.14.0/go.mod h1:sawfccIbzZTqEDETgFXqTho0QybSa7l++s0DH+LDiLs=
Expand Down Expand Up @@ -144,10 +145,15 @@ github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd h1:TRLaZ9cD/w
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd/go.mod h1:6dJC0mAP4ikYIbvyc7fijjWJddQyLn8Ig3JB5CqoB9Q=
github.com/modern-go/reflect2 v1.0.2 h1:xBagoLtFs94CBntxluKeaWgTMpvLxC4ur3nMaC9Gz0M=
github.com/modern-go/reflect2 v1.0.2/go.mod h1:yWuevngMOJpCy52FWWMvUC8ws7m/LJsjYzDa0/r8luk=
github.com/oklog/ulid/v2 v2.1.0 h1:+9lhoxAP56we25tyYETBBY1YLA2SaoLvUFgrP2miPJU=
github.com/oklog/ulid/v2 v2.1.0/go.mod h1:rcEKHmBBKfef9DhnvX7y1HZBYxjXb0cP5ExxNsTT1QQ=
github.com/pborman/getopt v0.0.0-20170112200414-7148bc3a4c30/go.mod h1:85jBQOZwpVEaDAr341tbn15RS4fCAsIst0qp7i8ex1o=
github.com/pelletier/go-toml/v2 v2.0.1/go.mod h1:r9LEWfGN8R5k0VXJ+0BkIe7MYkRdwZOjgMj2KwnJFUo=
github.com/pelletier/go-toml/v2 v2.0.8 h1:0ctb6s9mE31h0/lhu+J6OPmVeDxJn+kYnJc2jZR9tGQ=
github.com/pelletier/go-toml/v2 v2.0.8/go.mod h1:vuYfssBdrU2XDZ9bYydBu6t+6a6PYNcZljzZR9VXg+4=
github.com/pingcap/errors v0.11.4 h1:lFuQV/oaUMGcD2tqt+01ROSmJs75VG1ToEOkZIZ4nE4=
github.com/pkg/diff v0.0.0-20210226163009-20ebb0f2a09e/go.mod h1:pJLUxLENpZxwdsKMEsNbx1VGcRFpLqf3715MtcvvzbA=
github.com/pkg/errors v0.9.1 h1:FEBLx1zS214owpjy7qsBeixbURkuhQAwrK5UwLGTwt4=
github.com/pkg/errors v0.9.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
Expand Down
Loading

0 comments on commit 831f705

Please sign in to comment.