Skip to content

Commit

Permalink
Add new relic notification script post deploy. (#27)
Browse files Browse the repository at this point in the history
* Add new relic notification script post deploy.

* Review fixes:

- Consolidate kubectl commands
- Get actual API key
- Update jsonpath to image to be more specific

* Review fixes #2:

- Use regex to get image hash from yaml (instead of asking k8s)
- Alphabetize some things

* Review fixes part 3:

- Wrap subshell command to capture output
- Improve comments
- Notify new relic prior to waiting for/running acceptance tests
  • Loading branch information
jpetto authored and jgmize committed Jul 10, 2019
1 parent 189f8b1 commit dd35bba
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 5 deletions.
16 changes: 11 additions & 5 deletions .gitlab-ci.yml
Expand Up @@ -12,6 +12,7 @@ stages:
script:
- kubectl_1.11 apply -f ${DEPLOYMENT}
- kubectl_1.11 rollout status -f ${DEPLOYMENT}/web-deploy.yaml
- ./newrelic-notify.sh
# Retry doesn't seem to work for now. Sleep a few seconds before running the
# tests.
- sleep 5s
Expand All @@ -21,8 +22,9 @@ stages:
deploy oregon-b dev:
extends: .deploy
variables:
KUBECONFIG: /home/gitlab-runner/.kube/oregon-b.kubeconfig
DEPLOYMENT: oregon-b/snippets-dev
KUBECONFIG: /home/gitlab-runner/.kube/oregon-b.kubeconfig
NEWRELIC_APP: snippets-dev-oregon-b
URL: https://snippets-dev.oregon-b.moz.works
only:
changes:
Expand All @@ -31,8 +33,9 @@ deploy oregon-b dev:
deploy oregon-b stage:
extends: .deploy
variables:
KUBECONFIG: /home/gitlab-runner/.kube/oregon-b.kubeconfig
DEPLOYMENT: oregon-b/snippets-stage
KUBECONFIG: /home/gitlab-runner/.kube/oregon-b.kubeconfig
NEWRELIC_APP: snippets-stage-oregon-b
URL: https://snippets.allizom.org
only:
changes:
Expand All @@ -41,8 +44,9 @@ deploy oregon-b stage:
deploy oregon-b prod:
extends: .deploy
variables:
KUBECONFIG: /home/gitlab-runner/.kube/oregon-b.kubeconfig
DEPLOYMENT: oregon-b/snippets-prod
KUBECONFIG: /home/gitlab-runner/.kube/oregon-b.kubeconfig
NEWRELIC_APP: snippets-prod-oregon-b
URL: https://snippets-prod.oregon-b.moz.works
only:
changes:
Expand All @@ -51,8 +55,9 @@ deploy oregon-b prod:
deploy frankfurt prod:
extends: .deploy
variables:
KUBECONFIG: /home/gitlab-runner/.kube/frankfurt.kubeconfig
DEPLOYMENT: frankfurt/snippets-prod
KUBECONFIG: /home/gitlab-runner/.kube/frankfurt.kubeconfig
NEWRELIC_APP: snippets-prod-frankfurt
URL: https://snippets-prod.frankfurt.moz.works
only:
changes:
Expand All @@ -61,8 +66,9 @@ deploy frankfurt prod:
deploy oregon-b admin:
extends: .deploy
variables:
KUBECONFIG: /home/gitlab-runner/.kube/oregon-b.kubeconfig
DEPLOYMENT: oregon-b/snippets-admin
KUBECONFIG: /home/gitlab-runner/.kube/oregon-b.kubeconfig
NEWRELIC_APP: snippets-admin-oregon-b
URL: https://snippets-admin.mozilla.org
only:
changes:
Expand Down
19 changes: 19 additions & 0 deletions newrelic-notify.sh
@@ -0,0 +1,19 @@
#!/bin/bash

set -ex pipefail

NEWRELIC_USER=gitlab

API_KEY=$(< ~/.newrelic-api-key)

# the image value in the yaml contains the first 7 digits of the git commit hash
# yaml line format is as follows:
# image: mozorg/snippets:283065b
GIT_COMMIT_SHORT="$(grep -oP '(image: .+?:)\K.*' ${DEPLOYMENT}/web-deploy.yaml)"

# go tell new relic
curl -s -H "x-api-key:${API_KEY}" \
-d "deployment[app_name]=${NEWRELIC_APP}" \
-d "deployment[revision]=${GIT_COMMIT_SHORT}" \
-d "deployment[user]=${NEWRELIC_USER}" \
https://api.newrelic.com/deployments.xml

0 comments on commit dd35bba

Please sign in to comment.