Skip to content

Commit

Permalink
Merge pull request #1 from ashleyjtaylor/feature/init
Browse files Browse the repository at this point in the history
chore: init
  • Loading branch information
ashleyjtaylor authored Mar 9, 2024
2 parents b50c35a + 7ef6c62 commit ed70a34
Show file tree
Hide file tree
Showing 20 changed files with 4,215 additions and 0 deletions.
5 changes: 5 additions & 0 deletions .commitlintrc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"extends": [
"@commitlint/config-conventional"
]
}
47 changes: 47 additions & 0 deletions .eslintrc.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
/** @type {import("eslint").Linter.Config} */
module.exports = {
$schema: 'https://json.schemastore.org/eslintrc',
root: true,
env: {
node: true,
browser: true,
es2021: true
},
extends: [
'eslint:recommended',
'plugin:@typescript-eslint/recommended'
],
parser: '@typescript-eslint/parser',
parserOptions: {
ecmaVersion: 'latest',
sourceType: 'module'
},
plugins: [
'@typescript-eslint'
],
settings: {
'import/resolver': {
typescript: {
project: './tsconfig.json'
}
}
},
ignorePatterns: ['dist', 'cdk.out'],
rules: {
'max-len': ['error', { 'code': 160 }],
'eol-last': 'error',
'comma-dangle': 'error',
semi: ['error', 'never'],
quotes: ['error', 'single'],
indent: ['error', 2, { 'SwitchCase': 1 }],
'no-trailing-spaces': 'error',
'@typescript-eslint/no-unused-vars': [
'error',
{
argsIgnorePattern: '^_',
varsIgnorePattern: '^_',
caughtErrorsIgnorePattern: '^_'
}
]
}
}
86 changes: 86 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
name: ci

env:
NODE_VERSION: 20

permissions: read-all

on:
push:
branches:
- main
paths-ignore:
- "**/*.md"
pull_request:
paths-ignore:
- "**/*.md"

concurrency: ${{ github.workflow }}-${{ github.ref }}

jobs:
audit:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-node@v4
with:
node-version: ${{ env.NODE_VERSION }}
- run: npm ci
- run: npm audit

lint:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0
- uses: actions/setup-node@v4
with:
node-version: ${{ env.NODE_VERSION }}
- run: npm ci
- run: npx turbo run lint --filter=...[HEAD^1]

test:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0
- uses: actions/setup-node@v4
with:
node-version: ${{ env.NODE_VERSION }}
- run: npm ci
- run: npx turbo run test --filter=...[HEAD^1]

build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0
- uses: actions/setup-node@v4
with:
node-version: ${{ env.NODE_VERSION }}
- run: npm ci
- run: npx turbo run build --filter=...[HEAD^1]

sonarcloud:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0
- name: SonarCloud Scan
uses: sonarsource/sonarcloud-github-action@master
env:
NODE_VERSION: ${{ env.NODE_VERSION }}
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }}

trigger-deploy:
if: github.ref == 'refs/heads/main'
runs-on: ubuntu-latest
needs: [audit, lint, test, build, sonarcloud]
steps:
- uses: actions/checkout@v4
- run: gh workflow run deploy.yml -f environment=dev
52 changes: 52 additions & 0 deletions .github/workflows/infrastructure.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
name: infrastructure

env:
NODE_VERSION: 20
OIDC_ROLE_ARN: arn:aws:iam::${{ secrets.AWS_ACCOUNT_ID }}:role/saas-github-oidc-provider-role

permissions:
id-token: write
contents: read

on:
push:
branches:
- main
paths:
- 'infrastructure/**'
- '!**/*.md'

jobs:
infrastructure:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0
- uses: actions/setup-node@v4
with:
node-version: ${{ env.NODE_VERSION }}

- name: Install
run: npm ci

- name: Build
working-directory: ./infrastructure
run: |
npm run lint
npm run build
- name: Assume OIDC Role
uses: aws-actions/configure-aws-credentials@v4
with:
role-session-name: gh-infrastructure-deploy-session
role-to-assume: ${{ env.OIDC_ROLE_ARN }}
aws-region: ${{ secrets.AWS_REGION }}

- name: Synth
working-directory: ./infrastructure
run: cdk synth --require-approval never

- name: Deploy
working-directory: ./infrastructure
run: cdk deploy --require-approval never
8 changes: 8 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
.DS_Store
.turbo
.vscode

node_modules
dist
cdk.out
.cdk.staging
4 changes: 4 additions & 0 deletions .husky/commit-msg
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
#!/usr/bin/env sh
. "$(dirname -- "$0")/_/husky.sh"

npx --no -- commitlint --edit ${1}
5 changes: 5 additions & 0 deletions .husky/pre-commit
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
#!/usr/bin/env sh
. "$(dirname -- "$0")/_/husky.sh"

npm run lint
npm run test
15 changes: 15 additions & 0 deletions infrastructure/bin/app.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
#!/usr/bin/env node
import 'source-map-support/register'
import * as cdk from 'aws-cdk-lib'
import ToolsStack from '../src/ToolsStack'

const app = new cdk.App()

new ToolsStack(app, 'ToolsStack', {
env: {
region: process.env.AWS_REGION,
account: process.env.AWS_ACCOUNT_ID
}
})

