Skip to content

Commit 30a37e7

Browse files
feat(deploy): Add gocd pipedream pipelines (#20)
Deploys the uptime-checker via gocd
1 parent 2227d70 commit 30a37e7

11 files changed

+232
-0
lines changed
+60
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
name: Validate Deployment Pipelines
2+
3+
on:
4+
pull_request:
5+
push:
6+
branches: [main, test-me-*]
7+
8+
concurrency:
9+
group: ${{ github.workflow }}-${{ github.head_ref || github.run_id }}
10+
cancel-in-progress: true
11+
12+
jobs:
13+
files-changed:
14+
name: files-changed
15+
runs-on: ubuntu-latest
16+
# Map a step output to a job output
17+
outputs:
18+
gocd: ${{ steps.changes.outputs.gocd }}
19+
steps:
20+
- uses: actions/checkout@v3
21+
- name: Check for relevant file changes
22+
uses: getsentry/paths-filter@4512585405083f25c027a35db413c2b3b9006d50 # v2.11.1
23+
id: changes
24+
with:
25+
filters: |
26+
gocd:
27+
- 'gocd/**'
28+
- '.github/workflows/validate-pipelines.yml'
29+
30+
validate:
31+
if: needs.files-changed.outputs.gocd == 'true'
32+
needs: files-changed
33+
name: Validate GoCD Pipelines
34+
runs-on: ubuntu-latest
35+
36+
# required for google auth
37+
permissions:
38+
contents: "read"
39+
id-token: "write"
40+
41+
steps:
42+
- uses: actions/checkout@v3
43+
- id: 'auth'
44+
uses: google-github-actions/auth@v1
45+
with:
46+
workload_identity_provider: 'projects/868781662168/locations/global/workloadIdentityPools/prod-github/providers/github-oidc-pool'
47+
service_account: '[email protected]'
48+
token_format: 'id_token'
49+
id_token_audience: '610575311308-9bsjtgqg4jm01mt058rncpopujgk3627.apps.googleusercontent.com'
50+
id_token_include_email: true
51+
- uses: getsentry/action-gocd-jsonnet@v1
52+
with:
53+
jb-install: true
54+
jsonnet-dir: gocd/templates
55+
generated-dir: gocd/generated-pipelines
56+
- uses: getsentry/action-validate-gocd-pipelines@v1
57+
with:
58+
configrepo: uptime-checker__main
59+
gocd_access_token: ${{ secrets.GOCD_ACCESS_TOKEN }}
60+
google_oidc_token: ${{ steps.auth.outputs.id_token }}

.gitignore

+3
Original file line numberDiff line numberDiff line change
@@ -1 +1,4 @@
11
/target
2+
3+
/gocd/generated-pipelines
4+
/gocd/templates/vendor

Makefile

+17
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
SHELL=/bin/bash
2+
3+
gocd: ## Build GoCD pipelines
4+
rm -rf ./gocd/generated-pipelines
5+
mkdir -p ./gocd/generated-pipelines
6+
cd ./gocd/templates && jb install && jb update
7+
8+
# Format
9+
find . -type f \( -name '*.libsonnet' -o -name '*.jsonnet' \) -print0 | xargs -n 1 -0 jsonnetfmt -i
10+
# Lint
11+
find . -type f \( -name '*.libsonnet' -o -name '*.jsonnet' \) -print0 | xargs -n 1 -0 jsonnet-lint -J ./gocd/templates/vendor
12+
# Build
13+
cd ./gocd/templates && find . -type f \( -name '*.jsonnet' \) -print0 | xargs -n 1 -0 jsonnet --ext-code output-files=true -J vendor -m ../generated-pipelines
14+
15+
# Convert JSON to yaml
16+
cd ./gocd/generated-pipelines && find . -type f \( -name '*.yaml' \) -print0 | xargs -n 1 -0 yq -p json -o yaml -i
17+
.PHONY: gocd
+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
#!/bin/bash
2+
3+
/devinfra/scripts/checks/googlecloud/checkcloudbuild.py \
4+
"${GO_REVISION_UPTIME_CHECKER_REPO}" \
5+
"sentryio" \
6+
"us-central1-docker.pkg.dev/sentryio/uptime-checker/image"
+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
#!/bin/bash
2+
3+
/devinfra/scripts/checks/githubactions/checkruns.py \
4+
"getsentry/uptime-checker" \
5+
"${GO_REVISION_UPTIME_CHECKER_REPO}" \
6+
"test"

gocd/templates/bash/deploy.sh

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
#!/bin/bash
2+
3+
eval $(/devinfra/scripts/regions/project_env_vars.py --region="${SENTRY_REGION}")
4+
5+
/devinfra/scripts/k8s/k8stunnel &&
6+
/devinfra/scripts/k8s/k8s-deploy.py \
7+
--label-selector="${LABEL_SELECTOR}" \
8+
--image="us-central1-docker.pkg.dev/sentryio/uptime-checker/image:${GO_REVISION_UPTIME_CHECKER_REPO}" \
9+
--container-name="uptime-checker"

gocd/templates/bash/wait-canary.sh

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
#!/bin/bash
2+
3+
sleep 300

gocd/templates/jsonnetfile.json

+15
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
{
2+
"version": 1,
3+
"dependencies": [
4+
{
5+
"source": {
6+
"git": {
7+
"remote": "https://github.com/getsentry/gocd-jsonnet.git",
8+
"subdir": "libs"
9+
}
10+
},
11+
"version": "v2.10.0"
12+
}
13+
],
14+
"legacyImports": true
15+
}

gocd/templates/jsonnetfile.lock.json

+16
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
{
2+
"version": 1,
3+
"dependencies": [
4+
{
5+
"source": {
6+
"git": {
7+
"remote": "https://github.com/getsentry/gocd-jsonnet.git",
8+
"subdir": "libs"
9+
}
10+
},
11+
"version": "74ae5728e2d7ed39fdd43cf3b2d28dde7e4567a1",
12+
"sum": "AKMGYALLyaVVVjTNnZy64PoCDA8QjxTbHBe5dCnE4tE="
13+
}
14+
],
15+
"legacyImports": false
16+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
local gocdtasks = import 'github.com/getsentry/gocd-jsonnet/libs/gocd-tasks.libsonnet';
2+
3+
function(region) {
4+
environment_variables: {
5+
// SENTRY_REGION is used by the dev-infra scripts to connect to GKE
6+
SENTRY_REGION: region,
7+
},
8+
materials: {
9+
uptime_checker_repo: {
10+
git: '[email protected]:getsentry/uptime-checker.git',
11+
shallow_clone: true,
12+
branch: 'main',
13+
destination: 'uptime-checker',
14+
},
15+
},
16+
lock_behavior: 'unlockWhenFinished',
17+
stages: [
18+
{
19+
checks: {
20+
fetch_materials: true,
21+
jobs: {
22+
checks: {
23+
timeout: 1200,
24+
elastic_profile_id: 'uptime-checker',
25+
environment_variables: {
26+
GITHUB_TOKEN: '{{SECRET:[devinfra-github][token]}}',
27+
},
28+
tasks: [
29+
gocdtasks.script(importstr '../bash/check-github-runs.sh'),
30+
gocdtasks.script(importstr '../bash/check-cloudbuild.sh'),
31+
],
32+
},
33+
},
34+
},
35+
},
36+
{
37+
'deploy-canary': {
38+
fetch_materials: true,
39+
jobs: {
40+
deploy: {
41+
timeout: 600,
42+
elastic_profile_id: 'uptime-checker',
43+
environment_variables: {
44+
LABEL_SELECTOR: 'service=uptime-checker,env=canary',
45+
},
46+
tasks: [
47+
gocdtasks.script(importstr '../bash/deploy.sh'),
48+
gocdtasks.script(importstr '../bash/wait-canary.sh'),
49+
],
50+
},
51+
},
52+
},
53+
},
54+
{
55+
'deploy-primary': {
56+
fetch_materials: true,
57+
jobs: {
58+
deploy: {
59+
timeout: 600,
60+
elastic_profile_id: 'uptime-checker',
61+
environment_variables: {
62+
LABEL_SELECTOR: 'service=uptime-checker',
63+
},
64+
tasks: [
65+
gocdtasks.script(importstr '../bash/deploy.sh'),
66+
],
67+
},
68+
},
69+
},
70+
},
71+
],
72+
}

gocd/templates/uptime-checker.jsonnet

+25
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
local uptime_checker = import './pipelines/uptime-checker.libsonnet';
2+
local pipedream = import 'github.com/getsentry/gocd-jsonnet/libs/pipedream.libsonnet';
3+
4+
// Pipedream can be configured using this object, you can learn more about the
5+
// configuration options here: https://github.com/getsentry/gocd-jsonnet#readme
6+
local pipedream_config = {
7+
name: 'uptime-checker',
8+
auto_deploy: true,
9+
materials: {
10+
uptime_checker_repo: {
11+
git: '[email protected]:getsentry/uptime-checker.git',
12+
shallow_clone: true,
13+
branch: 'main',
14+
destination: 'uptime-checker',
15+
},
16+
},
17+
rollback: {
18+
material_name: 'uptime_checker_repo',
19+
stage: 'deploy-primary',
20+
elastic_profile_id: 'uptime-checker',
21+
},
22+
exclude_regions: ['customer-1', 'customer-2', 'customer-3', 'customer-4', 'customer-6', 'customer-7'],
23+
};
24+
25+
pipedream.render(pipedream_config, uptime_checker)

0 commit comments

Comments
 (0)