-
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.
Merge pull request #6 from AtomiCloud/ernest/sul-20-create-full-deplo…
…yment-script feat: secerets operator creation playbook
- Loading branch information
Showing
3 changed files
with
424 additions
and
281 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,122 @@ | ||
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 type { UtilPrompter } from '../../lib/prompts/util-prompter.ts'; | ||
import { input, password } from '@inquirer/prompts'; | ||
import type { YamlManipulator } from '../../lib/utility/yaml-manipulator.ts'; | ||
import path from 'node:path'; | ||
import type { RunBook } from '../run-book.ts'; | ||
|
||
class SecretsOperatorCreator implements RunBook { | ||
constructor( | ||
private task: TaskRunner, | ||
private stp: ServiceTreePrompter, | ||
private up: UtilPrompter, | ||
private y: YamlManipulator, | ||
private sulfoxide_infisical: ServiceTreeService, | ||
) {} | ||
|
||
name: string = 'Create Secrets Operator'; | ||
desc: string = 'Deploy 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); | ||
}, | ||
]); | ||
|
||
// prompt to check if we want new secrets | ||
const newSecrets = await this.up.YesNo(`Do you want to inject new secrets for ${cluster.principal.name}?`); | ||
if (newSecrets) { | ||
await this.task.Run([ | ||
'Inject new secrets', | ||
async () => { | ||
const token = await input({ message: `Enter your ${cluster.cloud.name} token` }); | ||
|
||
const yamlPath = path.join(i_path, 'bw.secrets.yaml'); | ||
await this.y.Mutate(yamlPath, [[['Tokens', cluster.cloud.name, cluster.principal.name], token]]); | ||
|
||
console.log('✅ Secrets modified. Remember to update Bitwarden the new secrets'); | ||
|
||
let updated = false; | ||
|
||
while (!updated) { | ||
updated = await this.up.YesNo('Have you updated Bitwarden with the new secrets?'); | ||
} | ||
}, | ||
]); | ||
} | ||
|
||
// synchronize secrets | ||
await this.task.Run([ | ||
'Synchronize secrets', | ||
async () => { | ||
await $`nix develop -c pls sync`.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([ | ||
'Apply general (database and ingress) Tofu', | ||
async () => { | ||
await $`pls general:apply -- -auto-approve`.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([ | ||
'Provision compute', | ||
async () => { | ||
await $`pls ${{ raw: compute }}:init`.cwd(i_path); | ||
}, | ||
]); | ||
|
||
await this.task.Run([ | ||
'Apply compute', | ||
async () => { | ||
await $`pls ${{ raw: compute }}:apply -- -auto-approve`.cwd(i_path); | ||
}, | ||
]); | ||
|
||
// deploy secrets operator | ||
const c = cluster.principal.slug; | ||
await this.task.Run([ | ||
'Deploy secrets operator', | ||
async () => { | ||
await $`nix develop -c pls deploy -- ${{ raw: c }}`.cwd(i_path).env({ | ||
ANSIBLE_HOST_KEY_CHECKING: 'False', | ||
}); | ||
}, | ||
]); | ||
} | ||
} | ||
|
||
export { SecretsOperatorCreator }; |
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
Oops, something went wrong.