Skip to content
This repository was archived by the owner on Mar 21, 2024. It is now read-only.

Commit 81da099

Browse files
authored
📝 Add deprecation and update docs (#20)
1 parent 88541be commit 81da099

File tree

1 file changed

+66
-59
lines changed

1 file changed

+66
-59
lines changed

README.md

Lines changed: 66 additions & 59 deletions
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,16 @@
1-
[![Build Status](https://travis-ci.org/tiangolo/node-frontend.svg?branch=master)](https://travis-ci.org/tiangolo/node-frontend)
1+
# 🚨 DEPRECATION WARNING 🚨
22

3-
## Supported tags and respective `Dockerfile` links
3+
This was a Docker image. I'm currently not using nor recommending the Docker image, it is no longer supported.
44

5-
* [`10`, `latest` _(Dockerfile)_](https://github.com/tiangolo/node-frontend/blob/master/Dockerfile)
5+
You are better off building a Docker image from scratch, see below how. 🤓
66

7-
# Node.js frontend development with Chrome Headless tests
7+
There are more details about the deprecation at the end.
88

9-
This Docker image simplifies the process of creating a full Node.js environment for frontend development with multistage building.
10-
11-
It includes all the dependencies for Puppeteer, so you can just `npm install puppeteer` and it should work.
12-
13-
It also includes a default Nginx configuration for your frontend application, so in multi-stage Docker builds you can just copy it to an Ngnix "stage" and have an always freshly compiled production ready frontend Docker image for deployment.
14-
15-
It is derivated from this article I wrote:
16-
17-
> Angular in Docker with Nginx, supporting configurations / environments, built with multi-stage Docker builds and testing with Chrome Headless
18-
19-
[in Medium](https://medium.com/@tiangolo/angular-in-docker-with-nginx-supporting-environments-built-with-multi-stage-docker-builds-bb9f1724e984), and [in GitHub](https://github.com/tiangolo/medium-posts/tree/master/angular-in-docker)
20-
21-
## How to use
9+
## Build a Frontend Docker Image
2210

2311
### Previous steps
2412

25-
* Create your frontend Node.js based code (Angular, React, Vue.js).
13+
* Create your frontend Node.js based code (React, etc).
2614

2715
* Create a file `.dockerignore` (similar to `.gitignore`) and include in it:
2816

@@ -32,19 +20,19 @@ node_modules
3220

3321
...to avoid copying your `node_modules` to Docker, making things unnecessarily slower.
3422

35-
* If you want to integrate testing as part of your frontend build inside your Docker image building process (using Chrome Headless via Puppeteer), install Puppeteer locally, so that you can test it locally too and to have it in your development dependencies in your `package.json`:
23+
* If you want to integrate testing as part of your frontend build inside your Docker image building process, install any dependencies you might need, for example Playwright, so that you can test it locally too and to have it in your development dependencies in your `package.json`:
3624

3725
```bash
38-
npm install --save-dev puppeteer
26+
npm init playwright@latest
3927
```
4028

4129
### Dockerfile
4230

43-
* Create a file `Dockerfile` based on this image and name the stage `build-stage`, for building:
31+
* Create a file `Dockerfile` for building and name the stage `build-stage`:
4432

4533
```Dockerfile
4634
# Stage 0, "build-stage", based on Node.js, to build and compile the frontend
47-
FROM tiangolo/node-frontend:10 as build-stage
35+
FROM node:latest as build-stage
4836

4937
...
5038

@@ -62,7 +50,7 @@ COPY package*.json /app/
6250
...
6351
```
6452

65-
...just the `package*.json` files to install all the dependencies once and let Docker use the cache for the next builds. Instead of installing everything after every change in your source code.
53+
...copy just the `package*.json` files to install all the dependencies once and let Docker use the cache for the next builds. By doing this before copying the whole app code, Docker will be able to use the cache and you won't have to wait for Docker to install with `npm install` every time you change the code.
6654

6755
* Install `npm` packages inside your `Dockerfile`:
6856

@@ -74,8 +62,7 @@ RUN npm install
7462
...
7563
```
7664

77-
* Copy your source code, it can be TypeScript files, `.vue` or React with JSX, it will be compiled inside Docker:
78-
65+
* Copy your source code to the Docker image:
7966

8067
```Dockerfile
8168
...
@@ -85,28 +72,28 @@ COPY ./ /app/
8572
...
8673
```
8774

88-
* If you have integrated testing with Chrome Headless using Puppeteer, this image comes with all the dependencies for Puppeteer, so, after installing your dependencies (including `puppeteer` itself), you can just run it. E.g.:
75+
* If you need to pass build arguments, create a default `ARG` to be used at build time:
8976

9077
```Dockerfile
9178
...
9279

93-
RUN npm run test -- --browsers ChromeHeadlessNoSandbox --watch=false
80+
ARG VITE_API_URL=${VITE_API_URL}
9481

9582
...
9683
```
9784

98-
...if your tests didn't pass, they will throw an error and your build will stop. So, you will never ship a "broken" frontend Docker image to production.
99-
100-
* If you need to pass buildtime arguments, for example in Angular, for `--configuration`s, create a default `ARG` to be used at build time:
85+
* If you have integrated testing, you can run your tests now:
10186

10287
```Dockerfile
10388
...
10489

105-
ARG configuration=production
90+
RUN npm run test
10691

10792
...
10893
```
10994

95+
...if your tests didn't pass, they will throw an error and your build will stop. So, you will never ship a "broken" frontend Docker image to production.
96+
11097
* Build your source frontend app as you normally would, with `npm`:
11198

11299
```Dockerfile
@@ -117,25 +104,15 @@ RUN npm run build
117104
...
118105
```
119106

120-
* If you need to pass build time arguments (for example in Angular), modify the previous instruction using the previously declared `ARG`, e.g.:
121-
122-
```Dockerfile
123-
...
124-
125-
RUN npm run build -- --output-path=./dist/out --configuration $configuration
126-
127-
...
128-
```
129-
130-
...after that, you would have a fresh build of your frontend app code inside a Docker container. But if you are serving frontend (static files) you could serve them with a high performance server as Nginx, and have a leaner Docker image without all the Node.js code.
107+
...after that, you would have a fresh build of your frontend app code inside a Docker image. But if you are serving frontend (static files) you could serve them with a high performance server as Nginx, and have a leaner Docker image without all the Node.js code.
131108

132109
* Create a new "stage" (just as if it was another Docker image in the same file) based on Nginx:
133110

134111
```Dockerfile
135112
...
136113

137114
# Stage 1, based on Nginx, to have only the compiled app, ready for production with Nginx
138-
FROM nginx:1.15
115+
FROM nginx:latest
139116

140117
...
141118
```
@@ -145,19 +122,31 @@ FROM nginx:1.15
145122
```Dockerfile
146123
...
147124

148-
COPY --from=build-stage /app/dist/out/ /usr/share/nginx/html
125+
COPY --from=build-stage /app/dist/ /usr/share/nginx/html
149126

150127
...
151128
```
152129

153-
... make sure you change `/app/dist/out/` to the directory inside `/app/` that contains your compiled frontend code.
130+
* Create a file `nginx.conf` with:
154131

155-
* This image also contains a default Nginx configuration so that you don't have to provide one. By default it routes everything to your frontend app (to your `index.html`), so that you can use "HTML5" full URLs and they will always work, even if your users type them directly in the browser. Make your Docker image copy that default configuration from the previous stage to Nginx's configurations directory:
132+
```Nginx
133+
server {
134+
listen 80;
135+
136+
location / {
137+
root /usr/share/nginx/html;
138+
index index.html index.htm;
139+
try_files $uri /index.html =404;
140+
}
141+
}
142+
```
143+
144+
* This configuration routes everything to your frontend app (to your `index.html`), so that you can use full URLs and they will always work, even if your users type them directly in the browser. Make your Docker image copy that configuration to Nginx's configurations directory:
156145

157146
```Dockerfile
158147
...
159148

160-
COPY --from=build-stage /nginx.conf /etc/nginx/conf.d/default.conf
149+
COPY ./nginx.conf /etc/nginx/conf.d/default.conf
161150

162151
...
163152
```
@@ -166,7 +155,7 @@ COPY --from=build-stage /nginx.conf /etc/nginx/conf.d/default.conf
166155

167156
```Dockerfile
168157
# Stage 0, "build-stage", based on Node.js, to build and compile the frontend
169-
FROM tiangolo/node-frontend:10 as build-stage
158+
FROM node:latest as build-stage
170159

171160
WORKDIR /app
172161

@@ -176,19 +165,19 @@ RUN npm install
176165

177166
COPY ./ /app/
178167

179-
RUN npm run test -- --browsers ChromeHeadlessNoSandbox --watch=false
168+
ARG VITE_API_URL=${VITE_API_URL}
180169

181-
ARG configuration=production
170+
RUN npm run test
182171

183-
RUN npm run build -- --output-path=./dist/out --configuration $configuration
172+
RUN npm run build
184173

185174

186175
# Stage 1, based on Nginx, to have only the compiled app, ready for production with Nginx
187-
FROM nginx:1.15
176+
FROM nginx:latest
188177

189-
COPY --from=build-stage /app/dist/out/ /usr/share/nginx/html
178+
COPY --from=build-stage /app/dist/ /usr/share/nginx/html/
190179

191-
COPY --from=build-stage /nginx.conf /etc/nginx/conf.d/default.conf
180+
COPY ./nginx.conf /etc/nginx/conf.d/default.conf
192181
```
193182

194183
### Building the Docker image
@@ -199,12 +188,12 @@ COPY --from=build-stage /nginx.conf /etc/nginx/conf.d/default.conf
199188
docker build -t my-frontend-project:prod .
200189
```
201190

202-
...If you had tests and added above, they will be run. Your app will be compiled and you will end up with a lean high performance Nginx server with your fresh compiled app. Ready for production.
191+
...If you had tests and added them above, they will be run. Your app will be compiled and you will end up with a lean high performance Nginx server with your fresh compiled app. Ready for production.
203192

204-
* If you need to pass build time arguments (like for Angular `--configuration`s), for example if you have a "staging" environment, you can pass them like:
193+
* If you need to pass build time arguments, for example if you have a "staging" environment, you can pass them like:
205194

206195
```bash
207-
docker build -t my-frontend-project:stag --build-arg configuration="staging" .
196+
docker build -t my-frontend-project:stag --build-arg VITE_API_URL="https://staging.example.com" .
208197
```
209198

210199
### Testing the Docker image
@@ -225,11 +214,11 @@ docker run -p 80:80 my-frontend-project:prod
225214
npm run start
226215
```
227216

228-
...use it.
217+
...use it.
229218

230219
It's faster and simpler to develop locally. But once you think you got it, build your Docker image and try it. You will see how it looks in the full production environment.
231220

232-
* If you want to have Chrome Headless tests, run them locally first, as you normally would (Karma, Jasmine, Jest, etc). Using the live normal browser. Make sure you have all the configurations right. Then install Puppeteer locally and make sure it runs locally (with local Headless Chrome). Once you know it is running locally, you can add that to your `Dockerfile` and have "continuous integration" and "continuous building"... and if you want add "continuous deployment". But first make it run locally, it's easier to debug only one step at a time.
221+
* If you want to have tests using a (maybe headless) browser, run them locally first, as you normally would. Using the live normal browser. Make sure you have all the configurations right. Once you know it is running locally, you can add that to your `Dockerfile` and have "continuous integration" and "continuous building"... and if you want, add "continuous deployment". But first make it run locally, it's easier to debug only one step at a time.
233222

234223
* Have fun.
235224

@@ -284,6 +273,24 @@ By making Nginx simply respond with 404 errors when requested for `/docs`, you a
284273

285274
And because you have a load balancer on top, redirecting requests to `/docs` to the correct service, Nginx would never actually return that 404. Only in the case of a failure, or during development.
286275

276+
## Deprecated Image
277+
278+
This used to be a Docker image to simplify the process of creating a full Node.js environment for frontend development with multistage building.
279+
280+
It included all the dependencies for Puppeteer, so you could just `npm install puppeteer` and it should work.
281+
282+
It also included a default Nginx configuration for your frontend application, with the same content above, so in multi-stage Docker builds you could copy it to an Nginx "stage".
283+
284+
It is derived from this article I wrote:
285+
286+
> Angular in Docker with Nginx, supporting configurations / environments, built with multi-stage Docker builds and testing with Chrome Headless
287+
288+
[in Medium](https://medium.com/@tiangolo/angular-in-docker-with-nginx-supporting-environments-built-with-multi-stage-docker-builds-bb9f1724e984), and [in GitHub](https://github.com/tiangolo/medium-posts/tree/master/angular-in-docker)
289+
290+
As copying the `nginx.conf` file to the `Dockerfile` is not that much work, and the dependencies for Puppeteer are probably no longer relevant as Playwright is in many cases a better option, it doesn't make sense to keep supporting this Docker image, and it doesn't make sense for you to use it.
291+
292+
You are better off following the instructions above. 🤓
293+
287294
## Release Notes
288295

289296
### Latest Changes

0 commit comments

Comments
 (0)