app.synth()
66 changes: 66 additions & 0 deletions infrastructure/cdk.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
{
"app": "npx ts-node --prefer-ts-exts bin/app.ts",
"watch": {
"include": [
"**"
],
"exclude": [
"README.md",
"cdk*.json",
"**/*.d.ts",
"**/*.js",
"tsconfig.json",
"package*.json",
"yarn.lock",
"node_modules",
"test"
]
},
"context": {
"@aws-cdk/aws-lambda:recognizeLayerVersion": true,
"@aws-cdk/core:checkSecretUsage": true,
"@aws-cdk/core:target-partitions": [
"aws",
"aws-cn"
],
"@aws-cdk-containers/ecs-service-extensions:enableDefaultLogDriver": true,
"@aws-cdk/aws-ec2:uniqueImdsv2TemplateName": true,
"@aws-cdk/aws-ecs:arnFormatIncludesClusterName": true,
"@aws-cdk/aws-iam:minimizePolicies": true,
"@aws-cdk/core:validateSnapshotRemovalPolicy": true,
"@aws-cdk/aws-codepipeline:crossAccountKeyAliasStackSafeResourceName": true,
"@aws-cdk/aws-s3:createDefaultLoggingPolicy": true,
"@aws-cdk/aws-sns-subscriptions:restrictSqsDescryption": true,
"@aws-cdk/aws-apigateway:disableCloudWatchRole": true,
"@aws-cdk/core:enablePartitionLiterals": true,
"@aws-cdk/aws-events:eventsTargetQueueSameAccount": true,
"@aws-cdk/aws-iam:standardizedServicePrincipals": true,
"@aws-cdk/aws-ecs:disableExplicitDeploymentControllerForCircuitBreaker": true,
"@aws-cdk/aws-iam:importedRoleStackSafeDefaultPolicyName": true,
"@aws-cdk/aws-s3:serverAccessLogsUseBucketPolicy": true,
"@aws-cdk/aws-route53-patters:useCertificate": true,
"@aws-cdk/customresources:installLatestAwsSdkDefault": false,
"@aws-cdk/aws-rds:databaseProxyUniqueResourceName": true,
"@aws-cdk/aws-codedeploy:removeAlarmsFromDeploymentGroup": true,
"@aws-cdk/aws-apigateway:authorizerChangeDeploymentLogicalId": true,
"@aws-cdk/aws-ec2:launchTemplateDefaultUserData": true,
"@aws-cdk/aws-secretsmanager:useAttachedSecretResourcePolicyForSecretTargetAttachments": true,
"@aws-cdk/aws-redshift:columnId": true,
"@aws-cdk/aws-stepfunctions-tasks:enableEmrServicePolicyV2": true,
"@aws-cdk/aws-ec2:restrictDefaultSecurityGroup": true,
"@aws-cdk/aws-apigateway:requestValidatorUniqueId": true,
"@aws-cdk/aws-kms:aliasNameRef": true,
"@aws-cdk/aws-autoscaling:generateLaunchTemplateInsteadOfLaunchConfig": true,
"@aws-cdk/core:includePrefixInUniqueNameGeneration": true,
"@aws-cdk/aws-efs:denyAnonymousAccess": true,
"@aws-cdk/aws-opensearchservice:enableOpensearchMultiAzWithStandby": true,
"@aws-cdk/aws-lambda-nodejs:useLatestRuntimeVersion": true,
"@aws-cdk/aws-efs:mountTargetOrderInsensitiveLogicalId": true,
"@aws-cdk/aws-rds:auroraClusterChangeScopeOfInstanceParameterGroupWithEachParameters": true,
"@aws-cdk/aws-appsync:useArnForSourceApiAssociationIdentifier": true,
"@aws-cdk/aws-rds:preventRenderingDeprecatedCredentials": true,
"@aws-cdk/aws-codepipeline-actions:useNewDefaultBranchForCodeCommitSource": true,
"@aws-cdk/aws-cloudwatch-actions:changeLambdaPermissionLogicalIdForLambdaAction": true,
"@aws-cdk/aws-codepipeline:crossAccountKeysDefaultValueToFalse": true
}
}
19 changes: 19 additions & 0 deletions infrastructure/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
{
"name": "infrastructure",
"version": "0.1.0",
"bin": {
"infrastructure": "bin/infrastructure.js"
},
"scripts": {
"lint": "eslint .",
"build": "tsc -p .",
"cdk-init": "cdk deploy ToolsStack",
"cdk-synth": "cdk synth",
"cdk-deploy": "cdk deploy"
},
"dependencies": {
"aws-cdk-lib": "2.132.0",
"constructs": "^10.0.0",
"source-map-support": "^0.5.21"
}
}
17 changes: 17 additions & 0 deletions infrastructure/src/ToolsStack.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import { Construct } from 'constructs'
import { Stack, StackProps } from 'aws-cdk-lib'

import OIDCProvider from './constructs/oidc-provider'

export default class ToolsStack extends Stack {
constructor(scope: Construct, id: string, props: StackProps) {
super(scope, id, props)

new OIDCProvider(this, 'OIDCProvider', {
project: 'saas',
issuer: 'token.actions.githubusercontent.com',
roleName: 'saas-github-oidc-provider-role',
githubRepo: 'ashleyjtaylor/saas'
})
}
}
Loading

0 comments on commit ed70a34

Please sign in to comment.