Skip to content

Commit

Permalink
extract buildspec as json
Browse files Browse the repository at this point in the history
  • Loading branch information
harishv7 committed Jul 31, 2024
1 parent 441b401 commit cc1b8d1
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 4 deletions.
8 changes: 8 additions & 0 deletions apps/studio/src/server/modules/aws/buildspec.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"version": "0.2",
"phases": {
"build": {
"commands": ["echo \"hello\""]
}
}
}
8 changes: 6 additions & 2 deletions apps/studio/src/server/modules/aws/codebuild.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@ import {
StartBuildCommand,
} from "@aws-sdk/client-codebuild"
import { ServiceException } from "@aws-sdk/smithy-client"
import * as yaml from "yaml"

import buildspec from "./buildspec.json"

const client = new CodeBuildClient({ region: "ap-southeast-1" })

Expand Down Expand Up @@ -61,6 +64,8 @@ export const createCodeBuildProject = async ({
projectId: string
siteId: number
}): Promise<any> => {
const stringifiedBuildspec = yaml.stringify(buildspec)

/* TODO: Things to add
1. VPC config
2. Default service role
Expand All @@ -71,8 +76,7 @@ export const createCodeBuildProject = async ({
name: projectId,
source: {
type: "NO_SOURCE",
buildspec:
'version: 0.2\n\nphases:\n build:\n commands:\n - echo "hello"\n',
buildspec: stringifiedBuildspec,
},
artifacts: {
type: "NO_ARTIFACTS",
Expand Down
9 changes: 7 additions & 2 deletions apps/studio/src/server/modules/page/page.router.ts
Original file line number Diff line number Diff line change
Expand Up @@ -267,10 +267,16 @@ export const pageRouter = router({
siteId,
})
} catch (e) {
ctx.logger.error("CodeBuild project creation failure", {
const msg = "CodeBuild project creation failure"
ctx.logger.error(msg, {
userId: ctx.user.id,
siteId,
})
throw new TRPCError({
message: msg,
code: "INTERNAL_SERVER_ERROR",
cause: e,
})
}

// update site to the newly created codebuild project id
Expand All @@ -280,7 +286,6 @@ export const pageRouter = router({

// initiate new build
await startProjectById(codeBuildId)

return addedVersionResult
}),
})

0 comments on commit cc1b8d1

Please sign in to comment.