Skip to content

Commit

Permalink
Issue 305 - Pass through additional path segments and use appver for …
Browse files Browse the repository at this point in the history
…static apps (#334)

* Add a test to show that iframe appver qs works

* Pass additional paths to static app iframes

* Remove erroneous --no-paginate

* Add static test app

* Fix filename

* Remove startup-type arg
  • Loading branch information
huntharo authored May 19, 2023
1 parent c87b3e7 commit 10ee3d3
Show file tree
Hide file tree
Showing 17 changed files with 262 additions and 59 deletions.
69 changes: 41 additions & 28 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,12 @@ name: CI

on:
push:
branches: [ main ]
branches: [main]
paths:
- '**'
- '!**/README.md'
pull_request:
branches: [ main ]
branches: [main]
paths:
- '**'
- '!**/README.md'
Expand All @@ -21,6 +21,7 @@ env:
# Set env to prod so we don't get an env suffix on the DNS names
NODE_ENV: ${{ secrets.NODE_ENV }}
DEMO_APP_NAME: demo-app
STATIC_APP_NAME: static-app
NEXTJS_DEMO_APP_NAME: nextjs-demo
RELEASE_APP_NAME: release
AWS_REGION: us-east-2
Expand Down Expand Up @@ -101,8 +102,8 @@ jobs:

- name: Optionally Build All TypeScript
if: steps.cache-typescript-build.outputs.cache-hit != 'true'
run: yarn build
run: yarn build

- name: Run Lint
run: yarn lint

Expand Down Expand Up @@ -230,17 +231,19 @@ jobs:

- name: Build Edge-to-Origin for Local Deploy
run: yarn esbuild:edge-to-origin

- name: Configure AWS Credentials
uses: aws-actions/configure-aws-credentials@v2
with:
role-session-name: microapps-ghpublic-build
role-to-assume: arn:aws:iam::${{ secrets.AWS_ACCOUNT_ID }}:role/builder-writeRole
aws-region: ${{ env.AWS_REGION }}

- name: Stitch Version and Prefix into Simple Demo App
- name: Stitch Version and Prefix into Simple Demo App and Static App
run: |
npx replace-in-file "/\/0\.0\.0/g" ${PREFIX}/${PACKAGE_VERSION} --configFile=.demo-app-replace.config.js --isRegex
npx replace-in-file "/\/0\.0\.0/g" ${PREFIX}/${PACKAGE_VERSION} --configFile=.demo-app-replace.config.js --isRegex
npx replace-in-file "/0\.0\.0/g" ${PACKAGE_VERSION} --configFile=.demo-app-replace.config.js --isRegex
npx replace-in-file "/0\.0\.0/g" ${PACKAGE_VERSION} --configFile=.static-app-replace.config.js --isRegex
- name: Stitch Prefix into Nextjs Demo App
run: |
Expand Down Expand Up @@ -307,17 +310,17 @@ jobs:
id: getCDKExports
run: |
echo "prefix="${PREFIX} >> $GITHUB_OUTPUT
echo "edgeDomain="$(aws cloudformation list-exports --query "Exports[?Name==\`${{ matrix.deployName }}-ghpublic-${NODE_ENV}${{ needs.build.outputs.prSuffix }}-edge-domain-name\`].Value" --no-paginate --output text) >> $GITHUB_OUTPUT
echo "EDGE_DOMAIN="$(aws cloudformation list-exports --query "Exports[?Name==\`${{ matrix.deployName }}-ghpublic-${NODE_ENV}${{ needs.build.outputs.prSuffix }}-edge-domain-name\`].Value" --no-paginate --output text) >> $GITHUB_ENV
echo "EDGE_TO_ORIGIN_ROLE_ARN="$(aws cloudformation list-exports --query "Exports[?Name==\`${{ matrix.deployName }}-ghpublic-${NODE_ENV}${{ needs.build.outputs.prSuffix }}-edge-role-role-arn\`].Value" --no-paginate --output text) >> $GITHUB_ENV
echo "DEPLOYER_LAMBDA_NAME="$(aws cloudformation list-exports --query "Exports[?Name==\`${{ matrix.deployName }}-ghpublic-${NODE_ENV}${{ needs.build.outputs.prSuffix }}-deployer-func-name\`].Value" --no-paginate --output text) >> $GITHUB_ENV
echo "DEPLOYER_LAMBDA_ARN="$(aws cloudformation list-exports --query "Exports[?Name==\`${{ matrix.deployName }}-ghpublic-${NODE_ENV}${{ needs.build.outputs.prSuffix }}-deployer-func-arn\`].Value" --no-paginate --output text) >> $GITHUB_ENV
echo "DEMO_APP_LAMBDA_NAME="$(aws cloudformation list-exports --query "Exports[?Name==\`${{ matrix.deployName }}-ghpublic-${NODE_ENV}${{ needs.build.outputs.prSuffix }}-demo-app-func-name\`].Value" --no-paginate --output text) >> $GITHUB_ENV
echo "DEMO_APP_LAMBDA_VERSION_ARN="$(aws cloudformation list-exports --query "Exports[?Name==\`${{ matrix.deployName }}-ghpublic-${NODE_ENV}${{ needs.build.outputs.prSuffix }}-demo-app-vers-arn\`].Value" --no-paginate --output text) >> $GITHUB_ENV
echo "NEXTJS_DEMO_APP_LAMBDA_NAME="$(aws cloudformation list-exports --query "Exports[?Name==\`${{ matrix.deployName }}-ghpublic-${NODE_ENV}${{ needs.build.outputs.prSuffix }}-nextjs-demo-app-func-name\`].Value" --no-paginate --output text) >> $GITHUB_ENV
echo "NEXTJS_DEMO_APP_LAMBDA_VERSION_ARN="$(aws cloudformation list-exports --query "Exports[?Name==\`${{ matrix.deployName }}-ghpublic-${NODE_ENV}${{ needs.build.outputs.prSuffix }}-nextjs-demo-app-vers-arn\`].Value" --no-paginate --output text) >> $GITHUB_ENV
echo "RELEASE_APP_LAMBDA_NAME="$(aws cloudformation list-exports --query "Exports[?Name==\`${{ matrix.deployName }}-ghpublic-${NODE_ENV}${{ needs.build.outputs.prSuffix }}-release-app-func-name\`].Value" --no-paginate --output text) >> $GITHUB_ENV
echo "RELEASE_APP_LAMBDA_VERSION_ARN="$(aws cloudformation list-exports --query "Exports[?Name==\`${{ matrix.deployName }}-ghpublic-${NODE_ENV}${{ needs.build.outputs.prSuffix }}-release-app-vers-arn\`].Value" --no-paginate --output text) >> $GITHUB_ENV
echo "edgeDomain="$(aws cloudformation list-exports --query "Exports[?Name==\`${{ matrix.deployName }}-ghpublic-${NODE_ENV}${{ needs.build.outputs.prSuffix }}-edge-domain-name\`].Value" --output text) >> $GITHUB_OUTPUT
echo "EDGE_DOMAIN="$(aws cloudformation list-exports --query "Exports[?Name==\`${{ matrix.deployName }}-ghpublic-${NODE_ENV}${{ needs.build.outputs.prSuffix }}-edge-domain-name\`].Value" --output text) >> $GITHUB_ENV
echo "EDGE_TO_ORIGIN_ROLE_ARN="$(aws cloudformation list-exports --query "Exports[?Name==\`${{ matrix.deployName }}-ghpublic-${NODE_ENV}${{ needs.build.outputs.prSuffix }}-edge-role-role-arn\`].Value" --output text) >> $GITHUB_ENV
echo "DEPLOYER_LAMBDA_NAME="$(aws cloudformation list-exports --query "Exports[?Name==\`${{ matrix.deployName }}-ghpublic-${NODE_ENV}${{ needs.build.outputs.prSuffix }}-deployer-func-name\`].Value" --output text) >> $GITHUB_ENV
echo "DEPLOYER_LAMBDA_ARN="$(aws cloudformation list-exports --query "Exports[?Name==\`${{ matrix.deployName }}-ghpublic-${NODE_ENV}${{ needs.build.outputs.prSuffix }}-deployer-func-arn\`].Value" --output text) >> $GITHUB_ENV
echo "DEMO_APP_LAMBDA_NAME="$(aws cloudformation list-exports --query "Exports[?Name==\`${{ matrix.deployName }}-ghpublic-${NODE_ENV}${{ needs.build.outputs.prSuffix }}-demo-app-func-name\`].Value" --output text) >> $GITHUB_ENV
echo "DEMO_APP_LAMBDA_VERSION_ARN="$(aws cloudformation list-exports --query "Exports[?Name==\`${{ matrix.deployName }}-ghpublic-${NODE_ENV}${{ needs.build.outputs.prSuffix }}-demo-app-vers-arn\`].Value" --output text) >> $GITHUB_ENV
echo "NEXTJS_DEMO_APP_LAMBDA_NAME="$(aws cloudformation list-exports --query "Exports[?Name==\`${{ matrix.deployName }}-ghpublic-${NODE_ENV}${{ needs.build.outputs.prSuffix }}-nextjs-demo-app-func-name\`].Value" --output text) >> $GITHUB_ENV
echo "NEXTJS_DEMO_APP_LAMBDA_VERSION_ARN="$(aws cloudformation list-exports --query "Exports[?Name==\`${{ matrix.deployName }}-ghpublic-${NODE_ENV}${{ needs.build.outputs.prSuffix }}-nextjs-demo-app-vers-arn\`].Value" --output text) >> $GITHUB_ENV
echo "RELEASE_APP_LAMBDA_NAME="$(aws cloudformation list-exports --query "Exports[?Name==\`${{ matrix.deployName }}-ghpublic-${NODE_ENV}${{ needs.build.outputs.prSuffix }}-release-app-func-name\`].Value" --output text) >> $GITHUB_ENV
echo "RELEASE_APP_LAMBDA_VERSION_ARN="$(aws cloudformation list-exports --query "Exports[?Name==\`${{ matrix.deployName }}-ghpublic-${NODE_ENV}${{ needs.build.outputs.prSuffix }}-release-app-vers-arn\`].Value" --output text) >> $GITHUB_ENV
- name: Echo Exports
run: |
Expand All @@ -337,6 +340,16 @@ jobs:
--url https://www.pwrdrvr.com \
--overwrite
- name: Publish Static App to Child MicroApps
run: |
npx microapps-publish publish-static \
--app-name ${STATIC_APP_NAME} \
--new-version 0.0.0 \
--deployer-lambda-name ${DEPLOYER_LAMBDA_ARN} \
--static-assets-path packages/static-app/src \
--default-file index.html \
--overwrite
- name: Publish Demo App to MicroApps
run: |
npx microapps-publish publish \
Expand All @@ -352,7 +365,7 @@ jobs:
- name: Demo App URL
uses: Sibz/github-status-action@v1
with:
with:
authToken: ${{secrets.GITHUB_TOKEN}}
context: 'Demo App URL on ${{ matrix.deployName }}'
description: 'Passed'
Expand Down Expand Up @@ -407,7 +420,7 @@ jobs:
- name: Demo App URL - Root App
uses: Sibz/github-status-action@v1
with:
with:
authToken: ${{secrets.GITHUB_TOKEN}}
context: 'Demo App (Root App) URL on ${{ matrix.deployName }}'
description: 'Passed'
Expand Down Expand Up @@ -440,7 +453,7 @@ jobs:
- name: Nextjs Demo App URL
uses: Sibz/github-status-action@v1
with:
with:
authToken: ${{secrets.GITHUB_TOKEN}}
context: 'Nextjs Demo App URL on ${{ matrix.deployName }}'
description: 'Passed'
Expand Down Expand Up @@ -472,7 +485,7 @@ jobs:
- name: Release App URL
uses: Sibz/github-status-action@v1
with:
with:
authToken: ${{secrets.GITHUB_TOKEN}}
context: 'Release App URL on ${{ matrix.deployName }}'
description: 'Passed'
Expand Down Expand Up @@ -516,10 +529,10 @@ jobs:
if: ${{ matrix.deployName == 'microapps-core' }}
id: getChildCDKExports
run: |
echo "CHILD_DEPLOYER_LAMBDA_ARN="$(aws cloudformation list-exports --query "Exports[?Name==\`${{ matrix.deployName }}-ghchild-${NODE_ENV}${{ needs.build.outputs.prSuffix }}-deployer-func-arn\`].Value" --no-paginate --output text) >> $GITHUB_ENV
echo "CHILD_DEMO_APP_LAMBDA_NAME="$(aws cloudformation list-exports --query "Exports[?Name==\`${{ matrix.deployName }}-ghchild-${NODE_ENV}${{ needs.build.outputs.prSuffix }}-demo-app-func-name\`].Value" --no-paginate --output text) >> $GITHUB_ENV
echo "CHILD_DEMO_APP_LAMBDA_VERSION_ARN="$(aws cloudformation list-exports --query "Exports[?Name==\`${{ matrix.deployName }}-ghchild-${NODE_ENV}${{ needs.build.outputs.prSuffix }}-demo-app-vers-arn\`].Value" --no-paginate --output text) >> $GITHUB_ENV
echo "CHILD_DEPLOYER_LAMBDA_ARN="$(aws cloudformation list-exports --query "Exports[?Name==\`${{ matrix.deployName }}-ghchild-${NODE_ENV}${{ needs.build.outputs.prSuffix }}-deployer-func-arn\`].Value" --output text) >> $GITHUB_ENV
echo "CHILD_DEMO_APP_LAMBDA_NAME="$(aws cloudformation list-exports --query "Exports[?Name==\`${{ matrix.deployName }}-ghchild-${NODE_ENV}${{ needs.build.outputs.prSuffix }}-demo-app-func-name\`].Value" --output text) >> $GITHUB_ENV
echo "CHILD_DEMO_APP_LAMBDA_VERSION_ARN="$(aws cloudformation list-exports --query "Exports[?Name==\`${{ matrix.deployName }}-ghchild-${NODE_ENV}${{ needs.build.outputs.prSuffix }}-demo-app-vers-arn\`].Value" --output text) >> $GITHUB_ENV
- name: Echo Exports
if: ${{ matrix.deployName == 'microapps-core' }}
run: |
Expand Down Expand Up @@ -637,8 +650,8 @@ jobs:
jq ".compilerOptions += { \"skipLibCheck\": true }" packages/microapps-cdk/tsconfig.jsii.json > packages/microapps-cdk/tsconfig.json
- name: Build All TypeScript
run: yarn build
run: yarn build

- name: Install CDK Construct Deps
working-directory: packages/microapps-cdk/
run: yarn install --frozen-lockfile
Expand Down
10 changes: 5 additions & 5 deletions .github/workflows/pr-closed.yml
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ jobs:
if: ${{ matrix.deployName == 'microapps-core' }}
run: |
aws cloudformation delete-stack --stack-name "${{ matrix.deployName }}-ghchild-priv-${NODE_ENV}-pr-${PR_NUMBER}"
aws cloudformation wait stack-delete-complete --no-paginate --output text --stack-name "${{ matrix.deployName }}-ghchild-priv-${NODE_ENV}-pr-${PR_NUMBER}"
aws cloudformation wait stack-delete-complete --output text --stack-name "${{ matrix.deployName }}-ghchild-priv-${NODE_ENV}-pr-${PR_NUMBER}"
#
# Cleanup the Child Deployer, when applicable
Expand All @@ -69,7 +69,7 @@ jobs:
if: ${{ matrix.deployName == 'microapps-core' }}
run: |
aws cloudformation delete-stack --stack-name "${{ matrix.deployName }}-ghchild-${NODE_ENV}-pr-${PR_NUMBER}"
aws cloudformation wait stack-delete-complete --no-paginate --output text --stack-name "${{ matrix.deployName }}-ghchild-${NODE_ENV}-pr-${PR_NUMBER}"
aws cloudformation wait stack-delete-complete --output text --stack-name "${{ matrix.deployName }}-ghchild-${NODE_ENV}-pr-${PR_NUMBER}"
#
# Cleanup the Lambda Resource Policy allowing Child Deployer
Expand All @@ -85,17 +85,17 @@ jobs:
- name: Destroy Parent CDK Stack
run: |
aws cloudformation delete-stack --stack-name "${{ matrix.deployName }}-ghpublic-${NODE_ENV}-pr-${PR_NUMBER}"
aws cloudformation wait stack-delete-complete --no-paginate --output text --stack-name "${{ matrix.deployName }}-ghpublic-${NODE_ENV}-pr-${PR_NUMBER}"
aws cloudformation wait stack-delete-complete --output text --stack-name "${{ matrix.deployName }}-ghpublic-${NODE_ENV}-pr-${PR_NUMBER}"
# TODO - Need to get the stack name from the parent stack export
# - name: Destroy Parent Edge to Origin Stack
# run: |
# aws cloudformation delete-stack --stack-name "${{ matrix.deployName }}-ghpublic-${NODE_ENV}-pr-${PR_NUMBER}"
# aws cloudformation wait stack-delete-complete --no-paginate --output text --stack-name "${{ matrix.deployName }}-ghpublic-${NODE_ENV}-pr-${PR_NUMBER}"
# aws cloudformation wait stack-delete-complete --output text --stack-name "${{ matrix.deployName }}-ghpublic-${NODE_ENV}-pr-${PR_NUMBER}"

# Example:
# microapps-core-ghpublic-prod-pr-303-edge-role
# - name: Destroy Parent Edge to Origin Stack
# run: |
# aws cloudformation delete-stack --stack-name "${{ matrix.deployName }}-ghpublic-${NODE_ENV}-pr-${PR_NUMBER}-edge-role"
# aws cloudformation wait stack-delete-complete --no-paginate --output text --stack-name "${{ matrix.deployName }}-ghpublic-${NODE_ENV}-pr-${PR_NUMBER}-edge-role"
# aws cloudformation wait stack-delete-complete --output text --stack-name "${{ matrix.deployName }}-ghpublic-${NODE_ENV}-pr-${PR_NUMBER}-edge-role"
4 changes: 4 additions & 0 deletions .static-app-replace.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
// https://www.npmjs.com/package/replace-in-file
module.exports = {
files: 'packages/static-app/src/**/*',
};
6 changes: 3 additions & 3 deletions deploy.sh
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,13 @@ npx cdk deploy microapps-core --context @pwrdrvr/microapps:deployReleaseApp=true
RELEASE_APP_PACKAGE_VERSION=$(node -p -e "require('./node_modules/@pwrdrvr/microapps-app-release-cdk/package.json').version")

# Extract Deployer Lambda Name
DEPLOYER_LAMBDA_NAME="$(aws cloudformation list-exports --query "Exports[?Name==\`microapps-demo-deploy-${NODE_ENV}-deployer-func-name\`].Value" --no-paginate --output text)"
DEPLOYER_LAMBDA_NAME="$(aws cloudformation list-exports --query "Exports[?Name==\`microapps-demo-deploy-${NODE_ENV}-deployer-func-name\`].Value" --output text)"

# Extract Release App Lambda Name
RELEASE_APP_LAMBDA_NAME=$(aws cloudformation list-exports --query "Exports[?Name==\`microapps-demo-deploy-${NODE_ENV}-release-app-func-name\`].Value" --no-paginate --output text)
RELEASE_APP_LAMBDA_NAME=$(aws cloudformation list-exports --query "Exports[?Name==\`microapps-demo-deploy-${NODE_ENV}-release-app-func-name\`].Value" --output text)

# Extract Edge Domain Name
EDGE_DOMAIN=$(aws cloudformation list-exports --query "Exports[?Name==\`microapps-demo-deploy-${NODE_ENV}-edge-domain-name\`].Value" --no-paginate --output text)
EDGE_DOMAIN=$(aws cloudformation list-exports --query "Exports[?Name==\`microapps-demo-deploy-${NODE_ENV}-edge-domain-name\`].Value" --output text)

# Deploy the Release App
npx microapps-publish publish --app-name release --new-version ${RELEASE_APP_PACKAGE_VERSION} --deployer-lambda-name ${DEPLOYER_LAMBDA_NAME} --app-lambda-name ${RELEASE_APP_LAMBDA_NAME} --static-assets-path node_modules/@pwrdrvr/microapps-app-release-cdk/lib/static_files/release/${RELEASE_APP_PACKAGE_VERSION}/ --overwrite --no-cache
Expand Down
5 changes: 4 additions & 1 deletion packages/demo-app/static_files/file.html
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
<!DOCTYPE html>
<html>
<html lang="en">
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Demo App</title>
</head>

<body>
<div>`file.html`</div>
<div>Version: 0.0.0</div>
</body>
</html>
5 changes: 4 additions & 1 deletion packages/demo-app/static_files/index.html
Original file line number Diff line number Diff line change
@@ -1,11 +1,14 @@
<!DOCTYPE html>
<html>
<html lang="en">
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Demo App</title>
</head>

<body>
<div>This is a simple demo app</div>
<div>Version: 0.0.0</div>
<div>
<button
onclick="fetch(`serverIncrement?currValue=${document.getElementById('output').innerText}`).then((response) => response.json()).then((data) => {document.getElementById('output').innerText = data.newValue })"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1552,7 +1552,7 @@ describe('edge-to-origin - routing - without prefix', () => {
});
});

it('static app - request to [root]/notVersion should load app frame with defaultFile', async () => {
it('static app - request to [root]/notVersion should load app frame with notVersion suffix', async () => {
return jest.isolateModulesAsync(async () => {
const { Config } = await import('./config/config');

Expand Down Expand Up @@ -1624,7 +1624,7 @@ describe('edge-to-origin - routing - without prefix', () => {
expect(responseResponse).toHaveProperty('body');
expect(responseResponse.headers).not.toHaveProperty('location');
expect(responseResponse.body?.length).toBeGreaterThan(80);
expect(responseResponse.body).toContain('<iframe src="/3.2.1-beta.1/bat.html" seamless');
expect(responseResponse.body).toContain('<iframe src="/3.2.1-beta.1/notVersion" seamless');
});
});

Expand Down
4 changes: 2 additions & 2 deletions packages/microapps-edge-to-origin/src/index.route.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1631,7 +1631,7 @@ describe('edge-to-origin - routing - without prefix', () => {
expect(responseResponse.headers?.location[0].value).toBe('/bat/3.2.1-beta.3/bat.html');
});

it('static app - request to app/notVersion should load app frame with defaultFile', async () => {
it('static app - request to app/notVersion should load app frame with notVersion suffix', async () => {
const AppName = 'BatAppNotVersion';
const app = new Application({
AppName,
Expand Down Expand Up @@ -1690,7 +1690,7 @@ describe('edge-to-origin - routing - without prefix', () => {
expect(responseResponse.headers).not.toHaveProperty('location');
expect(responseResponse.body?.length).toBeGreaterThan(80);
expect(responseResponse.body).toContain(
`<iframe src="/${AppName}/3.2.1-beta.1/bat.html" seamless`,
`<iframe src="/${AppName}/3.2.1-beta.1/notVersion" seamless`,
);
});

Expand Down
Loading

0 comments on commit 10ee3d3

Please sign in to comment.