Skip to content

Commit 443e348

Browse files
feat!: support multiple environments in HakoDelete
This reverts commit 5f3c6ce.
1 parent c7fa1f4 commit 443e348

File tree

3 files changed

+243
-34
lines changed

3 files changed

+243
-34
lines changed

package-lock.json

Lines changed: 204 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

plugins/hako/readme.md

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -38,12 +38,12 @@ _(\*) Required._
3838
Remove unneeded ephemeral app
3939
#### Task options
4040

41-
| Property | Description | Type | Default |
42-
| :--------------------- | :---------------------------------------------------------------------------------------------------------------- | :-------- | :------ |
43-
| **`appName`** (\*) | name of the app with the ephemeral app to delete (will be the same as the name of the docker image) | `string` | |
44-
| `asReviewApp` | whether to delete a temporary review app. overrides the `ephemeralId` option with its own hash of the git branch. | `boolean` | `false` |
45-
| `ephemeralId` | ID that is used by Hako to identify a particular ephemeral app | `string` | |
46-
| **`environment`** (\*) | the Hako environment the ephemeral app is in | `string` | |
41+
| Property | Description | Type | Default |
42+
| :---------------------- | :---------------------------------------------------------------------------------------------------------------- | :-------------- | :------ |
43+
| **`appName`** (\*) | name of the app with the ephemeral app to delete (will be the same as the name of the docker image) | `string` | |
44+
| `asReviewApp` | whether to delete a temporary review app. overrides the `ephemeralId` option with its own hash of the git branch. | `boolean` | `false` |
45+
| `ephemeralId` | ID that is used by Hako to identify a particular ephemeral app | `string` | |
46+
| **`environments`** (\*) | | `Array<string>` | |
4747

4848
_(\*) Required._
4949
<!-- end autogenerated docs -->

plugins/hako/src/tasks/delete.ts

Lines changed: 33 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ const HakoDeleteSchema = z
2626
.string()
2727
.optional()
2828
.describe('ID that is used by Hako to identify a particular ephemeral app'),
29-
environment: HakoEnvironmentName.describe('the Hako environment the ephemeral app is in')
29+
environments: z.array(HakoEnvironmentName.describe('the Hako environments to delete apps in'))
3030
})
3131
.describe('Remove unneeded ephemeral app')
3232

@@ -36,39 +36,45 @@ export default class HakoDelete extends Task<{ task: typeof HakoDeleteSchema }>
3636
async run() {
3737
const awsCredentials = readState('ci')?.awsCredentials ?? {}
3838

39-
const awsRegion = hakoRegions[this.options.environment.region]
40-
4139
const { subdomain } = getAppDetails({
4240
name: this.options.appName,
4341
ephemeralId: this.options.ephemeralId,
4442
asReviewApp: this.options.asReviewApp
4543
})
4644

47-
this.logger.info(`Deleting ${styles.code(subdomain)} from Hako`)
45+
for (const environment of this.options.environments) {
46+
const awsRegion = hakoRegions[environment.region]
47+
48+
this.logger.info(
49+
`Deleting ${styles.code(subdomain)} from Hako environment ${environment.name} in ${
50+
environment.region
51+
}`
52+
)
4853

49-
const child = spawn('docker', [
50-
'run',
51-
'--interactive',
52-
'--env',
53-
`AWS_REGION=${awsRegion}`,
54-
'--env',
55-
`AWS_ACCESS_KEY_ID=${awsCredentials.accessKeyId}`,
56-
'--env',
57-
`AWS_SECRET_ACCESS_KEY=${awsCredentials.secretAccessKey}`,
58-
'--env',
59-
`AWS_SESSION_TOKEN=${awsCredentials.sessionToken}`,
60-
'--platform',
61-
'linux/amd64',
62-
hakoImageName,
63-
'app',
64-
'delete',
65-
'--app',
66-
subdomain,
67-
'--env',
68-
this.options.environment.name
69-
])
54+
const child = spawn('docker', [
55+
'run',
56+
'--interactive',
57+
'--env',
58+
`AWS_REGION=${awsRegion}`,
59+
'--env',
60+
`AWS_ACCESS_KEY_ID=${awsCredentials.accessKeyId}`,
61+
'--env',
62+
`AWS_SECRET_ACCESS_KEY=${awsCredentials.secretAccessKey}`,
63+
'--env',
64+
`AWS_SESSION_TOKEN=${awsCredentials.sessionToken}`,
65+
'--platform',
66+
'linux/amd64',
67+
hakoImageName,
68+
'app',
69+
'delete',
70+
'--app',
71+
subdomain,
72+
'--env',
73+
environment.name
74+
])
7075

71-
hookFork(this.logger, 'hako-app-delete', child)
72-
await waitOnExit('hako-app-delete', child)
76+
hookFork(this.logger, 'hako-app-delete', child)
77+
await waitOnExit('hako-app-delete', child)
78+
}
7379
}
7480
}

0 commit comments

Comments
 (0)