Skip to content

Commit

Permalink
chore: add cdk deploy to workflow
Browse files Browse the repository at this point in the history
  • Loading branch information
marcellmueller committed Dec 6, 2024
1 parent 032a46a commit 2629f1d
Show file tree
Hide file tree
Showing 6 changed files with 34 additions and 1,249 deletions.
22 changes: 10 additions & 12 deletions .github/workflows/deploy-aws.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,25 +28,23 @@ jobs:
role-to-assume: ${{ secrets.AWS_DEPLOY_ROLE_ARN }}
aws-region: ${{ secrets.AWS_REGION }}

- name: Provision infrastructure with AWS CloudFormation
uses: aws-actions/aws-cloudformation-github-deploy@v1
with:
name: ${{ env.STACK_NAME }}
no-fail-on-empty-changeset: "1"
template: ./infrastructure/deploy.yml

# Build frontend and deploy to s3 - maybe split this out into a separate workflow and call from here
- name: Setup Node
uses: actions/setup-node@v3

- name: Install dependencies
# Build frontend
- name: Install frontend dependencies
uses: bahmutov/npm-install@v1
with:
working-directory: ./frontend

- name: Build project
working-directory: ./frontend
run: npm run build

- name: Deploy static site to S3 bucket
run: aws s3 sync ./frontend/dist s3://$FRONTEND_BUCKET --delete
- name: Install CDK dependencies
uses: bahmutov/npm-install@v1
with:
working-directory: ./infrastructure

- name: Provision infrastructure and deploy frontend to s3 with AWS CDK
working-directory: ./infrastructure
run: npm run cdk deploy
9 changes: 8 additions & 1 deletion frontend/src/components/Dashboard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -26,5 +26,12 @@ export default function Dashboard() {
});
}, []);

return <div>{JSON.stringify(data)}</div>;
return (
<>
<h2>CDK Deployment working</h2>
<p>Random build number: {Math.floor(Math.random() * 90000) + 10000}</p>

<div>{JSON.stringify(data)}</div>
</>
);
}
8 changes: 4 additions & 4 deletions infrastructure/lib/infrastructure-stack.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
import * as cdk from "aws-cdk-lib/core";
import { Stack, StackProps, RemovalPolicy } from "aws-cdk-lib";
import { Construct } from "constructs";
import * as s3 from "aws-cdk-lib/aws-s3";
import * as s3deploy from "aws-cdk-lib/aws-s3-deployment";
import * as path from "path";
import * as cloudfront from "aws-cdk-lib/aws-cloudfront";
import * as origins from "aws-cdk-lib/aws-cloudfront-origins";

export class InfrastructureStack extends cdk.Stack {
constructor(scope: Construct, id: string, props?: cdk.StackProps) {
export class InfrastructureStack extends Stack {
constructor(scope: Construct, id: string, props?: StackProps) {
super(scope, id, props);

const s3CorsRule: s3.CorsRule = {
Expand All @@ -21,7 +21,7 @@ export class InfrastructureStack extends cdk.Stack {
blockPublicAccess: s3.BlockPublicAccess.BLOCK_ALL,
accessControl: s3.BucketAccessControl.PRIVATE,
cors: [s3CorsRule],
removalPolicy: cdk.RemovalPolicy.DESTROY,
removalPolicy: RemovalPolicy.DESTROY,
objectLockEnabled: false,
});

Expand Down
Loading

0 comments on commit 2629f1d

Please sign in to comment.