Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[cft] Add pipeline to shutdown deployment #136659

Merged
merged 5 commits into from
Jul 20, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions .buildkite/pipelines/purge_cloud_deployment.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
steps:
- block: "Purge deployment"
prompt: "Fill out the details to shutdown a PR deployment"
fields:
- text: "Pull Request Number"
key: "kibana-pull-request"
if: "build.env('KIBANA_PULL_REQUEST') == null || build.env('KIBANA_PULL_REQUEST') == ''"

- command: .buildkite/scripts/steps/cloud/purge_deployment.sh
label: Purge a cloud deployment
timeout_in_minutes: 10
agents:
queue: kibana-default
2 changes: 1 addition & 1 deletion .buildkite/pipelines/purge_cloud_deployments.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
steps:
- command: .buildkite/scripts/steps/cloud/purge.sh
- command: .buildkite/scripts/steps/cloud/purge_deployments.sh
label: Purge old cloud deployments
timeout_in_minutes: 10
agents:
Expand Down
5 changes: 0 additions & 5 deletions .buildkite/scripts/steps/cloud/purge.sh

This file was deleted.

5 changes: 5 additions & 0 deletions .buildkite/scripts/steps/cloud/purge_deployment.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
#!/usr/bin/env bash

set -euo pipefail

ts-node .buildkite/scripts/steps/cloud/purge_deployment.ts
35 changes: 35 additions & 0 deletions .buildkite/scripts/steps/cloud/purge_deployment.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the Elastic License
* 2.0 and the Server Side Public License, v 1; you may not use this file except
* in compliance with, at your election, the Elastic License 2.0 or the Server
* Side Public License, v 1.
*/

import { execSync } from 'child_process';

const deploymentsListJson = execSync('ecctl deployment list --output json').toString();
const { deployments } = JSON.parse(deploymentsListJson);

const prNumber = parseInt(
process.env.KIBANA_PULL_REQUEST ||
execSync('buildkite-agent meta-data get kibana-pull-request').toString(),
10
);
const deploymentName = `kibana-pr-${prNumber}`;
const deployment = deployments.find((d: any) => d.name === deploymentName);

if (!prNumber || !deployment) {
console.error(`${deploymentName} not found`);
process.exit(1);
}

console.log(`Scheduling deployment for deletion: ${deployment.name} / ${deployment.id}`);
try {
execSync(`ecctl deployment shutdown --force '${deployment.id}'`, { stdio: 'inherit' });
execSync(`vault delete secret/kibana-issues/dev/cloud-deploy/${deployment.name}`, {
stdio: 'inherit',
});
} catch (ex) {
console.error(ex.toString());
}
5 changes: 5 additions & 0 deletions .buildkite/scripts/steps/cloud/purge_deployments.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
#!/usr/bin/env bash

set -euo pipefail

ts-node .buildkite/scripts/steps/cloud/purge_deployments.ts