Skip to content

Commit

Permalink
Update release app to iframe-less (#276)
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
huntharo authored Dec 31, 2022
1 parent 5723b77 commit fb9ea86
Show file tree
Hide file tree
Showing 6 changed files with 34 additions and 42 deletions.
38 changes: 21 additions & 17 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -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:
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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} \
Expand Down Expand Up @@ -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 \
Expand All @@ -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} \
Expand Down Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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}
Expand Down
2 changes: 1 addition & 1 deletion .nextjs-demo-replace.config.js
Original file line number Diff line number Diff line change
@@ -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/**/*',
};
2 changes: 1 addition & 1 deletion .release-replace.config.js
Original file line number Diff line number Diff line change
@@ -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/**/*',
};
14 changes: 1 addition & 13 deletions packages/cdk/lib/MicroApps.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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),
});

Expand Down Expand Up @@ -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', {
Expand All @@ -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', {
Expand Down
4 changes: 2 additions & 2 deletions packages/cdk/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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": {
Expand Down
16 changes: 8 additions & 8 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down

0 comments on commit fb9ea86

Please sign in to comment.