Skip to content

Commit

Permalink
Make API Gateway optional - default skip (#292)
Browse files Browse the repository at this point in the history
* Make API Gateway optional - default skip

Fixes #291

* Point to S3 origin when no APIgwy origin

* Only add execute-api permission when needed

* Override the S3 origin

* Only upload CDK synth zip when labeled

Saves about two minutes in deploy job

* Try caching installed node modules

* Make more module installs optional

* Fix CDK construct optional install

* Attempt to fix SigV4 failure

* Add OriginShield

* fix path

* Fix module cache for jsii

* Fix createNextDataPathRoute

* Fix app URLs listed on PR

* Fix link
  • Loading branch information
huntharo authored Jan 8, 2023
1 parent 6a18126 commit 9354613
Show file tree
Hide file tree
Showing 11 changed files with 402 additions and 189 deletions.
89 changes: 74 additions & 15 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -47,10 +47,34 @@ jobs:
uses: actions/setup-node@v3
with:
node-version: 16
cache: 'yarn'
cache-dependency-path: '**/yarn.lock'
# Note: this cache is not particularly useful...
# It is about 780 MB and is only needed if we run `yarn install`,
# which we only do if `yarn.lock` has changed, which means this cacue
# key is changed in that case... so... it's not useful in the one
# case where we need it because we are caching installed modules below.
# cache: 'yarn'
# cache-dependency-path: '**/yarn.lock'

# https://www.jonathan-wilkinson.com/github-actions-cache-everything
- name: Cache Node Modules
id: cache-node-modules
uses: actions/cache@v3
with:
path: |
**/node_modules
key: node-modules-ci-${{ hashFiles('**/yarn.lock') }}

- name: Optionally Install Node Modules
if: steps.cache-node-modules.outputs.cache-hit != 'true'
run: yarn install --frozen-lockfile

- name: Install Node Modules
# We do this here so the `build-jsii` modules are installed too
# and become part of the cache - if we don't then
# their install will get skipped during `build-jsii` but they won't
# be present in the cache so the build will fail
- name: Optionally Install CDK Construct Deps
if: steps.cache-node-modules.outputs.cache-hit != 'true'
working-directory: packages/microapps-cdk/
run: yarn install --frozen-lockfile

- name: Extract App NPM Versions
Expand Down Expand Up @@ -127,10 +151,25 @@ jobs:
uses: actions/setup-node@v3
with:
node-version: 16
cache: 'yarn'
cache-dependency-path: '**/yarn.lock'
# Note: this cache is not particularly useful...
# It is about 780 MB and is only needed if we run `yarn install`,
# which we only do if `yarn.lock` has changed, which means this cacue
# key is changed in that case... so... it's not useful in the one
# case where we need it because we are caching installed modules below.
# cache: 'yarn'
# cache-dependency-path: '**/yarn.lock'

# https://www.jonathan-wilkinson.com/github-actions-cache-everything
- name: Cache Node Modules
id: cache-node-modules
uses: actions/cache@v3
with:
path: |
**/node_modules
key: node-modules-ci-${{ hashFiles('**/yarn.lock') }}

- name: Install Node Modules
- name: Optionally Install Node Modules
if: steps.cache-node-modules.outputs.cache-hit != 'true'
run: yarn install --frozen-lockfile

- name: Build All TypeScript
Expand Down Expand Up @@ -164,18 +203,22 @@ jobs:
npx replace-in-file "/\/u002F${RELEASE_APP_NAME}/g" ${PREFIX_U}/u002F${RELEASE_APP_NAME} --configFile=.release-replace.config.js --isRegex
fi
#
# Synth and upload if BUILD-CDK-ZIP label is present
#
- name: Synth CDK Stack
if: github.event_name == 'pull_request' && contains( github.event.pull_request.labels.*.name, 'BUILD-CDK-ZIP')
run: |
npx cdk synth --context @pwrdrvr/microapps:deployDemoApp=true \
--context @pwrdrvr/microapps:deployNexjsDemoApp=true \
--context @pwrdrvr/microapps:deployReleaseApp=true \
--require-approval never ${{ matrix.deployName }}
# Upload Synth
- name: Zip Package
if: github.event_name == 'pull_request' && contains( github.event.pull_request.labels.*.name, 'BUILD-CDK-ZIP')
working-directory: .
run: zip -r cdk-out.zip cdk.out
- name: Upload Zip
if: github.event_name == 'pull_request' && contains( github.event.pull_request.labels.*.name, 'BUILD-CDK-ZIP')
uses: actions/upload-artifact@v3
with:
name: cdk_out_${{ matrix.deployName }}
Expand Down Expand Up @@ -226,7 +269,7 @@ jobs:
description: 'Passed'
state: 'success'
sha: ${{github.event.pull_request.head.sha || github.sha}}
target_url: https://${{ steps.getCDKExports.outputs.edgeDomain }}${{ steps.getCDKExports.outputs.prefix }}/${{ env.DEMO_APP_NAME }}?appver=${{ env.PACKAGE_VERSION }}
target_url: https://${{ steps.getCDKExports.outputs.edgeDomain }}${{ steps.getCDKExports.outputs.prefix }}/${{ env.DEMO_APP_NAME }}/?appver=${{ env.PACKAGE_VERSION }}

- name: Test Demo App
run: |
Expand Down Expand Up @@ -310,7 +353,7 @@ jobs:
description: 'Passed'
state: 'success'
sha: ${{github.event.pull_request.head.sha || github.sha}}
target_url: https://${{ steps.getCDKExports.outputs.edgeDomain }}${{ steps.getCDKExports.outputs.prefix }}/${{ env.NEXTJS_DEMO_APP_NAME }}/${{ needs.build.outputs.nextjsDemoAppPackageVersion }}
target_url: https://${{ steps.getCDKExports.outputs.edgeDomain }}${{ steps.getCDKExports.outputs.prefix }}/${{ env.NEXTJS_DEMO_APP_NAME }}?appver=${{ needs.build.outputs.nextjsDemoAppPackageVersion }}

- name: Test Nextjs Demo App
run: |
Expand Down Expand Up @@ -341,7 +384,7 @@ jobs:
description: 'Passed'
state: 'success'
sha: ${{github.event.pull_request.head.sha || github.sha}}
target_url: https://${{ steps.getCDKExports.outputs.edgeDomain }}${{ steps.getCDKExports.outputs.prefix }}/${{ env.RELEASE_APP_NAME }}/${{ needs.build.outputs.releaseAppPackageVersion }}
target_url: https://${{ steps.getCDKExports.outputs.edgeDomain }}${{ steps.getCDKExports.outputs.prefix }}/${{ env.RELEASE_APP_NAME }}?appver=${{ needs.build.outputs.releaseAppPackageVersion }}

- name: Test Release App
run: |
Expand All @@ -362,10 +405,25 @@ jobs:
uses: actions/setup-node@v3
with:
node-version: 16
cache: 'yarn'
cache-dependency-path: '**/yarn.lock'
# Note: this cache is not particularly useful...
# It is about 780 MB and is only needed if we run `yarn install`,
# which we only do if `yarn.lock` has changed, which means this cacue
# key is changed in that case... so... it's not useful in the one
# case where we need it because we are caching installed modules below.
# cache: 'yarn'
# cache-dependency-path: '**/yarn.lock'

# https://www.jonathan-wilkinson.com/github-actions-cache-everything
- name: Cache Node Modules
id: cache-node-modules
uses: actions/cache@v3
with:
path: |
**/node_modules
key: node-modules-ci-${{ hashFiles('**/yarn.lock') }}

- name: Install Node Modules
- name: Optionally Install Node Modules
if: steps.cache-node-modules.outputs.cache-hit != 'true'
run: yarn install --frozen-lockfile

# - name: Generate Projen Files
Expand All @@ -385,7 +443,8 @@ jobs:
# - name: Move root modules out of the way for CDK Construct build
# run: mv node_modules node_modules_hide

- name: Install CDK Construct Deps
- name: Optionally Install CDK Construct Deps
if: steps.cache-node-modules.outputs.cache-hit != 'true'
working-directory: packages/microapps-cdk/
run: yarn install --frozen-lockfile

Expand Down
3 changes: 3 additions & 0 deletions packages/demo-app/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,9 @@ export async function handler(
// eslint-disable-next-line @typescript-eslint/no-unused-vars
context?: lambda.Context,
): Promise<unknown> {
// eslint-disable-next-line no-console
console.log('event', event);

if (event.rawPath.endsWith('/serverIncrement')) {
const currValue = parseInt(event.queryStringParameters?.currValue ?? '0', 10);
const newValue = currValue + 1;
Expand Down
Loading

0 comments on commit 9354613

Please sign in to comment.