Skip to content

Commit

Permalink
More static deployment stuff (#19)
Browse files Browse the repository at this point in the history
* More static deployment stuff

* Fix tests

* fix cd
  • Loading branch information
lukeshay authored Nov 30, 2022
1 parent a2a876d commit 303cf98
Show file tree
Hide file tree
Showing 32 changed files with 689 additions and 204 deletions.
2 changes: 1 addition & 1 deletion .changeset/config.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,6 @@
"commit": false,
"fixed": [],
"ignore": ["@astro-aws/www", "@astro-aws/infra"],
"linked": [],
"linked": [["@astro-aws/adapter", "@astro-aws/constructs"]],
"updateInternalDependencies": "patch"
}
6 changes: 6 additions & 0 deletions .changeset/cool-buckets-hunt.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
"@astro-aws/adapter": minor
"@astro-aws/constructs": minor
---

Added support for static deployments
1 change: 1 addition & 0 deletions .eslintignore
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
.env
.env.production
.netlify
.turbo
cdk.out/
dist/
node_modules/
Expand Down
14 changes: 14 additions & 0 deletions .github/FUNDING.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
github:
- lukeshay
custom:
- https://account.venmo.com/u/LukeShay
- https://paypal.me/rlshay
# patreon: # Replace with a single Patreon username
# open_collective: # Replace with a single Open Collective username
# ko_fi: # Replace with a single Ko-fi username
# tidelift: # Replace with a single Tidelift platform-name/package-name e.g., npm/babel
# community_bridge: # Replace with a single Community Bridge project-name e.g., cloud-foundry
# liberapay: # Replace with a single Liberapay username
# issuehunt: # Replace with a single IssueHunt username
# otechie: # Replace with a single Otechie username
# lfx_crowdfunding: # Replace with a single LFX Crowdfunding project-name e.g., cloud-foundry
72 changes: 38 additions & 34 deletions .github/workflows/cd-dev.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,56 +11,60 @@ on:

env:
CI: true
TURBO_TOKEN: ${{ secrets.TURBO_TOKEN }}
TURBO_TEAM: ${{ secrets.TURBO_TEAM }}

permissions:
id-token: write
contents: read
deployments: write

jobs:
deploy-dev:
name: Deploy Dev
prepare-yarn-cache:
name: Cache dependencies
runs-on: ubuntu-22.04
environment:
name: development
url: https://astro-aws.dev.lshay.dev/
concurrency:
group: ${{ format('{0}-{1}', github.workflow, github.job) }}
steps:
- run: echo "::add-mask::${{ secrets.AWS_ACCOUNT_ID }}"
- uses: actions/checkout@v3
- name: Configure AWS Credentials
uses: aws-actions/configure-aws-credentials@v1
with:
aws-region: us-east-1
role-to-assume: ${{ secrets.AWS_ROLE_ARN }}
role-session-name: astro-aws-cd-dev
- uses: actions/setup-node@v3
with:
node-version: "18"
cache: "yarn"
- run: yarn install --mode=skip-build
- run: yarn deploy:one infra -- DEV
env:
YARN_ENABLE_SCRIPTS: false
deploy-dev:
name: Deploy Dev
needs: [prepare-yarn-cache]
concurrency:
group: ${{ format('{0}-{1}', github.workflow, github.job) }}
uses: ./.github/workflows/deploy.yml
with:
aws_session_name: astro-aws-cd-dev
environment_name: development
environment_url: https://dev.astro-aws.org/
stack_environment: DEV
secrets: inherit
deploy-dev-node-16:
name: Deploy Dev Node 16
runs-on: ubuntu-22.04
environment:
name: development-node-16
url: https://astro-aws.dev-node-16.lshay.dev/
needs: [prepare-yarn-cache]
concurrency:
group: ${{ format('{0}-{1}', github.workflow, github.job) }}
steps:
- run: echo "::add-mask::${{ secrets.AWS_ACCOUNT_ID }}"
- uses: actions/checkout@v3
- name: Configure AWS Credentials
uses: aws-actions/configure-aws-credentials@v1
with:
aws-region: us-east-1
role-to-assume: ${{ secrets.AWS_ROLE_ARN }}
role-session-name: astro-aws-cd-dev-node-16
- uses: actions/setup-node@v3
with:
node-version: "16"
cache: "yarn"
- run: yarn install --mode=skip-build
- run: yarn deploy:one infra -- NODE16
uses: ./.github/workflows/deploy.yml
with:
aws_session_name: astro-aws-cd-node-16
environment_name: development-node-16
environment_url: https://dev-node-16.astro-aws.org/
stack_environment: NODE16
secrets: inherit
deploy-dev-node-18:
name: Deploy Dev Node 18
needs: [prepare-yarn-cache]
concurrency:
group: ${{ format('{0}-{1}', github.workflow, github.job) }}
uses: ./.github/workflows/deploy.yml
with:
aws_session_name: astro-aws-cd-node-18
environment_name: development-node-18
environment_url: https://dev-node-18.astro-aws.org/
stack_environment: NODE18
secrets: inherit
4 changes: 3 additions & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ on:

