Created
December 10, 2022 19:40
-
-
Save cfuerst/a33d48a299f2a3fa8293ad3983b051a1 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
const { JsonPatch } = require("projen"); | |
const awsConfigureStep = { | |
uses: "aws-actions/configure-aws-credentials@v1-node16", | |
with: { | |
"aws-access-key-id": "${{ secrets.AWS_ACCESS_KEY_ID }}", | |
"aws-secret-access-key": "${{ secrets.AWS_SECRET_ACCESS_KEY }}", | |
"aws-region": "${{ secrets.CDK_DEPLOY_REGION }}", | |
}, | |
}; | |
const preDestroyJobs = { | |
runsOn: "ubuntu-latest", | |
permissions: { contents: "write" }, | |
if: "github.event.ref_type == 'branch'", | |
env: { GIT_DEL_BRANCH: "${{ github.event.ref }}" }, | |
steps: [ | |
{ | |
uses: "actions/checkout@v3", | |
with: { | |
ref: "${{ github.event.pull_request.head.ref }}", | |
repository: "${{ github.event.pull_request.head.repo.full_name }}", | |
}, | |
}, | |
{ | |
uses: "actions/setup-node@v3", | |
with: { | |
"node-version": "16.18.1", | |
}, | |
}, | |
{ | |
run: "yarn install --check-files", | |
}, | |
{ | |
uses: "aws-actions/configure-aws-credentials@v1-node16", | |
with: { | |
"aws-access-key-id": "${{ secrets.AWS_ACCESS_KEY_ID }}", | |
"aws-secret-access-key": "${{ secrets.AWS_SECRET_ACCESS_KEY }}", | |
"aws-region": "${{ secrets.CDK_DEPLOY_REGION }}", | |
}, | |
}, | |
{ | |
run: "npx projen default", | |
}, | |
awsConfigureStep, | |
{ id: "cdk-destroy", run: "npx cdk destroy --require-approval never --force >> $GITHUB_STEP_SUMMARY" }, | |
], | |
}; | |
const cdkDeployCmd = { id: "cdk-deploy", run: "npx cdk deploy --require-approval never --force >> $GITHUB_STEP_SUMMARY" }; | |
const patches = { | |
build: [ | |
JsonPatch.add("/jobs/build/steps/3", awsConfigureStep), | |
JsonPatch.add("/jobs/build/steps/-", cdkDeployCmd) | |
], | |
release: [ | |
JsonPatch.add("/jobs/release/steps/3", awsConfigureStep), | |
JsonPatch.add("/jobs/release/steps/-", cdkDeployCmd) | |
] | |
}; | |
module.exports = { preDestroyJobs, patches }; |
This file contains hidden or 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
const { awscdk } = require("projen"); | |
const { preDestroyJobs, patches } = require("./.projen-helper.js"); | |
const project = new awscdk.AwsCdkTypeScriptApp({ | |
author: "cfuerst", | |
authorAddress: "[email protected]", | |
authorName: "Christian Fürst", | |
authorOrganization: true, | |
copyrightOwner: "Christian Fürst", | |
cdkVersion: "2.5.0", | |
defaultReleaseBranch: "main", | |
name: "@cloudy-with-a-chance-of-meatballs/cdk-app-example-rest-api-rad-typescript", | |
repositoryUrl: "https://github.com/cloudy-with-a-chance-of-meatballs/cdk-app-example-rest-api-rad-typescript", | |
license: "MIT", | |
minNodeVersion: "16.18.1", | |
gitignore: [".idea/"], | |
deps: [ | |
"aws-cdk-lib", | |
"constructs", | |
"@cloudy-with-a-chance-of-meatballs/cdk-lambda-token-authorizer-jwt@^v0.0.41", | |
"@pepperize/cdk-apigateway-swagger-ui@^0.0.160", | |
], | |
description: "cdk sample application for a blueprint of a RAD (rapid application development) production ready rest api.", | |
eslint: true, | |
prettier: true, | |
prettierOptions: { | |
settings: { printWidth: 160 }, | |
}, | |
release: true, | |
releaseEveryCommit: true, | |
githubOptions: { | |
pullRequestLint: false, | |
}, | |
}); | |
//add a workflow for cdk destroy | |
const destroyWorkflow = project.github.addWorkflow("destroy"); | |
destroyWorkflow.on({ delete: {}, workflowDispatch: {} }); | |
destroyWorkflow.addJob("cdk-destroy", preDestroyJobs); | |
//add aws cli secret setup and deploy steps | |
["build", "release"].forEach((v) => { | |
project.github.tryFindWorkflow(v).file.patch(patches[v][0]); | |
project.github.tryFindWorkflow(v).file.patch(patches[v][1]); | |
}); | |
// synthesize the project files | |
project.synth(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Hi @cfuerst ,
To add the deploy job, I would be doing something like below: