mirror of
https://github.com/whekin/household-bot.git
synced 2026-03-31 12:24:02 +00:00
feat(infra): add aws lambda pulumi deployment target
This commit is contained in:
42
scripts/ops/publish-miniapp-aws.ts
Normal file
42
scripts/ops/publish-miniapp-aws.ts
Normal file
@@ -0,0 +1,42 @@
|
||||
import { mkdtemp, rm } from 'node:fs/promises'
|
||||
import { tmpdir } from 'node:os'
|
||||
import { join } from 'node:path'
|
||||
|
||||
const bucket = process.env.AWS_MINIAPP_BUCKET
|
||||
const botApiUrl = process.env.BOT_API_URL
|
||||
const awsRegion = process.env.AWS_REGION
|
||||
const dryRun = process.env.AWS_PUBLISH_DRY_RUN === 'true'
|
||||
|
||||
if (!bucket) {
|
||||
throw new Error('AWS_MINIAPP_BUCKET environment variable is required')
|
||||
}
|
||||
|
||||
if (!botApiUrl) {
|
||||
throw new Error('BOT_API_URL environment variable is required')
|
||||
}
|
||||
|
||||
await Bun.$`bun run --filter @household/miniapp build`
|
||||
|
||||
const distDir = join(process.cwd(), 'apps/miniapp/dist')
|
||||
const templatePath = join(process.cwd(), 'apps/miniapp/config.template.js')
|
||||
const stagingDir = await mkdtemp(join(tmpdir(), 'household-miniapp-'))
|
||||
|
||||
try {
|
||||
await Bun.$`cp -R ${distDir}/. ${stagingDir}`
|
||||
|
||||
const template = await Bun.file(templatePath).text()
|
||||
const configScript = template.replace('${BOT_API_URL}', botApiUrl)
|
||||
await Bun.write(join(stagingDir, 'config.js'), configScript)
|
||||
|
||||
const regionArgs = awsRegion ? ['--region', awsRegion] : []
|
||||
const syncArgs = dryRun ? ['--dryrun'] : []
|
||||
|
||||
await Bun.$`aws s3 sync ${stagingDir} s3://${bucket} --delete --exclude index.html --exclude config.js --cache-control public,max-age=31536000,immutable ${regionArgs} ${syncArgs}`
|
||||
await Bun.$`aws s3 cp ${join(stagingDir, 'index.html')} s3://${bucket}/index.html --cache-control no-cache ${regionArgs} ${syncArgs}`
|
||||
await Bun.$`aws s3 cp ${join(stagingDir, 'config.js')} s3://${bucket}/config.js --cache-control no-cache ${regionArgs} ${syncArgs}`
|
||||
} finally {
|
||||
await rm(stagingDir, {
|
||||
recursive: true,
|
||||
force: true
|
||||
})
|
||||
}
|
||||
Reference in New Issue
Block a user