Skip to content

Commit 9f0a035

Browse files
authored
Standalone server bundle (#34)
* Standalone server bundle * Build fix * Cache key fix * Path fix * Path fix * Build fixes and debugging * More debugging * Fix cache key * More fixes * Deploy fixes * Skip runtime module cache for now * More cache skip * Path fixes * Path fix for statics * More fixes * Fix static folder * Come on * Fix
1 parent 67106a7 commit 9f0a035

File tree

15 files changed

+3140
-877
lines changed

15 files changed

+3140
-877
lines changed

.github/workflows/ci.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ jobs:
7878
node_modules
7979
packages/**/node_modules
8080
!node_modules/.cache
81-
key: node-modules-${{ hashFiles('package.json', 'package-lock.json') }}
81+
key: node-modules-${{ hashFiles('package.json', 'package-lock.json', 'patches/*') }}
8282

8383
- name: Install Dependencies
8484
if: steps.cache-node-modules.outputs.cache-hit != 'true'
@@ -140,7 +140,7 @@ jobs:
140140
-n ${{ needs.version.outputs.packageVersion }} \
141141
-d ${DEPLOYER_LAMBDA_NAME} \
142142
-l microapps-app-${APP_NAME}-${ENV}${{ needs.version.outputs.prSuffix }} \
143-
-s packages/cdk-construct/lib/${APP_CONSTRUCT_FOLDER_NAME}/.static_files \
143+
-s packages/cdk-construct/lib/${APP_CONSTRUCT_FOLDER_NAME}/static_files \
144144
--overwrite --noCache
145145
146146
- name: App URL

.github/workflows/r_build-app.yml

Lines changed: 41 additions & 68 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
21
name: Build App
32

43
on:
@@ -44,33 +43,19 @@ jobs:
4443
path: |
4544
node_modules
4645
packages/**/node_modules
47-
!node_modules/.cache
48-
key: node-modules-${{ hashFiles('package.json', 'package-lock.json') }}
46+
key: node-modules-${{ hashFiles('package.json', 'package-lock.json', 'patches/*') }}
4947

50-
- name: Install Dependencies
48+
- name: Optionally Install Node Modules
5149
if: steps.cache-node-modules.outputs.cache-hit != 'true'
5250
run: npm ci
5351

54-
# - name: Link to node_modules - App
55-
# if: steps.cache-node-modules.outputs.cache-hit != 'true'
56-
# working-directory: packages/app/node_modules/.bin
57-
# run: |
58-
# ln -s ../../../../node_modules/.bin/next
59-
60-
- name: Install Node-Prune
61-
run: npm run install:node-prune
62-
63-
- name: Restore Next.js Build Cache
64-
uses: actions/cache@v3
65-
with:
66-
# See here for caching with `yarn` https://github.com/actions/cache/blob/main/examples.md#node---yarn or you can leverage caching with actions/setup-node https://github.com/actions/setup-node
67-
path: |
68-
${{ github.workspace }}/packages/app/.next/cache
69-
# Generate a new cache whenever packages or source files change.
70-
key: ${{ runner.os }}-nextjs-${{ hashFiles('**/package-lock.json') }}-${{ hashFiles('**.[jt]s', '**.[jt]sx') }}
71-
# If source files changed but packages didn't, rebuild from a prior cache.
72-
restore-keys: |
73-
${{ runner.os }}-nextjs-${{ hashFiles('**/package-lock.json') }}-
52+
# - name: Cache App Build Node Modules
53+
# id: cache-node-modules-app
54+
# uses: actions/cache@v3
55+
# with:
56+
# path: |
57+
# packages/app/node_modules
58+
# key: node-modules-app-${{ hashFiles('package.json', 'packages/app/package-lock.json', 'packages/app/patches/*') }}
7459

7560
# Fixes errors due to JSII tsconfig.json not ignoring libs
7661
# node_modules/flatpickr/dist/types/instance.d.ts(37,21): error TS2304: Cannot find name 'Node'.
@@ -104,60 +89,48 @@ jobs:
10489
run: |
10590
npx -w ${APP_PACKAGE_NAME} microapps-publish nextjs-version -n ${{ inputs.packageVersion }}
10691
107-
- name: Build Next.js App
92+
# outputTracing can't follow modules in npm workspaces
93+
# npm will not install modules in a workspace folder if there
94+
# is a package.json in the parent folder, so move it out of the way
95+
- name: Install Runtime Deps for outputTracing
96+
# if: steps.cache-node-modules-app.outputs.cache-hit != 'true'
97+
working-directory: packages/app/
10898
run: |
109-
npm run build:next
99+
mv ../../package.json ../../package.json.hide
100+
du -sh node_modules
101+
npm ci
102+
du -sh node_modules
103+
mv ../../package.json.hide ../../package.json
110104
111-
- name: Cache Runtime Node Modules
112-
id: cache-runtime-node-modules
105+
- name: Restore Next.js Build Cache
113106
uses: actions/cache@v3
114107
with:
115108
path: |
116-
packages/app-entry/runtime-deps/node_modules
117-
!packages/app-entry/runtime-deps/node_modules/.cache
118-
key: node-modules-${{ hashFiles('packages/app-entry/runtime-deps/package.json', 'packages/app-entry/runtime-deps/package-lock.json') }}
119-
120-
- name: Install Runtime Deps for Runtime
121-
if: steps.cache-runtime-node-modules.outputs.cache-hit != 'true'
122-
working-directory: packages/app-entry/runtime-deps/
123-
run: |
124-
npm ci --omit=dev
109+
${{ github.workspace }}/packages/app/.next/cache
110+
# Generate a new cache whenever packages or patches change.
111+
key: nextjs-${{ runner.os }}-${{ hashFiles('packages/app/package-lock.json', 'packages/app/patches/*', 'packages/app/next.config.js') }} }}
125112

