Skip to content

Commit

Permalink
feat: playbook to destroy infisical
Browse files Browse the repository at this point in the history
  • Loading branch information
kirinnee committed Sep 8, 2024
1 parent 14ad6bc commit 24bc860
Show file tree
Hide file tree
Showing 2 changed files with 127 additions and 41 deletions.
76 changes: 76 additions & 0 deletions src/books/secrets-operator-destruction/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
import type { CloudTreeCluster, ServiceTreeService } from '../../lib/service-tree-def.ts';
import type { TaskRunner } from '../../tasks/tasks.ts';
import type { ServiceTreePrompter } from '../../lib/prompts/landscape.ts';
import { $ } from 'bun';
import { password } from '@inquirer/prompts';
import type { RunBook } from '../run-book.ts';

class SecretsOperatorDestructor implements RunBook {
constructor(
private task: TaskRunner,
private stp: ServiceTreePrompter,
private sulfoxide_infisical: ServiceTreeService,
) {}

name: string = 'Destroy Secrets Operator';
desc: string = 'Teardown the secrets operator to a selected cloud-cluster';

async Run(): Promise<void> {
const cluster: CloudTreeCluster = await this.stp.Cluster(
'Which cloud do you want to create infisical in?',
'Which cluster do you want to create infisical in?',
);

const infisical = this.sulfoxide_infisical;

const i_path = `./platforms/${infisical.platform.slug}/${infisical.principal.slug}`;

await this.task.Run([
'Setup infisical',
async () => {
const pw = await password({ message: 'Enter your Bitwarden password' });

await $`echo ${pw} | nix develop -c pls setup`.cwd(i_path);
},
]);

await this.task.Run([
'Initialize general (database and ingress) Tofu',
async () => {
await $`pls general:init`.cwd(i_path);
},
]);

await this.task.Run([
'Destroy general (database and ingress) Tofu',
async () => {
await $`pls general:destroy`.cwd(i_path);
},
]);

await this.task.Run([
'Generate .env',
async () => {
await $`nix develop -c pls generate:env`.cwd(i_path);
},
]);

// provision compute
const compute = cluster.principal.slug;
await this.task.Run([
'Init Compute',
async () => {
await $`pls ${{ raw: compute }}:init`.cwd(i_path);
},
]);

await this.task.Run([
'Destroy compute',
async () => {
await $`pls ${{ raw: compute }}:destroy -- -auto-approve`.cwd(i_path);
},
]);
}
}

