From fb9ea86c61aab215207af680d774c7bf0ec4f0e3 Mon Sep 17 00:00:00 2001 From: Harold Hunt Date: Sat, 31 Dec 2022 15:59:51 -0500 Subject: [PATCH] Update release app to iframe-less (#276) * Update release app to iframe-less * Remove unused props * Fix static resource path * Fixup deploy commands * Fixup file replace paths * Fix more app paths * Fix one more path * Skip tests on nextjs-demo prefix deploy * Move replace up a directory on release app * Fix table removal policy, remove sharp layer * Rename workflow * Skip node_modules in rewrite * Replace build_manifest.js rewrites * More rewrites * Add fix for square brackets in release app * Unskip nextjs-demo prefix tests --- .github/workflows/ci.yml | 38 +++++++++++++++++++--------------- .nextjs-demo-replace.config.js | 2 +- .release-replace.config.js | 2 +- packages/cdk/lib/MicroApps.ts | 14 +------------ packages/cdk/package.json | 4 ++-- yarn.lock | 16 +++++++------- 6 files changed, 34 insertions(+), 42 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index b9c12009..d113676a 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -1,7 +1,7 @@ # Workflow references: # https://docs.github.com/en/actions/reference/workflow-syntax-for-github-actions # https://help.github.com/actions/language-and-framework-guides/using-nodejs-with-github-actions -name: Build / Deploy - CI +name: CI on: push: @@ -114,8 +114,10 @@ jobs: run: | if [ "${{ matrix.deployName }}" == "microapps-basic-prefix" ]; then echo 'PREFIX=/prefix' >> $GITHUB_ENV + echo 'PREFIX_U=/u002Fprefix' >> $GITHUB_ENV else echo 'PREFIX=' >> $GITHUB_ENV + echo 'PREFIX_U=' >> $GITHUB_ENV fi - name: Use Node.js 16 @@ -149,14 +151,14 @@ jobs: run: | if [ -n "${PREFIX}" ] ; then npx replace-in-file "/\/${NEXTJS_DEMO_APP_NAME}/g" ${PREFIX}/${NEXTJS_DEMO_APP_NAME} --configFile=.nextjs-demo-replace.config.js --isRegex - npx replace-in-file "/\/${NEXTJS_DEMO_APP_NAME}\/${{ needs.build.outputs.nextjsDemoAppPackageVersion }}/g" /${NEXTJS_DEMO_APP_NAME}/${{ needs.build.outputs.nextjsDemoAppPackageVersion }} --configFile=.nextjs-demo-replace.config.js --isRegex + npx replace-in-file "/\/u002F${NEXTJS_DEMO_APP_NAME}/g" ${PREFIX_U}/u002F${NEXTJS_DEMO_APP_NAME} --configFile=.nextjs-demo-replace.config.js --isRegex fi - name: Stitch Prefix into Release App run: | if [ -n "${PREFIX}" ] ; then npx replace-in-file "/\/${RELEASE_APP_NAME}/g" ${PREFIX}/${RELEASE_APP_NAME} --configFile=.release-replace.config.js --isRegex - npx replace-in-file "/\/${RELEASE_APP_NAME}\/${{ needs.build.outputs.releaseAppPackageVersion }}/g" /${RELEASE_APP_NAME}/${{ needs.build.outputs.releaseAppPackageVersion }} --configFile=.release-replace.config.js --isRegex + npx replace-in-file "/\/u002F${RELEASE_APP_NAME}/g" ${PREFIX_U}/u002F${RELEASE_APP_NAME} --configFile=.release-replace.config.js --isRegex fi - name: Synth CDK Stack @@ -203,7 +205,8 @@ jobs: - name: Publish Demo App to MicroApps run: | - npx microapps-publish publish -a ${DEMO_APP_NAME} \ + npx microapps-publish publish \ + -a ${DEMO_APP_NAME} \ -t lambda-url \ --startup-type direct \ -n ${PACKAGE_VERSION} \ @@ -235,7 +238,8 @@ jobs: - name: Publish Demo App to MicroApps - To Delete run: | - npx microapps-publish publish -a ${DEMO_APP_NAME} \ + npx microapps-publish publish \ + -a ${DEMO_APP_NAME} \ -t lambda-url \ --startup-type direct \ -n 0.0.0-test.1 \ @@ -252,7 +256,8 @@ jobs: - name: Publish Demo App to MicroApps - Root App run: | - npx microapps-publish publish -a '[root]' \ + npx microapps-publish publish \ + -a '[root]' \ -t lambda-url \ --startup-type direct \ -n ${PACKAGE_VERSION} \ @@ -286,11 +291,12 @@ jobs: run: | npx microapps-publish publish \ -t lambda-url \ + --startup-type direct \ -a ${NEXTJS_DEMO_APP_NAME} \ -n ${{ needs.build.outputs.nextjsDemoAppPackageVersion }} \ -d ${DEPLOYER_LAMBDA_NAME} \ -l ${NEXTJS_DEMO_APP_LAMBDA_NAME} \ - -s packages/cdk/node_modules/@pwrdrvr/microapps-app-nextjs-demo-cdk/lib/.static_files/${NEXTJS_DEMO_APP_NAME}/${{ needs.build.outputs.nextjsDemoAppPackageVersion }}/ \ + -s packages/cdk/node_modules/@pwrdrvr/microapps-app-nextjs-demo-cdk/lib/microapps-app-nextjs-demo/.static_files/ \ --overwrite --noCache - name: Nextjs Demo App URL @@ -305,25 +311,23 @@ jobs: - name: Test Nextjs Demo App run: | - echo Testing App Frame Loading - curl -H"accept: text/html" --fail https://${EDGE_DOMAIN}${PREFIX}/${NEXTJS_DEMO_APP_NAME}/ + echo Testing App Page Loading + curl -H"accept: text/html" --fail https://${EDGE_DOMAIN}${PREFIX}/${NEXTJS_DEMO_APP_NAME} echo Testing App HTML Loading - curl -H"accept: text/html" --fail https://${EDGE_DOMAIN}${PREFIX}/${NEXTJS_DEMO_APP_NAME}/${{ needs.build.outputs.nextjsDemoAppPackageVersion }} + curl -H"accept: text/html" --fail https://${EDGE_DOMAIN}${PREFIX}/${NEXTJS_DEMO_APP_NAME}?appver=${{ needs.build.outputs.nextjsDemoAppPackageVersion }} echo Testing Post Page Loading - curl -H"accept: text/html" --fail https://${EDGE_DOMAIN}${PREFIX}/${NEXTJS_DEMO_APP_NAME}/${{ needs.build.outputs.nextjsDemoAppPackageVersion }}/posts/pre-rendering - echo Testing Image Rendering - curl -H"accept: image/jpg" --fail -o /dev/null https://${EDGE_DOMAIN}${PREFIX}/${NEXTJS_DEMO_APP_NAME}/${{ needs.build.outputs.nextjsDemoAppPackageVersion }}/_next/image?url=%2Fimages%2Fprofile.jpg&w=384&q=75 + curl -H"accept: text/html" --fail https://${EDGE_DOMAIN}${PREFIX}/${NEXTJS_DEMO_APP_NAME}/posts/pre-rendering?appver=${{ needs.build.outputs.nextjsDemoAppPackageVersion }} - name: Publish Release App to MicroApps run: | npx microapps-publish publish \ -t lambda-url \ - --startup-type iframe \ + --startup-type direct \ -a ${RELEASE_APP_NAME} \ -n ${{ needs.build.outputs.releaseAppPackageVersion }} \ -d ${DEPLOYER_LAMBDA_NAME} \ -l ${RELEASE_APP_LAMBDA_NAME} \ - -s packages/cdk/node_modules/@pwrdrvr/microapps-app-release-cdk/lib/.static_files/${RELEASE_APP_NAME}/${{ needs.build.outputs.releaseAppPackageVersion }}/ \ + -s packages/cdk/node_modules/@pwrdrvr/microapps-app-release-cdk/lib/microapps-app-release/.static_files/ \ --overwrite --noCache - name: Release App URL @@ -339,9 +343,9 @@ jobs: - name: Test Release App run: | echo Testing App Frame Loading - curl -H"accept: text/html" --fail https://${EDGE_DOMAIN}${PREFIX}/${RELEASE_APP_NAME}/ + curl -H"accept: text/html" --fail https://${EDGE_DOMAIN}${PREFIX}/${RELEASE_APP_NAME} echo Testing App HTML Loading - curl -H"accept: text/html" --fail https://${EDGE_DOMAIN}${PREFIX}/${RELEASE_APP_NAME}/${{ needs.build.outputs.releaseAppPackageVersion }} + curl -H"accept: text/html" --fail https://${EDGE_DOMAIN}${PREFIX}/${RELEASE_APP_NAME}?appver=${{ needs.build.outputs.releaseAppPackageVersion }} echo Testing App Method Invocation curl -H"accept: application/json" --fail https://${EDGE_DOMAIN}${PREFIX}/${RELEASE_APP_NAME}/${{ needs.build.outputs.releaseAppPackageVersion }}/api/refresh/${DEMO_APP_NAME} diff --git a/.nextjs-demo-replace.config.js b/.nextjs-demo-replace.config.js index 10b63d41..5dfd1ff6 100644 --- a/.nextjs-demo-replace.config.js +++ b/.nextjs-demo-replace.config.js @@ -1,4 +1,4 @@ // https://www.npmjs.com/package/replace-in-file module.exports = { - files: 'packages/cdk/node_modules/@pwrdrvr/microapps-app-nextjs-demo-cdk/lib/.serverless_nextjs/**/*,packages/cdk/node_modules/@pwrdrvr/microapps-app-nextjs-demo-cdk/lib/.static_files/**/*', + files: 'packages/cdk/node_modules/@pwrdrvr/microapps-app-nextjs-demo-cdk/lib/microapps-app-nextjs-demo/.next/**/*,packages/cdk/node_modules/@pwrdrvr/microapps-app-nextjs-demo-cdk/lib/microapps-app-nextjs-demo/next.config.js,packages/cdk/node_modules/@pwrdrvr/microapps-app-nextjs-demo-cdk/lib/microapps-app-nextjs-demo/.static_files/**/*', }; \ No newline at end of file diff --git a/.release-replace.config.js b/.release-replace.config.js index 764ccac7..c608e416 100644 --- a/.release-replace.config.js +++ b/.release-replace.config.js @@ -1,4 +1,4 @@ // https://www.npmjs.com/package/replace-in-file module.exports = { - files: 'packages/cdk/node_modules/@pwrdrvr/microapps-app-release-cdk/lib/.serverless_nextjs/**/*,packages/cdk/node_modules/@pwrdrvr/microapps-app-release-cdk/lib/.static_files/**/*', + files: 'packages/cdk/node_modules/@pwrdrvr/microapps-app-release-cdk/lib/microapps-app-release/.next/**/*,packages/cdk/node_modules/@pwrdrvr/microapps-app-release-cdk/lib/microapps-app-release/next.config.js,packages/cdk/node_modules/@pwrdrvr/microapps-app-release-cdk/lib/microapps-app-release/.static_files/**/*', }; \ No newline at end of file diff --git a/packages/cdk/lib/MicroApps.ts b/packages/cdk/lib/MicroApps.ts index af730d04..1022f0aa 100644 --- a/packages/cdk/lib/MicroApps.ts +++ b/packages/cdk/lib/MicroApps.ts @@ -227,6 +227,7 @@ export class MicroAppsStack extends Stack { // the 2nd generation routing that needs the table name // in the edge lambda function const table = new MicroAppsTable(this, 'microapps-table', { + removalPolicy, ...(tableName ? { assetNameRoot: tableName } : optionalAssetNameOpts), }); @@ -256,23 +257,12 @@ export class MicroAppsStack extends Stack { }); } - let sharpLayer: lambda.ILayerVersion | undefined = undefined; - if (deployReleaseApp || deployNextjsDemoApp) { - sharpLayer = lambda.LayerVersion.fromLayerVersionArn( - this, - 'sharp-lambda-layer', - `arn:aws:lambda:${Aws.REGION}:${Aws.ACCOUNT_ID}:layer:sharp-heic:1`, - ); - } - if (deployReleaseApp) { const app = new MicroAppsAppRelease(this, 'release-app', { functionName: assetNameRoot ? `${assetNameRoot}-app-release${assetNameSuffix}` : undefined, table: microapps.svcs.table, - staticAssetsS3Bucket: microapps.s3.bucketApps, nodeEnv, removalPolicy, - sharpLayer, }); new CfnOutput(this, 'release-app-func-name', { @@ -286,10 +276,8 @@ export class MicroAppsStack extends Stack { functionName: assetNameRoot ? `${assetNameRoot}-app-nextjs-demo${assetNameSuffix}` : undefined, - staticAssetsS3Bucket: microapps.s3.bucketApps, nodeEnv, removalPolicy, - sharpLayer, }); new CfnOutput(this, 'nextjs-demo-app-func-name', { diff --git a/packages/cdk/package.json b/packages/cdk/package.json index 32098469..8061389c 100644 --- a/packages/cdk/package.json +++ b/packages/cdk/package.json @@ -14,8 +14,8 @@ "cdk": "cdk" }, "dependencies": { - "@pwrdrvr/microapps-app-nextjs-demo-cdk": "^0.2.1", - "@pwrdrvr/microapps-app-release-cdk": "^0.2.2", + "@pwrdrvr/microapps-app-nextjs-demo-cdk": "^0.3.1", + "@pwrdrvr/microapps-app-release-cdk": "^0.4.2", "source-map-support": "^0.5.16" }, "devDependencies": { diff --git a/yarn.lock b/yarn.lock index 174c039c..440a5fe6 100644 --- a/yarn.lock +++ b/yarn.lock @@ -2328,18 +2328,18 @@ resolved "https://registry.yarnpkg.com/@oozcitak/util/-/util-8.3.8.tgz" integrity sha512-T8TbSnGsxo6TDBJx/Sgv/BlVJL3tshxZP7Aq5R1mSnM5OcHY2dQaxLMu2+E8u3gN0MLOzdjurqN4ZRVuzQycOQ== -"@pwrdrvr/microapps-app-nextjs-demo-cdk@^0.2.1": - version "0.2.1" - resolved "https://registry.yarnpkg.com/@pwrdrvr/microapps-app-nextjs-demo-cdk/-/microapps-app-nextjs-demo-cdk-0.2.1.tgz" - integrity sha512-YAIhb/430pvvi0NlJSqAzE7tNSVtweSMRnBU4HY+8IwWJnwO8b5HVkfgUhb6aT6B6tx7FUEPY1+tDQoanCOAqg== +"@pwrdrvr/microapps-app-nextjs-demo-cdk@^0.3.1": + version "0.3.1" + resolved "https://registry.yarnpkg.com/@pwrdrvr/microapps-app-nextjs-demo-cdk/-/microapps-app-nextjs-demo-cdk-0.3.1.tgz#f4928ddc143282a6b0cf990d5b2def917b3c30cb" + integrity sha512-JutFBa1wj5TaA2C94IRkVGAUbsRfrOHxr+nuH18wTY2O9ulG2+UstTeXMN5cTZKJvrvHwQSXD2KSr/V8064Awg== dependencies: aws-cdk-lib "^2.8.0" constructs "^10.0.5" -"@pwrdrvr/microapps-app-release-cdk@^0.2.2": - version "0.2.4" - resolved "https://registry.yarnpkg.com/@pwrdrvr/microapps-app-release-cdk/-/microapps-app-release-cdk-0.2.4.tgz" - integrity sha512-DS/9IP92HO34lfSmP/ZzxuU6HWjUbj00tmEn7opO5n8AO61+7oj+PwzXwjtE2lOJZoYc7v++Yo6IYPq0UoyDGg== +"@pwrdrvr/microapps-app-release-cdk@^0.4.2": + version "0.4.2" + resolved "https://registry.yarnpkg.com/@pwrdrvr/microapps-app-release-cdk/-/microapps-app-release-cdk-0.4.2.tgz#59e48d99928fbb073a7d0408bba0a8fc45a81f2d" + integrity sha512-7Fx/j/FsyGwo9PYVKvvYtFP3y8WSEcR4bz8ntAqOHki6jm2bSz5fgerfu5fjWSt1+hpOqIQ3tihIPo+NvxXkBw== dependencies: aws-cdk-lib "^2.8.0" constructs "^10.0.5"