From 5443888bf6e5a209ec2a2cb018c28c3d655fc479 Mon Sep 17 00:00:00 2001 From: Vinci Rufus Date: Wed, 1 Jan 2020 14:40:10 +0000 Subject: [PATCH 1/7] copy only the necessary files during stage 2 in multi-stage. --- examples/with-docker/Dockerfile.multistage | 4 +++- examples/with-docker/package.json | 5 ++++- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/examples/with-docker/Dockerfile.multistage b/examples/with-docker/Dockerfile.multistage index 937a0c09d9a2882..c3b6d282d2addc8 100644 --- a/examples/with-docker/Dockerfile.multistage +++ b/examples/with-docker/Dockerfile.multistage @@ -9,6 +9,8 @@ RUN yarn build && yarn --production # And then copy over node_modules, etc from that stage to the smaller base image FROM mhart/alpine-node:base WORKDIR /app -COPY --from=builder /app . +COPY --from=builder /app/node_modules ./node_modules +COPY --from=builder /app/.next ./.next +COPY --from=builder /app/next.config.js ./next.config.js EXPOSE 3000 CMD ["node_modules/.bin/next", "start"] diff --git a/examples/with-docker/package.json b/examples/with-docker/package.json index 572d445107d3d0b..5c3b01b4be1c0ec 100644 --- a/examples/with-docker/package.json +++ b/examples/with-docker/package.json @@ -4,7 +4,10 @@ "scripts": { "dev": "next", "build": "next build", - "start": "next start" + "start": "next start", + "build-docker": "docker build -t next-app .", + "build-docker-multistage": "docker build -t next-app -f ./Dockerfile.multistage .", + "run-docker": "docker run --rm -it -p 3000:3000 -e 'API_URL=https://example.com' next-app" }, "dependencies": { "next": "latest", From c8dc6c95073c4c261ee6dbf14c07c8ab98ff7d36 Mon Sep 17 00:00:00 2001 From: Vinci Rufus Date: Wed, 1 Jan 2020 14:44:41 +0000 Subject: [PATCH 2/7] update readme --- examples/with-docker/README.md | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/examples/with-docker/README.md b/examples/with-docker/README.md index ae18ad304f9e3c3..727847a81f8a97f 100644 --- a/examples/with-docker/README.md +++ b/examples/with-docker/README.md @@ -30,7 +30,13 @@ docker build -t next-app . docker build -t next-app -f ./Dockerfile.multistage . ``` -Run it: +Alternatively you can add these commands as scripts to your package.json and simply run + +`yarn build-docker` +or +`yarn build-docker-multistage` + +Run the docker image: ```bash docker run --rm -it \ @@ -39,6 +45,8 @@ docker run --rm -it \ next-app ``` +or use `yarn build-docker-multistage` + Deploy it to the cloud with [now](https://zeit.co/now) ([download](https://zeit.co/download)) ```bash From e5468ab6b6069ec3aaa470664d549c69a8996c39 Mon Sep 17 00:00:00 2001 From: Vinci Rufus Date: Sat, 8 Feb 2020 21:10:58 +0000 Subject: [PATCH 3/7] adds compress:false to prevent the server from crashing while running http2 --- examples/with-http2/server.js | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/examples/with-http2/server.js b/examples/with-http2/server.js index ee872d61b1b0110..584904cd86aec03 100644 --- a/examples/with-http2/server.js +++ b/examples/with-http2/server.js @@ -6,7 +6,13 @@ const port = parseInt(process.env.PORT, 10) || 3000 const dev = process.env.NODE_ENV !== 'production' // Init the Next app: -const app = next({ dev }) +const app = next({ + dev, + conf: { + // this needs to be set false unitl to a bug in the compression npm module ets fixed. + compress: false, + }, +}) // Create the secure HTTPS server: // Don't forget to create the keys for your development From abfec0e70fd57e1deb832886b56b319640c7bd4c Mon Sep 17 00:00:00 2001 From: Vinci Rufus Date: Sat, 8 Feb 2020 22:36:27 +0000 Subject: [PATCH 4/7] moving the config to next.config --- examples/with-http2/next.config.js | 4 ++++ examples/with-http2/server.js | 8 +------- 2 files changed, 5 insertions(+), 7 deletions(-) create mode 100644 examples/with-http2/next.config.js diff --git a/examples/with-http2/next.config.js b/examples/with-http2/next.config.js new file mode 100644 index 000000000000000..9dcff279ec99cf6 --- /dev/null +++ b/examples/with-http2/next.config.js @@ -0,0 +1,4 @@ +module.exports = { + // this needs to be set false unitl to a bug in the compression npm module gets fixed. + compress: false, +} diff --git a/examples/with-http2/server.js b/examples/with-http2/server.js index 584904cd86aec03..ee872d61b1b0110 100644 --- a/examples/with-http2/server.js +++ b/examples/with-http2/server.js @@ -6,13 +6,7 @@ const port = parseInt(process.env.PORT, 10) || 3000 const dev = process.env.NODE_ENV !== 'production' // Init the Next app: -const app = next({ - dev, - conf: { - // this needs to be set false unitl to a bug in the compression npm module ets fixed. - compress: false, - }, -}) +const app = next({ dev }) // Create the secure HTTPS server: // Don't forget to create the keys for your development From a56e9f91206a2e6bad068c50e71383319174bdb7 Mon Sep 17 00:00:00 2001 From: Vinci Rufus Date: Sun, 9 Feb 2020 11:26:05 +0000 Subject: [PATCH 5/7] link to the issue --- examples/with-http2/next.config.js | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/examples/with-http2/next.config.js b/examples/with-http2/next.config.js index 9dcff279ec99cf6..74b0bb63d7f9b6a 100644 --- a/examples/with-http2/next.config.js +++ b/examples/with-http2/next.config.js @@ -1,4 +1,6 @@ module.exports = { - // this needs to be set false unitl to a bug in the compression npm module gets fixed. + /* this needs to be set false unitl to a bug in the compression npm module gets fixed. +reference: https://github.com/expressjs/compression/issues/122 + */ compress: false, } From d8bff8d9acc615115c4679093cc754837d21a56e Mon Sep 17 00:00:00 2001 From: Vinci Rufus Date: Sun, 9 Feb 2020 11:29:23 +0000 Subject: [PATCH 6/7] fix grammatical error --- examples/with-http2/next.config.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/examples/with-http2/next.config.js b/examples/with-http2/next.config.js index 74b0bb63d7f9b6a..cc981d8b23614bd 100644 --- a/examples/with-http2/next.config.js +++ b/examples/with-http2/next.config.js @@ -1,5 +1,5 @@ module.exports = { - /* this needs to be set false unitl to a bug in the compression npm module gets fixed. + /* this needs to be set to false unitl a bug in the compression npm module gets fixed. reference: https://github.com/expressjs/compression/issues/122 */ compress: false, From 110cc1ddb99e401b803cb1c3583de1a773e9f2ba Mon Sep 17 00:00:00 2001 From: Vinci Rufus Date: Sun, 9 Feb 2020 12:36:11 +0000 Subject: [PATCH 7/7] Update examples/with-http2/next.config.js Co-Authored-By: Jan Potoms <2109932+Janpot@users.noreply.github.com> --- examples/with-http2/next.config.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/examples/with-http2/next.config.js b/examples/with-http2/next.config.js index cc981d8b23614bd..a50ddf389e478b1 100644 --- a/examples/with-http2/next.config.js +++ b/examples/with-http2/next.config.js @@ -1,5 +1,5 @@ module.exports = { - /* this needs to be set to false unitl a bug in the compression npm module gets fixed. + /* this needs to be set to false until a bug in the compression npm module gets fixed. reference: https://github.com/expressjs/compression/issues/122 */ compress: false,