diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index c782c28..e586310 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -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 @@ -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: @@ -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: @@ -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: @@ -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: @@ -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: diff --git a/newrelic-notify.sh b/newrelic-notify.sh new file mode 100755 index 0000000..bc7e596 --- /dev/null +++ b/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