Skip to content

Commit

Permalink
feat: initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
DASPRiD committed Jan 15, 2024
0 parents commit 9897692
Show file tree
Hide file tree
Showing 13 changed files with 2,975 additions and 0 deletions.
53 changes: 53 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
name: Release

on:
push:
branches:
- main

jobs:
release:
name: Release
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v3

- name: Use Node.js 20.x
uses: actions/setup-node@v3
with:
node-version: 20

- name: Cache node modules
uses: actions/cache@v3
env:
cache-name: cache-node-modules
with:
path: ~/.npm
key: ${{ runner.os }}-build-${{ env.cache-name }}-${{ hashFiles('**/package-lock.json') }}
restore-keys: |
${{ runner.os }}-build-${{ env.cache-name }}-
${{ runner.os }}-build-
${{ runner.os }}-
- name: Install Dependencies
run: npm ci

- name: Biome CI
run: npm run biome-ci

- name: Build
run: npm run build

- name: Semantic Release
uses: cycjimmy/semantic-release-action@v3
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
NPM_TOKEN: ${{ secrets.NPM_TOKEN }}
HUSKY: 0
id: semantic
with:
semantic_version: 19.0.5
extra_plugins: |
@semantic-release/[email protected]
@semantic-release/[email protected]
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
/index.js
/cdk.out
/node_modules
1 change: 1 addition & 0 deletions .lefthook/commit-msg/commitlint.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
echo $(head -n1 $1) | npx commitlint --color
21 changes: 21 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
MIT License

Copyright (c) 2023 Soliant Consulting

Permission is hereby granted, free of charge, to any person obtaining a
copy of this software and associated documentation files (the "Software"),
to deal in the Software without restriction, including without limitation
the rights to use, copy, modify, merge, publish, distribute, sublicense,
and/or sell copies of the Software, and to permit persons to whom the
Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
DEALINGS IN THE SOFTWARE.
26 changes: 26 additions & 0 deletions biome.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
{
"$schema": "https://biomejs.dev/schemas/1.5.2/schema.json",
"organizeImports": {
"enabled": true
},
"files": {
"include": [
"biome.json",
"cdk.json",
"release.config.cjs",
"commitlint.config.cjs",
"index.ts"
]
},
"linter": {
"enabled": true,
"rules": {
"recommended": true
}
},
"formatter": {
"indentStyle": "space",
"indentWidth": 4,
"lineWidth": 100
}
}
3 changes: 3 additions & 0 deletions cdk.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"app": "node index.js"
}
1 change: 1 addition & 0 deletions commitlint.config.cjs
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
module.exports = { extends: ["@commitlint/config-conventional"] };
67 changes: 67 additions & 0 deletions index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
import * as cdk from "aws-cdk-lib";
import * as iam from "aws-cdk-lib/aws-iam";
import { Construct } from "constructs";

type BitbucketStackProps = cdk.StackProps & {
readonly repositoryUuid: string;
readonly bitbucketAudience: string;
readonly bitbucketDomain: string;
};

export class BitbucketStack extends cdk.Stack {
constructor(scope: Construct, id: string, props: BitbucketStackProps) {
super(scope, id, props);

const bitbucketProvider = new iam.OpenIdConnectProvider(this, "BitbucketProvider", {
url: `https://${props.bitbucketDomain}`,
clientIds: [props.bitbucketAudience],
});

const conditions: iam.Conditions = {
StringEquals: {
[`${props.bitbucketDomain}:aud`]: props.bitbucketAudience,
},
StringLike: {
[`${props.bitbucketDomain}:sub`]: `${props.repositoryUuid}:*`,
},
};

const role = new iam.Role(this, "BitbucketDeployRole", {
assumedBy: new iam.WebIdentityPrincipal(
bitbucketProvider.openIdConnectProviderArn,
conditions,
),
managedPolicies: [iam.ManagedPolicy.fromAwsManagedPolicyName("AdministratorAccess")],
description:
"This role is used via Bitbucket pipelines to deploy with AWS CDK or Terraform on the customers AWS account",
maxSessionDuration: cdk.Duration.hours(2),
});

new cdk.CfnOutput(this, "RoleArn", {
value: role.roleArn,
});
}
}

const app = new cdk.App();
const stackSuffix = app.node.tryGetContext("stackSuffix");
const repositoryUuid = app.node.tryGetContext("repositoryUuid");

if (typeof stackSuffix !== "string") {
console.error("Missing stackSuffix context variable");
process.exit(1);
}

if (typeof repositoryUuid !== "string") {
console.error("Missing repositoryUuid context variable");
process.exit(1);
}

new BitbucketStack(app, `BitbucketOpenIDConnect-${stackSuffix}`, {
repositoryUuid,
bitbucketDomain:
"api.bitbucket.org/2.0/workspaces/soliantconsulting/pipelines-config/identity/oidc",
bitbucketAudience: "ari:cloud:bitbucket::workspace/edf547a3-8e06-4217-abd8-7b9139a21e2c",
});

app.synth();
10 changes: 10 additions & 0 deletions lefthook.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
pre-commit:
commands:
check:
glob: "*.{js,ts,cjs,mjs,d.cts,d.mts,jsx,tsx,json,jsonc}"
run: npx biome check --apply --no-errors-on-unmatched --files-ignore-unknown=true {staged_files} && git update-index --again

commit-msg:
scripts:
"commitlint.sh":
runner: bash
Loading

0 comments on commit 9897692

Please sign in to comment.