env:
CI: true
TURBO_TOKEN: ${{ secrets.TURBO_TOKEN }}
TURBO_TEAM: ${{ secrets.TURBO_TEAM }}

jobs:
prepare-yarn-cache:
Expand All @@ -17,7 +19,7 @@ jobs:
- uses: actions/checkout@v3
- uses: actions/setup-node@v3
with:
node-version: "16"
node-version: "18"
cache: "yarn"
- run: yarn install --mode=skip-build
env:
Expand Down
89 changes: 89 additions & 0 deletions .github/workflows/deploy.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
name: Deploy

on:
workflow_call:
inputs:
node_version:
description: The version of node to use
required: true
type: string
default: "18"
stack_environment:
description: The stack environment to deploy
required: true
type: string
environment_name:
description: The GitHub environment name
required: true
type: string
environment_url:
description: The GitHub environment url
required: true
type: string
aws_session_name:
description: AWS session name
required: false
type: string
aws_region:
description: The AWS region
required: false
type: string
default: us-east-1
ref:
description: The git ref to checkout
required: false
type: string
repository:
description: The git repository to checkout
required: false
type: string
secrets:
AWS_ROLE_ARN:
description: The AWS Role ARN to use
required: true
AWS_ACCOUNT_ID:
description: The AWS Account ID
required: true
TURBO_TOKEN:
description: Turborepo remote cache token
required: false
TURBO_TEAM:
description: Turborepo remote cache team
required: false

env:
CI: true

permissions:
id-token: write
contents: read
deployments: write

jobs:
deploy:
name: Deploy
runs-on: ubuntu-22.04
env:
TURBO_TOKEN: ${{ secrets.TURBO_TOKEN }}
TURBO_TEAM: ${{ secrets.TURBO_TEAM }}
environment:
name: ${{ inputs.environment_name }}
url: ${{ inputs.environment_url }}
steps:
- run: echo "::add-mask::${{ secrets.AWS_ACCOUNT_ID }}"
- uses: actions/checkout@v3
with:
ref: ${{ inputs.ref }}
repository: ${{ inputs.repository }}
- name: Configure AWS Credentials
uses: aws-actions/configure-aws-credentials@v1
with:
aws-region: ${{ inputs.aws_region }}
role-to-assume: ${{ secrets.AWS_ROLE_ARN }}
role-session-name: ${{ inputs.aws_session_name }}
- uses: actions/setup-node@v3
with:
node-version: ${{ inputs.node_version }}
cache: "yarn"
- run: yarn install --mode=skip-build
- run: yarn deploy:one infra -- ${{ inputs.stack_environment }}
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
.DS_Store
.env*
.netlify
.turbo
.turbo/
cdk.out/
dist/
Expand Down
1 change: 1 addition & 0 deletions .prettierignore
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
.env
.env.production
.netlify
.turbo
cdk.out/
dist/
node_modules/
Expand Down
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1 +1,3 @@
# astro-aws

