You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: README.md
+38-12Lines changed: 38 additions & 12 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -249,13 +249,9 @@ Update `nodejs/Dockerfile`:
249
249
```Dockerfile
250
250
FROM public.ecr.aws/lambda/nodejs:24
251
251
252
-
COPY ./package*.json ${LAMBDA_TASK_ROOT}
253
-
254
-
RUN npm ci
255
-
256
252
COPY ./ ${LAMBDA_TASK_ROOT}
257
253
258
-
RUN npm run build
254
+
RUN npm ci && npm run build
259
255
260
256
CMD [ "build/index.handler" ]
261
257
```
@@ -540,7 +536,35 @@ docker compose up --abort-on-container-exit --build
540
536
541
537
## 5. Optimisation
542
538
543
-
**Goal:** Prepare for production with multi-stage builds.
539
+
**Goal:** Prepare for production with improved caching and multi-stage builds.
540
+
541
+
### Improved caching
542
+
543
+
Replace `nodejs/Dockerfile` with this cached optimised version:
544
+
545
+
```Dockerfile
546
+
FROM public.ecr.aws/lambda/nodejs:24
547
+
548
+
COPY ./package*.json ${LAMBDA_TASK_ROOT}
549
+
550
+
RUN npm ci
551
+
552
+
COPY ./ ${LAMBDA_TASK_ROOT}
553
+
554
+
RUN npm run build
555
+
556
+
CMD [ "build/index.handler" ]
557
+
```
558
+
559
+
Run the following command:
560
+
561
+
```shell
562
+
docker compose up --abort-on-container-exit --build
563
+
```
564
+
565
+
> [!TIP]
566
+
> In this iteration, as `npm ci` and `npm run build` are two different layers, when one changes it doesn't impact the other.
567
+
> For example, if we update our code without updating any packages, the `npm ci` can still use it's cached version where as the `npm run build` will get rebuilt.
0 commit comments