126-
- name: Remove Extraneous Files from Runtime Deps
127-
working-directory: packages/app-entry/runtime-deps/
113+
- name: Build Next.js App
114+
working-directory: packages/app/
128115
run: |
129-
node-prune
130-
# Remove the SWC files from the runtime deps (these are dev time only)
131-
rm -rf node_modules/@next/swc-*
116+
npm run build
117+
du -sh .next/*
118+
du -sh .next/standalone/*
119+
du -sh .next/standalone/.next/*
132120
133121
- name: Combine Build Outputs
134122
run: |
135-
mkdir -p ./packages/cdk-construct/lib/${{ inputs.APP_CONSTRUCT_FOLDER_NAME }}
136-
mkdir -p ./packages/cdk-construct/lib/${{ inputs.APP_CONSTRUCT_FOLDER_NAME }}/.static_files/
137-
cp -R ./packages/app/public/* ./packages/cdk-construct/lib/${{ inputs.APP_CONSTRUCT_FOLDER_NAME }}/.static_files/
138-
cp -R ./packages/app/.next ./packages/cdk-construct/lib/${{ inputs.APP_CONSTRUCT_FOLDER_NAME }}
139-
rm -rf ./packages/cdk-construct/lib/${{ inputs.APP_CONSTRUCT_FOLDER_NAME }}/.next/cache
140-
cp -R ./packages/app/next.config.js ./packages/cdk-construct/lib/${{ inputs.APP_CONSTRUCT_FOLDER_NAME }}
141-
cp -R ./packages/app-entry/runtime-deps/node_modules ./packages/cdk-construct/lib/${{ inputs.APP_CONSTRUCT_FOLDER_NAME }}
142-
cp -R ./packages/app-entry/run.sh ./packages/cdk-construct/lib/${{ inputs.APP_CONSTRUCT_FOLDER_NAME }}
143-
cp -R ./packages/app-entry/server.js ./packages/cdk-construct/lib/${{ inputs.APP_CONSTRUCT_FOLDER_NAME }}
144-
145-
# Prevent the static files from getting pulled into the Lambda
146-
- name: Remove Static Files from App Build
147-
working-directory: packages/cdk-construct/lib/
148-
run: |
149-
mkdir -p ${{ inputs.APP_CONSTRUCT_FOLDER_NAME }}/.static_files/_next/
150-
mv ${{ inputs.APP_CONSTRUCT_FOLDER_NAME }}/.next/static ${{ inputs.APP_CONSTRUCT_FOLDER_NAME }}/.static_files/_next
151-
152-
- name: Build the NPM tarball for Examination
153-
working-directory: packages/cdk-construct/
154-
run: |
155-
npm pack
156-
- name: Upload NPM tarball
157-
uses: actions/upload-artifact@v3
158-
with:
159-
name: cdk_npm_package
160-
path: packages/cdk-construct/pwrdrvr-microapps-app-${{ env.APP_NAME }}-cdk-${{ inputs.packageVersion }}.tgz
123+
mkdir -p ./packages/cdk-construct/lib/${{ inputs.APP_CONSTRUCT_FOLDER_NAME }}/static_files/_next/static
124+
mkdir -p ./packages/cdk-construct/lib/${{ inputs.APP_CONSTRUCT_FOLDER_NAME }}/server/.next
125+
cp -R ./packages/app/.next/static/* ./packages/cdk-construct/lib/${{ inputs.APP_CONSTRUCT_FOLDER_NAME }}/static_files/_next/static/
126+
cp -R ./packages/app/public/* ./packages/cdk-construct/lib/${{ inputs.APP_CONSTRUCT_FOLDER_NAME }}/static_files/
127+
cp -R ./packages/app/.next/standalone/* ./packages/cdk-construct/lib/${{ inputs.APP_CONSTRUCT_FOLDER_NAME }}/server/
128+
cp -R ./packages/app/.next/standalone/.next/* ./packages/cdk-construct/lib/${{ inputs.APP_CONSTRUCT_FOLDER_NAME }}/server/.next/
129+
cp -R ./packages/app/run.sh ./packages/cdk-construct/lib/${{ inputs.APP_CONSTRUCT_FOLDER_NAME }}/server/
130+
du -sh ./packages/cdk-construct/lib/${{ inputs.APP_CONSTRUCT_FOLDER_NAME }}/*
131+
du -sh ./packages/cdk-construct/lib/${{ inputs.APP_CONSTRUCT_FOLDER_NAME }}/server/*
132+
du -sh ./packages/cdk-construct/lib/${{ inputs.APP_CONSTRUCT_FOLDER_NAME }}/server/.next/*
133+
du -sh ./packages/cdk-construct/lib/${{ inputs.APP_CONSTRUCT_FOLDER_NAME }}/static_files/*
161134
162135
# Upload Artifact
163136
- name: Zip Package

.github/workflows/r_version.yml

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -52,10 +52,9 @@ jobs:
5252
path: |
5353
node_modules
5454
packages/**/node_modules
55-
!node_modules/.cache
56-
key: node-modules-${{ hashFiles('package.json', 'package-lock.json') }}
55+
key: node-modules-${{ hashFiles('package.json', 'package-lock.json', 'patches/*') }}
5756

58-
- name: Install Dependencies
57+
- name: Optionally Install Node Modules
5958
if: steps.cache-node-modules.outputs.cache-hit != 'true'
6059
run: npm ci
6160

0 commit comments

Comments
 (0)