Skip to content

Commit

Permalink
Update jsonnet libs and add rollback pipeline (#2301)
Browse files Browse the repository at this point in the history
  • Loading branch information
mattgauntseo-sentry committed Jul 17, 2023
1 parent 693bcb8 commit de43130
Show file tree
Hide file tree
Showing 9 changed files with 75 additions and 14 deletions.
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,7 @@ help: ## this help
gocd: ## Build GoCD pipelines
@ rm -rf ./gocd/generated-pipelines
@ mkdir -p ./gocd/generated-pipelines
@ cd ./gocd/templates && jb install
@ cd ./gocd/templates && jb install && jb update
@ find . -type f \( -name '*.libsonnet' -o -name '*.jsonnet' \) -print0 | xargs -n 1 -0 jsonnetfmt -i
@ find . -type f \( -name '*.libsonnet' -o -name '*.jsonnet' \) -print0 | xargs -n 1 -0 jsonnet-lint -J ./gocd/templates/vendor
@ cd ./gocd/templates && jsonnet -J vendor -m ../generated-pipelines ./relay.jsonnet
Expand Down
4 changes: 2 additions & 2 deletions gocd/generated-pipelines/relay-next-monitor.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ pipelines:
group: relay-next
lock_behavior: unlockWhenFinished
materials:
deploy-relay-next-us-pipeline-complete:
pipeline: deploy-relay-next-us
deploy-relay-next-pipeline-complete:
pipeline: deploy-relay-next
stage: pipeline-complete
relay_repo:
branch: master
Expand Down
6 changes: 3 additions & 3 deletions gocd/generated-pipelines/relay-next-us.yaml
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
format_version: 10
pipelines:
deploy-relay-next-us:
display_order: 1
display_order: 3
environment_variables:
SENTRY_REGION: us
group: relay-next
lock_behavior: unlockWhenFinished
materials:
deploy-relay-next-pipeline-complete:
pipeline: deploy-relay-next
deploy-relay-next-monitor-pipeline-complete:
pipeline: deploy-relay-next-monitor
stage: pipeline-complete
relay_repo:
branch: master
Expand Down
57 changes: 57 additions & 0 deletions gocd/generated-pipelines/rollback-relay-next.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
format_version: 10
pipelines:
rollback-relay-next:
display_order: 1
environment_variables:
ALL_PIPELINE_FLAGS: --pipeline="deploy-relay-next-monitor" --pipeline="deploy-relay-next-us" --pipeline="deploy-relay-next"
GOCD_ACCESS_TOKEN: '{{SECRET:[devinfra][gocd_access_token]}}'
REGION_PIPELINE_FLAGS: --pipeline="deploy-relay-next-monitor" --pipeline="deploy-relay-next-us"
ROLLBACK_MATERIAL_NAME: relay_repo
ROLLBACK_STAGE: deploy-production
group: relay-next
lock_behavior: unlockWhenFinished
materials:
deploy-relay-next-us-pipeline-complete:
pipeline: deploy-relay-next-us
stage: pipeline-complete
stages:
- pause_pipelines:
approval:
type: manual
jobs:
rollback:
tasks:
- script: |
##!/bin/bash
## Note: $ALL_PIPELINE_FLAGS has no quoting, for word expansion
## shellcheck disable=SC2086
if [[ "${ALL_PIPELINE_FLAGS:-}" ]]; then
set -- $ALL_PIPELINE_FLAGS
fi
## Pause all pipelines in the pipedream
gocd-pause-and-cancel-pipelines \
--pause-message="This pipeline is being rolled back, please check with team before un-pausing." \
"$@"
start_rollback:
jobs:
rollback:
tasks:
- script: |
##!/bin/bash
## Note: $REGION_PIPELINE_FLAGS has no quoting, for word expansion
## shellcheck disable=SC2086
if [[ "${REGION_PIPELINE_FLAGS:-}" ]]; then
set -- $REGION_PIPELINE_FLAGS
fi
## Get sha from the given pipeline run to deploy to all pipedream pipelines.
sha=$(gocd-sha-for-pipeline --material-name="${ROLLBACK_MATERIAL_NAME}")
gocd-emergency-deploy \
--commit-sha="${sha}" \
--deploy-stage="${ROLLBACK_STAGE}" \
--pause-message="This pipeline was rolled back, please check with team before un-pausing." \
"$@"
4 changes: 2 additions & 2 deletions gocd/templates/jsonnetfile.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,10 @@
"source": {
"git": {
"remote": "https://github.com/getsentry/gocd-jsonnet.git",
"subdir": "v1.0.0"
"subdir": "libs"
}
},
"version": "main"
"version": "v1.1.4"
}
],
"legacyImports": true
Expand Down
6 changes: 3 additions & 3 deletions gocd/templates/jsonnetfile.lock.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,11 @@
"source": {
"git": {
"remote": "https://github.com/getsentry/gocd-jsonnet.git",
"subdir": "v1.0.0"
"subdir": "libs"
}
},
"version": "7636a8579792e6e1e66b0b567583e5e05764c39f",
"sum": "eOpSoGZ9y3+6O3qllOXVBdiHfQ2xwcnAJWqlE4k3Rj8="
"version": "fc28e0fb504269698df9b19109543057eb5549cd",
"sum": "/R7fdDl7Sg9wqOEoDVkp49qiuMVtzjvAcqVGX4HbGG4="
}
],
"legacyImports": false
Expand Down
2 changes: 1 addition & 1 deletion gocd/templates/libs/relay-pops.libsonnet
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
local STAGE_NAME = 'deploy-pops';
local gocdtasks = import 'github.com/getsentry/gocd-jsonnet/v1.0.0/gocd-tasks.libsonnet';
local gocdtasks = import 'github.com/getsentry/gocd-jsonnet/libs/gocd-tasks.libsonnet';

// Create a gocd job that will run the deploy-pop script
local deploy_pop_job(region) =
Expand Down
2 changes: 1 addition & 1 deletion gocd/templates/libs/relay.libsonnet
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
local pops = import './relay-pops.libsonnet';
local gocdtasks = import 'github.com/getsentry/gocd-jsonnet/v1.0.0/gocd-tasks.libsonnet';
local gocdtasks = import 'github.com/getsentry/gocd-jsonnet/libs/gocd-tasks.libsonnet';

function(region) {
environment_variables: {
Expand Down
6 changes: 5 additions & 1 deletion gocd/templates/relay.jsonnet
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
local relay = import './libs/relay.libsonnet';
local pipedream = import 'github.com/getsentry/gocd-jsonnet/v1.0.0/pipedream.libsonnet';
local pipedream = import 'github.com/getsentry/gocd-jsonnet/libs/pipedream.libsonnet';

local pipedream_config = {
name: 'relay-next',
Expand All @@ -12,6 +12,10 @@ local pipedream_config = {
destination: 'relay',
},
},
rollback: {
material_name: 'relay_repo',
stage: 'deploy-production',
},
};

pipedream.render(pipedream_config, relay)

0 comments on commit de43130

Please sign in to comment.