Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit 2e23cbd

Browse files
committedNov 14, 2020
ci(lint): use super-linter
Replace all other linters with super-linter
1 parent 554638e commit 2e23cbd

13 files changed

+266
-189
lines changed
 

‎.editorconfig

+3
Original file line numberDiff line numberDiff line change
@@ -7,3 +7,6 @@ indent_size = 2
77
indent_style = space
88
insert_final_newline = true
99
trim_trailing_whitespace = true
10+
11+
[*.sh]
12+
space_redirects = true # like -sr
+18
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
2+
{
3+
"problemMatcher": [
4+
{
5+
"owner": "markdownlint",
6+
"pattern": [
7+
{
8+
"regexp": "^([^:]*):(\\d+):?(\\d+)?\\s([\\w-\\/]*)\\s(.*)$",
9+
"file": 1,
10+
"line": 2,
11+
"column": 3,
12+
"code": 4,
13+
"message": 5
14+
}
15+
]
16+
}
17+
]
18+
}

‎.github/workflows/eclint.yml

-14
This file was deleted.

‎.github/workflows/linter.yml

+24
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
name: Lint
2+
on:
3+
pull_request:
4+
5+
jobs:
6+
super-linter:
7+
name: Lint
8+
runs-on: ubuntu-latest
9+
10+
steps:
11+
- name: Checkout Code
12+
uses: actions/checkout@v2
13+
14+
- name: Setup Node
15+
uses: actions/setup-node@v1
16+
17+
- name: Add matchers
18+
run: |
19+
echo "::add-matcher::.github/super-linter-problem-matcher.json"
20+
- name: Lint Code Base
21+
uses: github/super-linter@v3
22+
env:
23+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
24+
FILTER_REGEX_EXCLUDE: .*.template

‎.github/workflows/markdown-link-check.yml

-19
This file was deleted.

‎.github/workflows/shfmt.yml

-20
This file was deleted.

‎CONTRIBUTING.md

+31-12
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,45 @@
11
# Contributing to docker-node
22

3-
Thank you for your contribution. Here are a set of guidelines for contributing to the docker-node project.
3+
Thank you for your contribution. Here are a set of guidelines for contributing
4+
to the docker-node project.
45

56
## Version Updates
67

78
New **Node.js** releases are released as soon as possible.
89

9-
New **NPM** releases are not tracked. We simply use the NPM version bundled in the corresponding Node.js release.
10+
New **NPM** releases are not tracked. We simply use the NPM version bundled in
11+
the corresponding Node.js release.
1012

11-
**Yarn** is updated to the latest version only when there is a new Node.js SemVer PATCH release (unless Yarn has received a security update), and it's updated only in the branch with the new release, preferably in the same PR. The `update.sh` script does this automatically when invoked with a specific branch, e.g. `./update.sh 6.10`.
13+
**Yarn** is updated to the latest version only when there is a new Node.js
14+
SemVer PATCH release (unless Yarn has received a security update), and it's
15+
updated only in the branch with the new release, preferably in the same PR. The
16+
`update.sh` script does this automatically when invoked with a specific branch,
17+
e.g. `./update.sh 6.10`.
1218

1319
### Submitting a PR for a version update
1420