[![CI](https://github.com/lukeshay/astro-aws/actions/workflows/ci.yml/badge.svg)](https://github.com/lukeshay/astro-aws/actions/workflows/ci.yml) [![CD](https://github.com/lukeshay/astro-aws/actions/workflows/cd-dev.yml/badge.svg)](https://github.com/lukeshay/astro-aws/actions/workflows/cd-dev.yml)
11 changes: 5 additions & 6 deletions apps/infra/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"name": "@astro-aws/infra",
"version": "0.0.0",
"private": true,
"homepage": "https://astro-aws.lshay.dev/",
"homepage": "https://astro-aws.org/",
"repository": {
"type": "git",
"url": "ssh://[email protected]/lukeshay/astro-aws.git",
Expand All @@ -18,8 +18,7 @@
],
"scripts": {
"build": "scripts build",
"deploy": "./scripts/build-and-invalidate.sh",
"invalidate": "./scripts/invalidate-cloudfront-cache.sh",
"deploy": "./scripts/deploy.sh",
"synth": "cdk synth"
},
"eslintConfig": {
Expand All @@ -32,9 +31,9 @@
"@astro-aws/constructs": "workspace:^",
"@astro-aws/www": "workspace:^",
"@types/node": "^18.11.9",
"aws-cdk": "^2.52.0",
"aws-cdk-lib": "^2.52.0",
"constructs": "^10.1.173",
"aws-cdk": "^2.53.0",
"aws-cdk-lib": "^2.53.0",
"constructs": "^10.1.175",
"eslint": "^8.28.0",
"prettier": "^2.8.0",
"typescript": "^4.9.3"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,3 @@ echo "AWS_ACCOUNT: ${AWS_ACCOUNT}"
echo "AWS_REGION: ${AWS_REGION}"

yarn cdk deploy --require-approval never "AstroAWS-${ENVIRONMENT}-*" ${AWS_ARGS}
./scripts/invalidate-cloudfront-cache.sh "${@}"
20 changes: 0 additions & 20 deletions apps/infra/scripts/invalidate-cloudfront-cache.sh

This file was deleted.

21 changes: 18 additions & 3 deletions apps/infra/src/lib/constants/environments.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
const base = {
analyticsReporting: false,
hostedZoneId: "Z0584480MGUI8KRBPWM",
};

export const Environments = {
DEV: "DEV",
DEV_NODE_16: "NODE16",
DEV_NODE_18: "NODE18",
PERSONAL: "PERSONAL",
PROD: "PROD",
} as const;
Expand All @@ -14,21 +16,34 @@ export type Environment = typeof Environments[keyof typeof Environments];
export const ENVIRONMENT_PROPS = {
[Environments.DEV]: {
...base,
domainName: "astro-aws.dev.lshay.dev",
alias: "dev",
environment: Environments.DEV,
hostedZoneName: "astro-aws.org",
output: "static",
},
[Environments.DEV_NODE_16]: {
...base,
domainName: "astro-aws.dev-node-16.lshay.dev",
alias: "node16.dev",
environment: Environments.DEV_NODE_16,
hostedZoneName: "astro-aws.org",
output: "server",
},
[Environments.DEV_NODE_18]: {
...base,
alias: "node18.dev",
environment: Environments.DEV_NODE_18,
hostedZoneName: "astro-aws.org",
output: "server",
},
[Environments.PROD]: {
...base,
domainName: "astro-aws.lshay.dev",
environment: Environments.PROD,
hostedZoneName: "astro-aws.org",
output: "static",
},
[Environments.PERSONAL]: {
...base,
environment: Environments.PERSONAL,
output: "static",
},
} as const;
Loading

0 comments on commit 303cf98

Please sign in to comment.