Skip to content

Commit

Permalink
feat: add ContinuousDeployment construct
Browse files Browse the repository at this point in the history
BREAKING CHANGE: the imports are new at @bifravst/ci
  • Loading branch information
coderbyheart committed Apr 11, 2024
1 parent edb72da commit 24d19d6
Show file tree
Hide file tree
Showing 3 changed files with 52 additions and 3 deletions.
47 changes: 47 additions & 0 deletions cdk/ContinuousDeployment.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
import { Duration, aws_iam as IAM, Stack } from 'aws-cdk-lib'
import { Construct } from 'constructs'

export class ContinuousDeployment extends Construct {
public readonly role: IAM.IRole
constructor(
parent: Construct,
{
repository: { owner, repo },
gitHubOICDProviderArn,
}: {
repository: {
owner: string
repo: string
}
gitHubOICDProviderArn: string
},
) {
super(parent, 'cd')

const gitHubOIDC = IAM.OpenIdConnectProvider.fromOpenIdConnectProviderArn(
this,
'gitHubOICDProvider',
gitHubOICDProviderArn,
)

this.role = new IAM.Role(this, 'ghRole', {
roleName: `${Stack.of(this).stackName}-cd`,
assumedBy: new IAM.WebIdentityPrincipal(
gitHubOIDC.openIdConnectProviderArn,
{
StringEquals: {
[`token.actions.githubusercontent.com:sub`]: `repo:${owner}/${repo}:environment:production`,
[`token.actions.githubusercontent.com:aud`]: 'sts.amazonaws.com',
},
},
),
description: `This role is used by GitHub Actions to deploy ${
Stack.of(this).stackName
}`,
maxSessionDuration: Duration.hours(1),
managedPolicies: [
IAM.ManagedPolicy.fromAwsManagedPolicyName('AdministratorAccess'),
],
})
}
}
2 changes: 2 additions & 0 deletions cdk/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
export * from './ContinuousDeployment.js'
export * from './RepoPermission.js'
6 changes: 3 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@
"version": "0.0.0-development",
"description": "Sets up the permissions in our CI account for all repositories in this account to be able to use it for CI runs.",
"exports": {
"./*": {
".": {
"import": {
"types": "./dist/*.d.ts",
"default": "./dist/*.js"
"types": "./dist/cdk/index.d.ts",
"default": "./dist/cdk/index.js"
}
}
},
Expand Down

0 comments on commit 24d19d6

Please sign in to comment.