export { SecretsOperatorDestructor };
92 changes: 51 additions & 41 deletions src/init/runbooks.ts
Original file line number Diff line number Diff line change
@@ -1,26 +1,29 @@
import type { Dependencies } from './index.ts';
import type { TaskGenerator } from './tasks.ts';
import type { RunBook } from '../books/run-book.ts';
import type { PhysicalClusterCloudCreator } from '../books/physical-cluster-creation/cloud.ts';
import { DigitalOceanPhysicalClusterCreator } from '../books/physical-cluster-creation/digital-ocean.ts';
import { CLOUDS, LANDSCAPE_TREE, SERVICE_TREE } from '../lib/service-tree.ts';
import { PhysicalClusterCreator } from '../books/physical-cluster-creation';
import { GracefulPhysicalClusterDestructor } from '../books/graceful-physical-cluster-destruction';
import { BareAdminClusterCreator } from '../books/bare-admin-cluster-creation';
import type { BareAdminClusterCloudCreator } from '../books/bare-admin-cluster-creation/cloud.ts';
import { DigitalOceanBareAdminClusterCreator } from '../books/bare-admin-cluster-creation/digital-ocean.ts';
import type { FullAdminClusterCloudCreator } from '../books/full-admin-cluster-creation/cloud.ts';
import { DigitalOceanFullAdminClusterCreator } from '../books/full-admin-cluster-creation/digital-ocean.ts';
import { FullAdminClusterCreator } from '../books/full-admin-cluster-creation';
import { GracefulAdminClusterDestructor } from '../books/graceful-admin-cluster-destruction';
import { GenericGracefulAdminClusterDestructor } from '../books/graceful-admin-cluster-destruction/generic.ts';
import { DigitalOceanGracefulPhysicalClusterDestructor } from '../books/graceful-physical-cluster-destruction/digital-ocean.ts';
import { AdminClusterMigrator } from '../books/admin-cluster-migration';
import { AdminClusterTransitioner } from '../books/admin-cluster-migration/transition.ts';
import { AwsPhysicalClusterCreator } from '../books/physical-cluster-creation/aws.ts';
import { AwsGracefulPhysicalClusterDestructor } from '../books/graceful-physical-cluster-destruction/aws.ts';
import type { Dependencies } from "./index.ts";
import type { TaskGenerator } from "./tasks.ts";
import type { RunBook } from "../books/run-book.ts";
import type { PhysicalClusterCloudCreator } from "../books/physical-cluster-creation/cloud.ts";
import { DigitalOceanPhysicalClusterCreator } from "../books/physical-cluster-creation/digital-ocean.ts";
import { CLOUDS, LANDSCAPE_TREE, SERVICE_TREE } from "../lib/service-tree.ts";
import { PhysicalClusterCreator } from "../books/physical-cluster-creation";
import { GracefulPhysicalClusterDestructor } from "../books/graceful-physical-cluster-destruction";
import { BareAdminClusterCreator } from "../books/bare-admin-cluster-creation";
import type { BareAdminClusterCloudCreator } from "../books/bare-admin-cluster-creation/cloud.ts";
import { DigitalOceanBareAdminClusterCreator } from "../books/bare-admin-cluster-creation/digital-ocean.ts";
import type { FullAdminClusterCloudCreator } from "../books/full-admin-cluster-creation/cloud.ts";
import { DigitalOceanFullAdminClusterCreator } from "../books/full-admin-cluster-creation/digital-ocean.ts";
import { FullAdminClusterCreator } from "../books/full-admin-cluster-creation";
import { GracefulAdminClusterDestructor } from "../books/graceful-admin-cluster-destruction";
import { GenericGracefulAdminClusterDestructor } from "../books/graceful-admin-cluster-destruction/generic.ts";
import {
DigitalOceanGracefulPhysicalClusterDestructor
} from "../books/graceful-physical-cluster-destruction/digital-ocean.ts";
import { AdminClusterMigrator } from "../books/admin-cluster-migration";
import { AdminClusterTransitioner } from "../books/admin-cluster-migration/transition.ts";
import { AwsPhysicalClusterCreator } from "../books/physical-cluster-creation/aws.ts";
import { AwsGracefulPhysicalClusterDestructor } from "../books/graceful-physical-cluster-destruction/aws.ts";
import { VultrPhysicalClusterCreator } from "../books/physical-cluster-creation/vultr.ts";
import { VultrGracefulPhysicalClusterDestructor } from "../books/graceful-physical-cluster-destruction/vultr.ts";
import { SecretsOperatorDestructor } from "../books/secrets-operator-destruction";
import { SecretsOperatorCreator } from "../books/secrets-operator-creation";

