Skip to content

Commit

Permalink
Merge pull request #1 from cullancarey/develop
Browse files Browse the repository at this point in the history
Develop
  • Loading branch information
cullancarey authored Oct 22, 2023
2 parents 22cf488 + 60b598a commit fce0754
Show file tree
Hide file tree
Showing 16 changed files with 746 additions and 322 deletions.
151 changes: 151 additions & 0 deletions .github/workflows/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,151 @@
# Deploy CDK Stack to Production

This GitHub Actions workflow automates the deployment of an AWS CDK stack to a development and production environment. It is triggered when changes are pushed to the `develop` or `main` branch. The workflow sets up AWS credentials, installs dependencies, and deploys the CDK stack.

## Workflow Details

### Workflow Name: Deploy-CDK-Stack/Dev

- **Run Name**: Running ${{github.workflow}} off of ${{ github.ref_name }}

### Trigger

This workflow is triggered on pushes to the `develop` branch.

```yaml
on:
push:
branches:
- develop
```
### Permissions
This workflow requires specific permissions:
- `id-token: write`: This is required for requesting the JWT.
- `contents: read`: This is required for actions/checkout.

### Jobs

#### Deploy

- **Name**: Deploy Development
- **Uses**: `./.github/workflows/deploy.yaml`
- **Environment**: development

### Workflow Name: Deploy-CDK-Stack/Prod

- **Run Name**: Running ${{github.workflow}} off of ${{ github.ref_name }}

### Trigger

This workflow is triggered on pushes to the `main` branch.

```yaml
on:
push:
branches:
- main
```

### Permissions

This workflow requires specific permissions:

- `id-token: write`: This is required for requesting the JWT.
- `contents: read`: This is required for actions/checkout.

### Jobs

#### Deploy

- **Name**: Deploy Production
- **Uses**: `./.github/workflows/deploy.yaml`
- **Environment**: production

## CDK Deployment Workflow

### Workflow Name: Deploy

This workflow is designed to be called by other workflows and is used for deploying to different environments. It sets up AWS credentials, installs dependencies, and deploys the CDK stack based on the specified environment.

### Trigger

This workflow is meant to be called by other workflows using the `workflow_call` event. It takes an `environment` input parameter.

```yaml
on:
workflow_call:
inputs:
environment:
required: true
type: string
description: "The GitHub environment to deploy against."
```

### Permissions

This workflow also requires specific permissions:

- `id-token: write`: Required for requesting the JWT.
- `contents: read`: Required for actions/checkout.

### Job Details

#### Deploy

- **Name**: Deploy to ${{ inputs.environment }}
- **Environment**: ${{ inputs.environment }}
- **Environment Variables**:
- `ENVIRONMENT`: ${{ vars.ENVIRONMENT }}
- `CDK_DEPLOY_ACCOUNT`: ${{ vars.ACCOUNT_ID }}
- `CDK_DEPLOY_REGION`: ${{ vars.REGION }}
- **Runs On**: ubuntu-latest
- **Defaults**:
- Working Directory: `src`

#### Steps

1. **Checkout Repository**: This step checks out the repository to the GitHub Actions runner.

```yaml
- name: Checkout
uses: actions/checkout@v3
```

2. **Configure AWS Credentials**: This step configures AWS credentials for the specified environment.

```yaml
- name: Configure AWS Credentials ${{ inputs.environment }}
uses: aws-actions/configure-aws-credentials@v2
with:
role-to-assume: arn:aws:iam::${{ vars.ACCOUNT_ID }}:role/${{ vars.DEPLOYMENT_ROLE}}
role-session-name: cdk-deployment-${{ vars.REGION }}-${{ vars.ACCOUNT_ID }}
aws-region: ${{ vars.REGION }}
```

3. **Install Dependencies**: This step installs necessary dependencies, including AWS CDK and Python requirements.

```yaml
- name: Install Dependencies
run: |
npm install -g aws-cdk
pip install -r requirements.txt
```

4. **CDK Synth**: This step runs `cdk synth` to generate CloudFormation templates.

```yaml
- name: CDK Synth
run: |
cdk synth
```

5. **Deploy CDK Stack**: This step deploys the CDK stack using `cdk deploy` with no approval required.

```yaml
- name: Deploy NumberGuessingGame
run: |
cdk deploy --app 'cdk.out/' --all --require-approval never
```
52 changes: 52 additions & 0 deletions .github/workflows/deploy.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
name: Deploy

on:
workflow_call:
inputs:
environment:
required: true
type: string
description: "The github environment to deploy against."

permissions:
id-token: write # This is required for requesting the JWT
contents: read # This is required for actions/checkout