15-
If you'd like to help us by submitting a PR for a version update, please do the following:
16-
17-
1. [Fork this project.](https://help.github.com/en/github/getting-started-with-github/fork-a-repo)
18-
1. [Clone the forked repository.](https://help.github.com/en/github/creating-cloning-and-archiving-repositories/cloning-a-repository)
19-
1. Create a branch for the update PR. For example, `git checkout master; git checkout -b version-update`.
20-
1. Run `./update.sh`. You can see additional options by using accessing the built-in help documentation with `./update.sh -h`. This script will automatically update the appropriate files with the latest versions and checksums.
21-
1. Commit the modified files to the `version-update` branch and push the branch to your fork.
22-
1. [Create a PR to merge the branch from your fork into this project's master branch.](https://help.github.com/en/github/collaborating-with-issues-and-pull-requests/creating-a-pull-request-from-a-fork).
21+
If you'd like to help us by submitting a PR for a version update, please do the
22+
following:
23+
24+
1. [Fork this
25+
project.](https://help.github.com/en/github/getting-started-with-github/fork-a-repo)
26+
1. [Clone the forked
27+
repository.](https://help.github.com/en/github/creating-cloning-and-archiving-repositories/cloning-a-repository)
28+
1. Create a branch for the update PR. For example, `git checkout master; git
29+
checkout -b version-update`.
30+
1. Run `./update.sh`. You can see additional options by using accessing the
31+
built-in help documentation with `./update.sh -h`. This script will
32+
automatically update the appropriate files with the latest versions and
33+
checksums.
34+
1. Commit the modified files to the `version-update` branch and push the branch
35+
to your fork.
36+
1. [Create a PR to merge the branch from your fork into this project's master
37+
branch.](https://help.github.com/en/github/collaborating-with-issues-and-pull-requests/creating-a-pull-request-from-a-fork).
2338

2439
## Adding dependencies to the base images
2540

26-
NodeJS is a big ecosystem with a variety of different use cases. The docker images for node are designed to provide the minimum for running core node. Additional dependencies (including dependencies for npm or yarn such as git) will not be included in these base images and will need to be included in descendent image.
41+
NodeJS is a big ecosystem with a variety of different use cases. The docker
42+
images for node are designed to provide the minimum for running core node.
43+
Additional dependencies (including dependencies for npm or yarn such as git)
44+
will not be included in these base images and will need to be included in
45+
descendent image.

‎GOVERNANCE.md

-2
Original file line numberDiff line numberDiff line change
@@ -111,8 +111,6 @@ If an agenda item cannot reach a consensus a WG member can call for a
111111
closing vote. The call for a vote must be seconded by a majority of
112112
the WG or else the discussion will continue. Simple majority wins.
113113

114-
<a id="developers-certificate-of-origin"></a>
115-
116114
## Developer's Certificate of Origin 1.1
117115

118116
By making a contribution to this project, I certify that:

‎README.md

+56-48
Original file line numberDiff line numberDiff line change
@@ -2,16 +2,18 @@
22

33
[![dockeri.co](http://dockeri.co/image/_/node)](https://registry.hub.docker.com/_/node/)
44

5-
[![GitHub issues](https://img.shields.io/github/issues/nodejs/docker-node.svg "GitHub issues")](https://github.com/nodejs/docker-node)
6-
[![GitHub stars](https://img.shields.io/github/stars/nodejs/docker-node.svg "GitHub stars")](https://github.com/nodejs/docker-node)
5+
[![GitHub issues](https://img.shields.io/github/issues/nodejs/docker-node.svg
6+
"GitHub issues")](https://github.com/nodejs/docker-node) [![GitHub
7+
stars](https://img.shields.io/github/stars/nodejs/docker-node.svg "GitHub
8+
stars")](https://github.com/nodejs/docker-node)
79

810
The official Node.js docker image, made with love by the node community.
911

1012
<!-- START doctoc generated TOC please keep comment here to allow auto update -->
1113
<!-- DON'T EDIT THIS SECTION, INSTEAD RE-RUN doctoc TO UPDATE -->
1214
## Table of Contents
1315

14-
- [What is Node.js?](#what-is-nodejs)
16+
- [What is Node.js](#what-is-nodejs)
1517
- [How to use this image](#how-to-use-this-image)
1618
- [Create a `Dockerfile` in your Node.js app project](#create-a-dockerfile-in-your-nodejs-app-project)
1719
- [Best Practices](#best-practices)
@@ -31,18 +33,18 @@ The official Node.js docker image, made with love by the node community.
3133
- [Docker Working Group Members](#docker-working-group-members)
3234
- [Docker Working Group Collaborators](#docker-working-group-collaborators)
3335
- [Emeritus](#emeritus)
34-
- [Docker Working Group Members](#docker-working-group-members-1)
36+
- [Emeritus Docker Working Group Members](#emeritus-docker-working-group-members)
3537

3638
<!-- END doctoc generated TOC please keep comment here to allow auto update -->
3739

38-
## What is Node.js?
40+
## What is Node.js
3941

4042
Node.js is a platform built on Chrome's JavaScript runtime for easily building
4143
fast, scalable network applications. Node.js uses an event-driven, non-blocking
4244
I/O model that makes it lightweight and efficient, perfect for data-intensive
4345
real-time applications that run across distributed devices.
4446

45-
See: http://nodejs.org
47+
See: <http://nodejs.org>
4648

4749
## How to use this image
4850

@@ -58,8 +60,8 @@ EXPOSE 8888
5860
You can then build and run the Docker image:
5961

6062
```console
61-
$ docker build -t my-nodejs-app .
62-
$ docker run -it --rm --name my-running-app my-nodejs-app
63+
docker build -t my-nodejs-app .
64+
docker run -it --rm --name my-running-app my-nodejs-app
6365
```
6466

6567
If you prefer Docker Compose:
@@ -83,16 +85,18 @@ services:
8385
You can then run using Docker Compose:
8486
8587
```console
86-
$ docker-compose up -d
88+
docker-compose up -d
8789
```
8890

89-
Docker Compose example copies your current directory (including node_modules) to the container.
90-
It assumes that your application has a file named [`package.json`](https://docs.npmjs.com/files/package.json)
91-
defining [start script](https://docs.npmjs.com/misc/scripts#default-values).
91+
Docker Compose example copies your current directory (including node_modules) to
92+
the container. It assumes that your application has a file named
93+
[`package.json`](https://docs.npmjs.com/files/package.json) defining [start
94+
script](https://docs.npmjs.com/misc/scripts#default-values).
9295

9396
### Best Practices
9497

95-
We have assembled a [Best Practices Guide](./docs/BestPractices.md) for those using these images on a daily basis.
98+
We have assembled a [Best Practices Guide](./docs/BestPractices.md) for those
99+
using these images on a daily basis.
96100

97101
### Run a single Node.js script
98102

@@ -101,16 +105,18 @@ complete `Dockerfile`. In such cases, you can run a Node.js script by using the
101105
Node.js Docker image directly:
102106

103107
```console
104-
$ docker run -it --rm --name my-running-script -v "$PWD":/usr/src/app -w /usr/src/app node:8 node your-daemon-or-script.js
108+
docker run -it --rm --name my-running-script -v "$PWD":/usr/src/app \
109+
-w /usr/src/app node:8 node your-daemon-or-script.js
105110
```
106111

107112
### Verbosity
108113

109-
Prior to 8.7.0 and 6.11.4 the docker images overrode the default npm log
110-
level from `warn` to `info`. However due to improvements to npm and new Docker
111-
patterns (e.g. multi-stage builds) the working group reached a [consensus](https://github.com/nodejs/docker-node/issues/528)
112-
to revert the log level to npm defaults. If you need more verbose output, please
113-
use one of the following methods to change the verbosity level.
114+
Prior to 8.7.0 and 6.11.4 the docker images overrode the default npm log level
115+
from `warn` to `info`. However due to improvements to npm and new Docker
116+
patterns (e.g. multi-stage builds) the working group reached a
117+
[consensus](https://github.com/nodejs/docker-node/issues/528) to revert the log
118+
level to npm defaults. If you need more verbose output, please use one of the
119+
following methods to change the verbosity level.
114120

115121
#### Dockerfile
116122

@@ -129,7 +135,7 @@ If you run the node image using `docker run` you can use the `-e` flag to
129135
override `NPM_CONFIG_LOGLEVEL`.
130136

131137
```console
132-
$ docker run -e NPM_CONFIG_LOGLEVEL=info node ...
138+
docker run -e NPM_CONFIG_LOGLEVEL=info node ...
133139
```
134140

135141
#### NPM run
@@ -138,7 +144,7 @@ If you are running npm commands you can use `--loglevel` to control the
138144
verbosity of the output.
139145

140146
```console
141-
$ docker run node npm --loglevel=warn ...
147+
docker run node npm --loglevel=warn ...
142148
```
143149

144150
## Image Variants
@@ -147,8 +153,8 @@ The `node` images come in many flavors, each designed for a specific use case.
147153
All of the images contain pre-installed versions of `node`,
148154
[`npm`](https://www.npmjs.com/), and [`yarn`](https://yarnpkg.com). For each
149155
supported architecture, the supported variants are different. In the file:
150-
[architectures](./architectures), it lists all supported variants for all of
151-
the architectures that we support now.
156+
[architectures](./architectures), it lists all supported variants for all of the
157+
architectures that we support now.
152158

153159
### `node:<version>`
154160

@@ -164,31 +170,32 @@ need to install, thus reducing the overall size of all images on your system.
164170

165171
### `node:alpine`
166172

167-
This image is based on the popular
168-
[Alpine Linux project](http://alpinelinux.org), available in
169-
[the `alpine` official image](https://hub.docker.com/_/alpine). Alpine Linux is
170-
much smaller than most distribution base images (~5MB), and thus leads to much
171-
slimmer images in general.
173+
This image is based on the popular [Alpine Linux
174+
project](http://alpinelinux.org), available in [the `alpine` official
175+
image](https://hub.docker.com/_/alpine). Alpine Linux is much smaller than most
176+
distribution base images (~5MB), and thus leads to much slimmer images in
177+
general.
172178

173179
This variant is highly recommended when final image size being as small as
174-
possible is desired. The main caveat to note is that it does use
175-
[musl libc](http://www.musl-libc.org) instead of
176-
[glibc and friends](http://www.etalabs.net/compare_libcs.html), so certain
177-
software might run into issues depending on the depth of their libc
178-
requirements. However, most software doesn't have an issue with this, so this
179-
variant is usually a very safe choice. See
180-
[this Hacker News comment thread](https://news.ycombinator.com/item?id=10782897)
181-
for more discussion of the issues that might arise and some pro/con comparisons
182-
of using Alpine-based images. One common issue that may arise is a missing shared
183-
library required for use of `process.dlopen`. To add the missing shared libraries
184-
to your image, adding the [`libc6-compat`](https://pkgs.alpinelinux.org/package/edge/main/x86/libc6-compat)
180+
possible is desired. The main caveat to note is that it does use [musl
181+
libc](http://www.musl-libc.org) instead of [glibc and
182+
friends](http://www.etalabs.net/compare_libcs.html), so certain software might
183+
run into issues depending on the depth of their libc requirements. However, most
184+
software doesn't have an issue with this, so this variant is usually a very safe
185+
choice. See [this Hacker News comment
186+
thread](https://news.ycombinator.com/item?id=10782897) for more discussion of
187+
the issues that might arise and some pro/con comparisons of using Alpine-based
188+
images. One common issue that may arise is a missing shared library required for
189+
use of `process.dlopen`. To add the missing shared libraries to your image,
190+
adding the
191+
[`libc6-compat`](https://pkgs.alpinelinux.org/package/edge/main/x86/libc6-compat)
185192
package in your Dockerfile is recommended: `apk add --no-cache libc6-compat`
186193

187-
To minimize image size, it's uncommon for additional related tools
188-
(such as `git` or `bash`) to be included in Alpine-based images. Using this
189-
image as a base, add the things you need in your own Dockerfile
190-
(see the [`alpine` image description](https://hub.docker.com/_/alpine/) for
191-
examples of how to install packages if you are unfamiliar).
194+
To minimize image size, it's uncommon for additional related tools (such as
195+
`git` or `bash`) to be included in Alpine-based images. Using this image as a
196+
base, add the things you need in your own Dockerfile (see the [`alpine` image
197+
description](https://hub.docker.com/_/alpine/) for examples of how to install
198+
packages if you are unfamiliar).
192199

193200
### `node:slim`
194201

@@ -217,14 +224,15 @@ upgrade your Docker daemon.
217224

218225
## Supported Node.js versions
219226

220-
This project will support Node.js versions as still under active support as per the [Node.js release schedule](https://github.com/nodejs/Release).
227+
This project will support Node.js versions as still under active support as per
228+
the [Node.js release schedule](https://github.com/nodejs/Release).
221229

222230
## Governance and Current Members
223231

224232
The Node.js Docker Image is governed by the Docker Working Group. See
225233
[GOVERNANCE.md](https://github.com/nodejs/docker-node/blob/master/GOVERNANCE.md)
226-
to learn more about the group's structure and [CONTRIBUTING.md](CONTRIBUTING.md) for guidance
227-
about the expectations for all contributors to this project.
234+
to learn more about the group's structure and [CONTRIBUTING.md](CONTRIBUTING.md)
235+
for guidance about the expectations for all contributors to this project.
228236

229237
### Docker Working Group Members
230238

@@ -242,6 +250,6 @@ about the expectations for all contributors to this project.
242250

243251
### Emeritus
244252

245-
#### Docker Working Group Members
253+
#### Emeritus Docker Working Group Members
246254

247255
- Christopher Horrell ([chorrell](https://github.com/chorrell))

‎SECURITY.md

+9-4
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,16 @@
22

33
## Reporting a Vulnerability
44

5-
Security issues relating to Node.js project should follow the process documented on <https://nodejs.org/en/security/>.
5+
Security issues relating to Node.js project should follow the process documented
6+
on <https://nodejs.org/en/security/>.
67

7-
CVEs for the base image packages should be reported to those repositories. Nothing to address those CVEs is in the hands of this repos.
8+
CVEs for the base image packages should be reported to those repositories.
9+
Nothing to address those CVEs is in the hands of this repos.
810

911
- [Alpine](https://github.com/alpinelinux/docker-alpine)
10-
- [Debian (buster, stretch)](https://github.com/debuerreotype/docker-debian-artifacts)
12+
- [Debian (buster,
13+
stretch)](https://github.com/debuerreotype/docker-debian-artifacts)
1114

12-
When base images are patched, the images are rebuilt and rolled out to the Docker hub without intervention by this repo. This process is explained in <https://github.com/docker-library/faq/#why-does-my-security-scanner-show-that-an-image-has-cves>.
15+
When base images are patched, the images are rebuilt and rolled out to the
16+
Docker hub without intervention by this repo. This process is explained in
17+
<https://github.com/docker-library/faq/#why-does-my-security-scanner-show-that-an-image-has-cves>.

‎docs/BestPractices.md

+82-27
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,24 @@
1+
<!-- START doctoc generated TOC please keep comment here to allow auto update -->
2+
<!-- DON'T EDIT THIS SECTION, INSTEAD RE-RUN doctoc TO UPDATE -->
3+
## Table of Contents
4+
5+
- [Docker and Node.js Best Practices](#docker-and-nodejs-best-practices)
6+
- [Table of Contents](#table-of-contents)
7+
- [Environment Variables](#environment-variables)
8+
- [Global npm dependencies](#global-npm-dependencies)
9+
- [Upgrading/downgrading Yarn](#upgradingdowngrading-yarn)
10+
- [Local](#local)
11+
- [Global](#global)
12+
- [Handling Kernel Signals](#handling-kernel-signals)
13+
- [Non-root User](#non-root-user)
14+
- [Memory](#memory)
15+
- [CMD](#cmd)
16+
- [Docker Run](#docker-run)
17+
- [Security](#security)
18+
- [node-gyp alpine](#node-gyp-alpine)
19+
20+
<!-- END doctoc generated TOC please keep comment here to allow auto update -->
21+
122
# Docker and Node.js Best Practices
223

324
<!-- START doctoc generated TOC please keep comment here to allow auto update -->
@@ -21,31 +42,38 @@
2142

2243
## Environment Variables
2344

24-
Run with `NODE_ENV` set to `production`. This is the way you would pass in secrets and other runtime configurations to your application as well.
45+
Run with `NODE_ENV` set to `production`. This is the way you would pass in
46+
secrets and other runtime configurations to your application as well.
2547

26-
```
48+
```console
2749
-e "NODE_ENV=production"
2850
```
2951

3052
## Global npm dependencies
3153

32-
If you need to install global npm dependencies, it is recommended to place those dependencies in the [non-root user](#non-root-user) directory. To achieve this, add the following line to your `Dockerfile`
54+
If you need to install global npm dependencies, it is recommended to place those
55+
dependencies in the [non-root user](#non-root-user) directory. To achieve this,
56+
add the following line to your `Dockerfile`
3357

3458
```Dockerfile
3559
ENV NPM_CONFIG_PREFIX=/home/node/.npm-global
3660

37-
ENV PATH=$PATH:/home/node/.npm-global/bin # optionally if you want to run npm global bin without specifying path
61+
# optionally if you want to run npm global bin without specifying path
62+
ENV PATH=$PATH:/home/node/.npm-global/bin
3863
```
3964

4065
## Upgrading/downgrading Yarn
4166

4267
### Local
4368

44-
If you need to upgrade/downgrade `yarn` for a local install, you can do so by issuing the following commands in your `Dockerfile`:
45-
46-
> Note that if you create some other directory which is not a descendant one from where you ran the command, you will end up using the global (dated) version. If you wish to upgrade `yarn` globally follow the instructions in the next section.
69+
If you need to upgrade/downgrade `yarn` for a local install, you can do so by
70+
issuing the following commands in your `Dockerfile`:
4771

48-
> When following the local install instructions, due to duplicated yarn the image will end up being bigger.
72+
> Note that if you create some other directory which is not a descendant one
73+
> from where you ran the command, you will end up using the global (dated)
74+
> version. If you wish to upgrade `yarn` globally follow the instructions in the
75+
> next section. When following the local install instructions, due to duplicated
76+
> yarn the image will end up being bigger.
4977
5078
```Dockerfile
5179
FROM node:6
@@ -62,22 +90,25 @@ FROM node:6
6290

6391
ENV YARN_VERSION 1.16.0
6492

65-
RUN curl -fSLO --compressed "https://yarnpkg.com/downloads/$YARN_VERSION/yarn-v$YARN_VERSION.tar.gz" \
93+
RUN curl -fSLO --compressed \
94+
"https://yarnpkg.com/downloads/$YARN_VERSION/yarn-v$YARN_VERSION.tar.gz" \
6695
&& tar -xzf yarn-v$YARN_VERSION.tar.gz -C /opt/ \
6796
&& ln -snf /opt/yarn-v$YARN_VERSION/bin/yarn /usr/local/bin/yarn \
6897
&& ln -snf /opt/yarn-v$YARN_VERSION/bin/yarnpkg /usr/local/bin/yarnpkg \
6998
&& rm yarn-v$YARN_VERSION.tar.gz
7099
```
71100

72-
If you're using an Alpine-based image, `curl` won't be present, so you'll need to make sure it's installed while using it:
101+
If you're using an Alpine-based image, `curl` won't be present, so you'll need
102+
to make sure it's installed while using it:
73103

74104
```Dockerfile
75105
FROM node:6-alpine
76106

77107
ENV YARN_VERSION 1.5.1
78108

79109
RUN apk add --no-cache --virtual .build-deps-yarn curl \
80-
&& curl -fSLO --compressed "https://yarnpkg.com/downloads/$YARN_VERSION/yarn-v$YARN_VERSION.tar.gz" \
110+
&& curl -fSLO --compressed \
111+
"https://yarnpkg.com/downloads/$YARN_VERSION/yarn-v$YARN_VERSION.tar.gz" \
81112
&& tar -xzf yarn-v$YARN_VERSION.tar.gz -C /opt/ \
82113
&& ln -snf /opt/yarn-v$YARN_VERSION/bin/yarn /usr/local/bin/yarn \
83114
&& ln -snf /opt/yarn-v$YARN_VERSION/bin/yarnpkg /usr/local/bin/yarnpkg \
@@ -87,19 +118,29 @@ RUN apk add --no-cache --virtual .build-deps-yarn curl \
87118

88119
## Handling Kernel Signals
89120

90-
Node.js was not designed to run as PID 1 which leads to unexpected behaviour when running inside of Docker. For example, a Node.js process running as PID 1 will not respond to `SIGINT` (`CTRL-C`) and similar signals. As of Docker 1.13, you can use the `--init` flag to wrap your Node.js process with a [lightweight init system](https://github.com/krallin/tini) that properly handles running as PID 1.
121+
Node.js was not designed to run as PID 1 which leads to unexpected behaviour
122+
when running inside of Docker. For example, a Node.js process running as PID 1
123+
will not respond to `SIGINT` (`CTRL-C`) and similar signals. As of Docker 1.13,
124+
you can use the `--init` flag to wrap your Node.js process with a [lightweight
125+
init system](https://github.com/krallin/tini) that properly handles running as
126+
PID 1.
91127

92-
```
128+
```console
93129
docker run -it --init node
94130
```
95131

96-
You can also include Tini [directly in your Dockerfile](https://github.com/krallin/tini#using-tini), ensuring your process is always started with an init wrapper.
132+
You can also include Tini [directly in your
133+
Dockerfile](https://github.com/krallin/tini#using-tini), ensuring your process
134+
is always started with an init wrapper.
97135

98136
## Non-root User
99137

100-
By default, Docker runs container as root which inside of the container can pose as a security issue. You would want to run the container as an unprivileged user wherever possible. The node images provide the `node` user for such purpose. The Docker Image can then be run with the `node` user in the following way:
138+
By default, Docker runs container as root which inside of the container can pose
139+
as a security issue. You would want to run the container as an unprivileged user
140+
wherever possible. The node images provide the `node` user for such purpose. The
141+
Docker Image can then be run with the `node` user in the following way:
101142

102-
```
143+
```console
103144
-u "node"
104145
```
105146

@@ -112,9 +153,12 @@ FROM node:6.10.3
112153
USER node
113154
```
114155

115-
Note that the `node` user is neither a build-time nor a run-time dependency and it can be removed or altered, as long as the functionality of the application you want to add to the container does not depend on it.
156+
Note that the `node` user is neither a build-time nor a run-time dependency and
157+
it can be removed or altered, as long as the functionality of the application
158+
you want to add to the container does not depend on it.
116159

117-
If you do not want nor need the user created in this image you can remove it with the following:
160+
If you do not want nor need the user created in this image you can remove it
161+
with the following:
118162

119163
```Dockerfile
120164
# For debian based images use:
@@ -136,7 +180,8 @@ If you need another name for the user (ex. `myapp`) execute:
136180
RUN usermod -d /home/myapp -l myapp node
137181
```
138182

139-
For alpine based images, you do not have `groupmod` nor `usermod`, so to change the uid/gid you have to delete the previous user:
183+
For alpine based images, you do not have `groupmod` nor `usermod`, so to change
184+
the uid/gid you have to delete the previous user:
140185

141186
```Dockerfile
142187
RUN deluser --remove-home node \
@@ -146,26 +191,33 @@ RUN deluser --remove-home node \
146191

147192
## Memory
148193

149-
By default, any Docker Container may consume as much of the hardware such as CPU and RAM. If you are running multiple containers on the same host you should limit how much memory they can consume.
194+
By default, any Docker Container may consume as much of the hardware such as CPU
195+
and RAM. If you are running multiple containers on the same host you should
196+
limit how much memory they can consume.
150197

151-
```
198+
```console
152199
-m "300M" --memory-swap "1G"
153200
```
154201

155202
## CMD
156203

157-
When creating an image, you can bypass the `package.json`'s `start` command and bake it directly into the image itself. First off this reduces the number of processes running inside of your container. Secondly it causes exit signals such as `SIGTERM` and `SIGINT` to be received by the Node.js process instead of npm swallowing them.
204+
When creating an image, you can bypass the `package.json`'s `start` command and
205+
bake it directly into the image itself. First off this reduces the number of
206+
processes running inside of your container. Secondly it causes exit signals such
207+
as `SIGTERM` and `SIGINT` to be received by the Node.js process instead of npm
208+
swallowing them.
158209

159210
```Dockerfile
160211
CMD ["node","index.js"]
161212
```
162213

163214
## Docker Run
164215

165-
Here is an example of how you would run a default Node.JS Docker Containerized application:
216+
Here is an example of how you would run a default Node.JS Docker Containerized
217+
application:
166218

167-
```
168-
$ docker run \
219+
```console
220+
docker run \
169221
-e "NODE_ENV=production" \
170222
-u "node" \
171223
-m "300M" --memory-swap "1G" \
@@ -176,11 +228,14 @@ $ docker run \
176228

177229
## Security
178230

179-
The Docker team has provided a tool to analyze your running containers for potential security issues. You can download and run this tool from here: https://github.com/docker/docker-bench-security
231+
The Docker team has provided a tool to analyze your running containers for
232+
potential security issues. You can download and run this tool from here:
233+
<https://github.com/docker/docker-bench-security>
180234

181235
## node-gyp alpine
182236

183-
Here is an example of how you would install dependencies for packages that require node-gyp support on the alpine variant:
237+
Here is an example of how you would install dependencies for packages that
238+
require node-gyp support on the alpine variant:
184239

185240
```Dockerfile
186241
FROM node:alpine

‎genMatrix.js

+31-31
Original file line numberDiff line numberDiff line change
@@ -1,80 +1,80 @@
1-
'use strict';
2-
const path = require('path');
3-
const fs = require('fs');
1+
'use strict'
2+
const path = require('path')
3+
const fs = require('fs')
44

55
const testFiles = [
66
'genMatrix.js',
7-
'.github/workflows/build-test.yml',
8-
];
7+
'.github/workflows/build-test.yml'
8+
]
99

10-
const nodeDirRegex = /^\d+$/;
10+
const nodeDirRegex = /^\d+$/
1111

1212
const areTestFilesChanged = (changedFiles) => changedFiles
13-
.some((file) => testFiles.includes(file));
13+
.some((file) => testFiles.includes(file))
1414

1515
// Returns a list of the child directories in the given path
1616
const getChildDirectories = (parent) => fs.readdirSync(parent, { withFileTypes: true })
1717
.filter((dirent) => dirent.isDirectory())
18-
.map(({ name }) => path.resolve(parent, name));
18+
.map(({ name }) => path.resolve(parent, name))
1919

2020
const getNodeVerionDirs = (base) => getChildDirectories(base)
21-
.filter((childPath) => nodeDirRegex.test(path.basename(childPath)));
21+
.filter((childPath) => nodeDirRegex.test(path.basename(childPath)))
2222

2323
// Returns the paths of Dockerfiles that are at: base/*/Dockerfile
2424
const getDockerfilesInChildDirs = (base) => getChildDirectories(base)
25-
.map((childDir) => path.resolve(childDir, 'Dockerfile'));
25+
.map((childDir) => path.resolve(childDir, 'Dockerfile'))
2626

27-
const getAllDockerfiles = (base) => getNodeVerionDirs(base).flatMap(getDockerfilesInChildDirs);
27+
const getAllDockerfiles = (base) => getNodeVerionDirs(base).flatMap(getDockerfilesInChildDirs)
2828

2929
const getAffectedDockerfiles = (filesAdded, filesModified, filesRenamed) => {
3030
const files = [
3131
...filesAdded,
3232
...filesModified,
33-
...filesRenamed,
34-
];
33+
...filesRenamed
34+
]
3535

3636
// If the test files were changed, include everything
3737
if (areTestFilesChanged(files)) {
38-
console.log('Test files changed so scheduling all Dockerfiles');
39-
return getAllDockerfiles(__dirname);
38+
console.log('Test files changed so scheduling all Dockerfiles')
39+
return getAllDockerfiles(__dirname)
4040
}
4141

42-
const modifiedDockerfiles = files.filter((file) => file.endsWith('/Dockerfile'));
42+
const modifiedDockerfiles = files.filter((file) => file.endsWith('/Dockerfile'))
4343

4444
// Get Dockerfiles affected by modified docker-entrypoint.sh files
4545
const entrypointAffectedDockerfiles = files
4646
.filter((file) => file.endsWith('/docker-entrypoint.sh'))
47-
.map((file) => path.resolve(path.dirname(file), 'Dockerfile'));
47+
.map((file) => path.resolve(path.dirname(file), 'Dockerfile'))
4848

4949
return [
5050
...modifiedDockerfiles,
51-
...entrypointAffectedDockerfiles,
52-
];
53-
};
51+
...entrypointAffectedDockerfiles
52+
]
53+
}
5454

5555
const getFullNodeVersionFromDockerfile = (file) => fs.readFileSync(file, 'utf8')
56-
.match(/^ENV NODE_VERSION (\d*\.*\d*\.\d*)/m)[1];
56+
.match(/^ENV NODE_VERSION (\d*\.*\d*\.\d*)/m)[1]
5757

5858
const getDockerfileMatrixEntry = (file) => {
59-
const [variant] = path.dirname(file).split(path.sep).slice(-1);
59+
const [variant] = path.dirname(file).split(path.sep).slice(-1)
6060

61-
const version = getFullNodeVersionFromDockerfile(file);
61+
const version = getFullNodeVersionFromDockerfile(file)
6262

6363
return {
6464
version,
65-
variant,
66-
};
67-
};
65+
variant
66+
}
67+
}
6868

6969
const generateBuildMatrix = (filesAdded, filesModified, filesRenamed) => {
70-
const dockerfiles = [...new Set(getAffectedDockerfiles(filesAdded, filesModified, filesRenamed))];
70+
const dockerfiles = [...new Set(getAffectedDockerfiles(filesAdded, filesModified, filesRenamed))]
7171

72-
const entries = dockerfiles.map(getDockerfileMatrixEntry);
72+
const entries = dockerfiles.map(getDockerfileMatrixEntry)
7373

7474
// Return null if there are no entries so we can skip the matrix step
7575
return entries.length
7676
? { include: entries }
77-
: null;
78-
};
77+
: null
78+
}
7979

80-
module.exports = generateBuildMatrix;
80+
module.exports = generateBuildMatrix

‎update.sh

+12-12
Original file line numberDiff line numberDiff line change
@@ -30,18 +30,18 @@ EOF
3030
SKIP=false
3131
while getopts "sh" opt; do
3232
case "${opt}" in
33-
s)
34-
SKIP=true
35-
shift
36-
;;
37-
h)
38-
usage
39-
exit
40-
;;
41-
\?)
42-
usage
43-
exit
44-
;;
33+
s)
34+
SKIP=true
35+
shift
36+
;;
37+
h)
38+
usage
39+
exit
40+
;;
41+
\?)
42+
usage
43+
exit
44+
;;
4545
esac
4646
done
4747

0 commit comments

Comments
 (0)
Please sign in to comment.