function initRunBooks(d: Dependencies, t: TaskGenerator): RunBook[] {
Expand All @@ -35,7 +38,7 @@ function initRunBooks(d: Dependencies, t: TaskGenerator): RunBook[] {
d.kubectl,
sulfoxide.services.tofu,
sulfoxide.services.argocd,
CLOUDS.Vultr.slug,
CLOUDS.Vultr.slug
),
new DigitalOceanPhysicalClusterCreator(
d.taskRunner,
Expand All @@ -44,7 +47,7 @@ function initRunBooks(d: Dependencies, t: TaskGenerator): RunBook[] {
d.kubectl,
sulfoxide.services.tofu,
sulfoxide.services.argocd,
CLOUDS.DigitalOcean.slug,
CLOUDS.DigitalOcean.slug
),
new AwsPhysicalClusterCreator(
d.taskRunner,
Expand All @@ -56,16 +59,16 @@ function initRunBooks(d: Dependencies, t: TaskGenerator): RunBook[] {
sulfoxide.services.argocd,
sulfoxide.services.cluster_scaler,
sulfoxide.services.aws_adapter,
CLOUDS.AWS.slug,
),
CLOUDS.AWS.slug
)
];
const physicalClusterCreator = new PhysicalClusterCreator(
d.taskRunner,
d.stp,
t.nitrosoWaiter,
sulfoxide.services.argocd,
LANDSCAPE_TREE.v,
phyClusterCreators,
phyClusterCreators
);

// graceful physical cluster destruction
Expand All @@ -78,7 +81,7 @@ function initRunBooks(d: Dependencies, t: TaskGenerator): RunBook[] {
sulfoxide.services.tofu,
sulfoxide.services.argocd,
LANDSCAPE_TREE.v,
CLOUDS.Vultr.slug,
CLOUDS.Vultr.slug
),
new DigitalOceanGracefulPhysicalClusterDestructor(
d.taskRunner,
Expand All @@ -88,7 +91,7 @@ function initRunBooks(d: Dependencies, t: TaskGenerator): RunBook[] {
sulfoxide.services.tofu,
sulfoxide.services.argocd,
LANDSCAPE_TREE.v,
CLOUDS.DigitalOcean.slug,
CLOUDS.DigitalOcean.slug
),
new AwsGracefulPhysicalClusterDestructor(
d.taskRunner,
Expand All @@ -99,14 +102,14 @@ function initRunBooks(d: Dependencies, t: TaskGenerator): RunBook[] {
sulfoxide.services.argocd,
sulfoxide.services.external_ingress,
LANDSCAPE_TREE.v,
CLOUDS.AWS.slug,
),
CLOUDS.AWS.slug
)
];

const phyGracefulDestructor = new GracefulPhysicalClusterDestructor(
d.stp,
d.serviceTreePrinter,
phyGracefulDestructors,
phyGracefulDestructors
);

// bare admin cluster creation
Expand All @@ -119,8 +122,8 @@ function initRunBooks(d: Dependencies, t: TaskGenerator): RunBook[] {
sulfoxide.services.backup_engine,
sulfoxide.services.metricsServer,
t.sulfoxideXenonWaiter,
CLOUDS.DigitalOcean.slug,
),
CLOUDS.DigitalOcean.slug
)
];
const bareAdminClusterCreator = new BareAdminClusterCreator(d.stp, d.serviceTreePrinter, bareAdminCloudCreators);

Expand All @@ -132,15 +135,15 @@ function initRunBooks(d: Dependencies, t: TaskGenerator): RunBook[] {
sulfoxide.services.internal_ingress,
t.sulfoxideHeliumWaiter,
t.sulfoxideBoronWaiter,
CLOUDS.DigitalOcean.slug,
),
CLOUDS.DigitalOcean.slug
)
];

const fullAdminCloudCreator = new FullAdminClusterCreator(
d.stp,
d.serviceTreePrinter,
bareAdminCloudCreators,
fullAdminCloudCreators,
fullAdminCloudCreators
);

// graceful admin cluster destruction
Expand All @@ -149,13 +152,13 @@ function initRunBooks(d: Dependencies, t: TaskGenerator): RunBook[] {
d.kubectl,
sulfoxide.services.argocd,
sulfoxide.services.internal_ingress,
sulfoxide.services.tofu,
sulfoxide.services.tofu
);

const adminGracefulDestructor = new GracefulAdminClusterDestructor(
d.stp,
d.serviceTreePrinter,
genericAdminGracefulDestructor,
genericAdminGracefulDestructor
);

// admin cluster migration
Expand All @@ -166,14 +169,14 @@ function initRunBooks(d: Dependencies, t: TaskGenerator): RunBook[] {
sulfoxide.services.backup_engine,
sulfoxide.services.internal_ingress,
t.sulfoxideHeliumWaiter,
t.sulfoxideBoronWaiter,
t.sulfoxideBoronWaiter
);
const adminClusterMigrator = new AdminClusterMigrator(
d.stp,
d.serviceTreePrinter,
bareAdminCloudCreators,
genericAdminGracefulDestructor,
adminClusterTransitioner,
adminClusterTransitioner
);

// create secrets operator
Expand All @@ -182,7 +185,13 @@ function initRunBooks(d: Dependencies, t: TaskGenerator): RunBook[] {
d.stp,
d.utilPrompter,
d.yamlManipulator,
sulfoxide.services.infisical,
sulfoxide.services.infisical
);

const secretsOperatorDestructor = new SecretsOperatorDestructor(
d.taskRunner,
d.stp,
sulfoxide.services.infisical
);


Expand All @@ -194,6 +203,7 @@ function initRunBooks(d: Dependencies, t: TaskGenerator): RunBook[] {
adminGracefulDestructor,
adminClusterMigrator,
secretsOperatorCreator,
secretsOperatorDestructor
];
}

Expand Down

0 comments on commit 24bc860

Please sign in to comment.