-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* feat: Add initial commands for maintenance windows * fix: Fix duration type * fix: Fix parameters for create maintenance window * fix: Fix fail arg for curl * fix: Evaulate description for maintenance * feat: Evaluate end maintenance window id * feat: Add id output for maintenance window * fix: Fix maintenance window default id * fix: Fix duplicate eval * feat: Add run-with-maintenance command * docs: Add examples, add jq requirement to orb description
- Loading branch information
Timo Reymann
committed
Feb 9, 2022
1 parent
5e87890
commit b313f5a
Showing
14 changed files
with
215 additions
and
55 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
.idea/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,9 @@ | ||
version: 2.1 | ||
|
||
description: | | ||
PagerDuty functionality for your pipelines | ||
PagerDuty functionality for your pipelines. | ||
This orb requires jq to be installed (which is the case for cimg/* docker images). | ||
display: | ||
home_url: "https://github.com/trustedshops-public/circleci-orb-pagerduty" | ||
source_url: "https://github.com/trustedshops-public/circleci-orb-pagerduty" |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
description: > | ||
Create maintenance window. | ||
The created maintenance window id is stored inside $PAGERDUTY_MAINTENANCE_WINDOW_ID | ||
parameters: | ||
pagerduty-token: | ||
default: PAGERDUTY_TOKEN | ||
description: Environment variable containing pagerduty token for api calls | ||
type: env_var_name | ||
duration: | ||
default: 15 | ||
description: Duration of the maintenance interval in minutes | ||
type: integer | ||
description: | ||
default: "CircleCI Deployment ${CIRCLE_WORKFLOW_ID}-${CIRCLE_JOB} | for more information see ${CIRCLE_BUILD_URL}" | ||
description: Description for the maintenance window, can contain env vars | ||
type: string | ||
services: | ||
description: List of services, seperated with comma WITHOUT spaces | ||
type: string | ||
from-mail: | ||
default: PAGERDUTY_EMAIL | ||
description: Environment variable containing a valid mail address as which the pagerduty maintenance window should be created | ||
type: env_var_name | ||
|
||
steps: | ||
- run: | ||
name: Create pagerduty maintenance window | ||
environment: | ||
PARAM_PAGERDUTY_TOKEN: <<parameters.pagerduty-token>> | ||
PARAM_PAGERDUTY_MAIL: <<parameters.from-mail>> | ||
PARAM_DURATION_MINUTES: <<parameters.duration>> | ||
PARAM_DESCRIPTION: <<parameters.description>> | ||
PARAM_SERVICES: <<parameters.services>> | ||
command: <<include(scripts/maintenance-window-create.sh)>> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
description: > | ||
Delete maintenance window | ||
parameters: | ||
maintenance-window-id: | ||
default: PAGERDUTY_MAINTENANCE_WINDOW_ID | ||
description: Maintenance window id | ||
type: string | ||
pagerduty-token: | ||
default: PAGERDUTY_TOKEN | ||
description: Environment variable containing pagerduty token for api calls | ||
type: env_var_name | ||
|
||
steps: | ||
- run: | ||
name: Delete pagerduty maintenance window | ||
environment: | ||
PARAM_MAINTENANCE_WINDOW_ID: <<parameters.maintenance-window-id>> | ||
PARAM_PAGERDUTY_TOKEN: <<parameters.pagerduty-token>> | ||
command: <<include(scripts/maintenance-window-delete.sh)>> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
description: > | ||
Run given steps with a maintenance window | ||
parameters: | ||
pagerduty-token: | ||
default: PAGERDUTY_TOKEN | ||
description: Environment variable containing pagerduty token for api calls | ||
type: env_var_name | ||
duration: | ||
default: 15 | ||
description: Duration of the maintenance interval in minutes | ||
type: integer | ||
description: | ||
default: "CircleCI Deployment ${CIRCLE_WORKFLOW_ID}-${CIRCLE_JOB} | for more information see ${CIRCLE_BUILD_URL}" | ||
description: Description for the maintenance window, can contain env vars | ||
type: string | ||
services: | ||
description: List of services, seperated with comma WITHOUT spaces | ||
type: string | ||
from-mail: | ||
default: PAGERDUTY_EMAIL | ||
description: Environment variable containing a valid mail address as which the pagerduty maintenance window should be created | ||
type: env_var_name | ||
steps: | ||
type: steps | ||
description: Steps to execute with connection open | ||
|
||
steps: | ||
- create-maintenance-window: | ||
pagerduty-token: <<parameters.pagerduty-token>> | ||
duration: <<parameters.duration>> | ||
description: <<parameters.description>> | ||
services: <<parameters.services>> | ||
from-mail: <<parameters.from-mail>> | ||
- <<parameters.steps>> | ||
- delete-maintenance-window: | ||
pagerduty-token: <<parameters.pagerduty-token>> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
description: Run your deployment with manual control over maintenance | ||
usage: | ||
version: 2.1 | ||
orbs: | ||
pagerduty: trustedshops-public/pagerduty@<version> | ||
workflows: | ||
version: 2 | ||
continious: | ||
jobs: | ||
- deploy: | ||
steps: | ||
- pagerduty/create-maintenance-window: | ||
services: PXXXX,PXYZ | ||
duration: 60 | ||
- run: | ||
name: Run deployment | ||
script: make deploy | ||
# Don't stop, but rather wait one hour because e.g. your legacy system requires some time to recover | ||
filters: | ||
branches: | ||
only: [ main ] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
description: Run your deployment with pagerduty maintenance | ||
usage: | ||
version: 2.1 | ||
orbs: | ||
pagerduty: trustedshops-public/pagerduty@<version> | ||
workflows: | ||
version: 2 | ||
continious: | ||
jobs: | ||
- deploy: | ||
steps: | ||
- pagerduty/run-with-maintenance: | ||
services: PXXXX,PXYZ | ||
steps: | ||
- run: | ||
name: Run deployment | ||
script: make deploy | ||
filters: | ||
branches: | ||
only: [ main ] |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
#!/bin/bash | ||
|
||
# Check if jq is installed | ||
if ! command -v jq &> /dev/null | ||
then | ||
echo "jq is required, but could not be found." | ||
exit 2 | ||
fi | ||
|
||
# Join all arguments by given separator | ||
function join_by { | ||
local IFS="$1"; | ||
shift; | ||
echo "$*"; | ||
} | ||
|
||
# Escape string for json | ||
function json_escape() { | ||
jq -R -s '.' <<< "$1" | ||
} | ||
|
||
PARAM_DESCRIPTION=$(eval echo "$PARAM_DESCRIPTION") | ||
|
||
# date format to use for pagerduty | ||
date_format='%Y-%m-%dT%H:%M:%S-00:00' | ||
pagerduty_token=$(eval echo "\$$PARAM_PAGERDUTY_TOKEN") | ||
|
||
# Build service list with json objects | ||
IFS="," | ||
services_json=() | ||
for service in ${PARAM_SERVICES} | ||
do | ||
services_json+=('{"id": "'"${service}"'", "type": "service_reference"}') | ||
done | ||
|
||
# Create maintenance | ||
response=$(curl --request POST \ | ||
--fail \ | ||
--url "https://api.pagerduty.com/maintenance_windows" \ | ||
--header 'Accept: application/vnd.pagerduty+json;version=2' \ | ||
--header "Authorization: Token token=${pagerduty_token}" \ | ||
--header 'Content-Type: application/json' \ | ||
--header "From: ${PARAM_PAGERDUTY_MAIL}" \ | ||
--data @- <<TEXT | ||
{ | ||
"maintenance_window": { | ||
"type": "maintenance_window", | ||
"start_time": "$(date -u +${date_format})", | ||
"end_time": "$(date -u -d "+ ${PARAM_DURATION_MINUTES} minutes" +${date_format})", | ||
"description": $(json_escape "${PARAM_DESCRIPTION}"), | ||
"services": [$(join_by "," "${services_json[@]}")] | ||
} | ||
} | ||
TEXT | ||
) | ||
|
||
# Extract and set env var | ||
id=$(echo "$response" | jq -r ".maintenance_window.id") | ||
export PAGERDUTY_MAINTENANCE_WINDOW_ID="${id}" | ||
echo "export PAGERDUTY_MAINTENANCE_WINDOW_ID='${id}'" >> "$BASH_ENV" | ||
|
||
echo "Maintenance window created: ${PAGERDUTY_MAINTENANCE_WINDOW_ID}" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
#!/bin/bash | ||
|
||
if ! command -v jq &> /dev/null | ||
then | ||
echo "jq is required, but could not be found." | ||
exit 2 | ||
fi | ||
|
||
pagerduty_token=$(eval echo "\$$PARAM_PAGERDUTY_TOKEN") | ||
PARAM_MAINTENANCE_WINDOW_ID=$(eval echo "\$$PARAM_MAINTENANCE_WINDOW_ID") | ||
|
||
curl --request DELETE \ | ||
--url "https://api.pagerduty.com/maintenance_windows/${PARAM_MAINTENANCE_WINDOW_ID}" \ | ||
--header 'Accept: application/vnd.pagerduty+json;version=2' \ | ||
--header "Authorization: Token token=${pagerduty_token}" \ | ||
--header 'Content-Type: application/json' | jq |