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

feat(cli): add website deploy #1190

Merged
merged 1 commit into from
May 29, 2023
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
8 changes: 4 additions & 4 deletions cli/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion cli/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
},
"devDependencies": {
"@types/mime": "^2.0.3",
"@types/node": "^17.0.31"
"@types/node": "^17.0.45"
},
"dependencies": {
"@aws-sdk/client-s3": "^3.45.0",
Expand Down
21 changes: 20 additions & 1 deletion cli/src/action/deploy/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,11 @@ import { AppSchema } from '../../schema/app'
import { DeploySchema } from '../../schema/deploy'
import { pushAll as pushAllFunctions } from '../function'
import { create as createBucket, push as pushBucket } from '../storage'
import { create as createWebsite } from '../website'
import { push as pushDependency } from '../dependency'
import { pullAll as pullAllPolicies } from '../policy'
import { getEmoji } from '../../util/print'
import { websiteControllerFindAll } from '../../api/v1/websitehosting'

export async function deploy() {
if (!DeploySchema.exist()) {
Expand Down Expand Up @@ -37,7 +39,23 @@ export async function deploy() {
if (!bucketMap.has(bucket.name)) {
await createBucket(bucket.name, { policy: bucket.policy })
} else {
console.log(`${bucket.name} already exist, skip`)
console.log(`bucket ${bucket.name} already exist, skip`)
}
}
}

if (deploySchema?.resources?.websites) {
const websites = await websiteControllerFindAll(appSchema.appid)
const websiteMap = new Map<string, boolean>()
websites.forEach((website) => {
websiteMap.set(website.bucketName, true)
})

for (let website of deploySchema?.resources?.websites) {
if (!websiteMap.has(website.bucketName) && !websiteMap.has(appSchema.appid + '-' + website.bucketName)) {
await createWebsite(website.bucketName, {})
} else {
console.log(`website:${website.bucketName} already exist, skip`)
}
}
}
Expand All @@ -48,5 +66,6 @@ export async function deploy() {
await pushBucket(bucket.bucketName, bucket.srcDir, { force: true, detail: false })
}
}

console.log(`${getEmoji('🚀')} deploy success`)
}
8 changes: 7 additions & 1 deletion cli/src/schema/deploy.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
import { DEPLOY_SCHEMA_NAME } from '../common/constant'
import { exist, loadYamlFile } from '../util/file'
import { getAppPath } from '../util/sys'
import path = require('path')
import * as path from 'node:path'

export class DeploySchema {
name: string

resources?: {
buckets?: BucketResource[]
websites?: WebsiteResource[]
}

actions?: {
Expand All @@ -30,6 +31,11 @@ export class BucketResource {
policy: 'private' | 'readonly' | 'readwrite'
}

export class WebsiteResource {
name: string
bucketName: string
}

export class BucketAction {
name: string
bucketName: string
Expand Down