jobs:
deploy:
name: Deploy to ${{ inputs.environment }}
environment: ${{ inputs.environment }}
env:
ENVIRONMENT: ${{ vars.ENVIRONMENT }}
CDK_DEPLOY_ACCOUNT: ${{ vars.ACCOUNT_ID }}
CDK_DEPLOY_REGION: ${{ vars.REGION }}
runs-on: ubuntu-latest
defaults:
run:
working-directory: src

steps:
# Checkout the repository to the GitHub Actions runner
- name: Checkout
uses: actions/checkout@v3

# Configure AWS Creds
- name: Configure AWS Credentials ${{ inputs.environment }}
uses: aws-actions/configure-aws-credentials@v2
with:
role-to-assume: arn:aws:iam::${{ vars.ACCOUNT_ID }}:role/${{ vars.DEPLOYMENT_ROLE}}
role-session-name: cdk-deployment-${{ vars.REGION }}-${{ vars.ACCOUNT_ID }}
aws-region: ${{ vars.REGION }}

- name: Install Dependencies
run: |
npm install -g aws-cdk
pip install -r requirements.txt
- name: CDK Synth
run: |
cdk synth
- name: Deploy NumberGuessingGame
run: |
cdk deploy --app 'cdk.out/' --all --require-approval never
20 changes: 20 additions & 0 deletions .github/workflows/deploy_dev.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
name: Deploy-CDK-Stack/Dev
run-name: Running ${{github.workflow}} off of ${{ github.ref_name }}

on:
push:
branches:
- develop

permissions:
id-token: write # This is required for requesting the JWT
contents: read # This is required for actions/checkout

jobs:
deploy:
name: Deploy Development
uses: ./.github/workflows/deploy.yaml
with:
environment: development


20 changes: 20 additions & 0 deletions .github/workflows/deploy_prod.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
name: Deploy-CDK-Stack/Prod
run-name: Running ${{github.workflow}} off of ${{ github.ref_name }}

on:
push:
branches:
- main

permissions:
id-token: write # This is required for requesting the JWT
contents: read # This is required for actions/checkout

jobs:
deploy:
name: Deploy Production
uses: ./.github/workflows/deploy.yaml
with:
environment: production


2 changes: 1 addition & 1 deletion src/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ def add_tags(
cloudfront_region = "us-east-1"

environment = os.environ.get("ENVIRONMENT")
environment = "production"
# environment = "development"
environment_config = app.node.try_get_context(environment)
account_id = environment_config.get("account_id")
region = environment_config.get("region")
Expand Down
72 changes: 72 additions & 0 deletions src/assets/about_us.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
<!DOCTYPE html>
<html lang="en">

<head>
<meta charset="UTF-8">
<!-- Meta tags for better SEO and Ads targeting -->
<meta name="description"
content="About the Number Guessing Game. Learn about our mission, the game, and the team behind it.">
<meta name="keywords" content="Number, Game, Guessing, About Us, Team, Mission">
<meta name="viewport" content="initial-scale=1, maximum-scale=1, user-scalable=no">
<title>About Us | Number Guessing Game</title>
<link rel="stylesheet" type="text/css" href="css/styles.css">
<!-- Asynchronous AdSense Code -->
<script async src="https://pagead2.googlesyndication.com/pagead/js/adsbygoogle.js?client=ca-pub-8738875399920144"
crossorigin="anonymous"></script>
</head>

<body>
<div id="wrapper">
<!-- Header Section -->
<header>
<h1>About Us</h1>
<nav>
<!-- Add some navigation links here -->
<a href="/">Home</a>
</nav>
</header>

<!-- Main Content Section -->
<main id="main-content" class="scrollable-content">
<section id="mission">
<h2>Our Mission</h2>
<p>
Our mission is to provide a fun and challenging experience for people who love numbers and puzzles.
We aim to improve cognitive skills and offer a delightful way to pass the time.
</p>
</section>

<section id="thegame">
<h2>The Game</h2>
<p>
The Number Guessing Game is designed to test your number guessing skills. You have to guess a
3-digit
number within a limited number of attempts. Various clues will guide you to the correct number,
making
each game a thrilling experience.
</p>
</section>

<section id="theteam">
<h2>The Team</h2>
<p>
It's just me. Cullan Carey. See everything about me <a href="https://cullancarey.com"
target="_blank">here</a>.
<span class="image avatar"><img src="images/avatar.jpg" alt="Cullan Carey Avatar" /></span>
</p>
</section>
</main>

<!-- Footer -->
<footer>
<nav>
<a href="terms_of_service.html">Terms of Service</a>
<a href="privacy_policy.html">Privacy Policy</a>
</nav>
</footer>
</div>

<script type="module" src="js/main.js"></script>
</body>

</html>
Loading

0 comments on commit fce0754

Please sign in to comment.