Skip to content

Commit

Permalink
feat(node-distroless): add node-distroless image combines google dist…
Browse files Browse the repository at this point in the history
…roless and dump-init
  • Loading branch information
johnitvn committed Nov 24, 2024
1 parent a99d80f commit 5bb0886
Show file tree
Hide file tree
Showing 7 changed files with 83 additions and 1 deletion.
6 changes: 6 additions & 0 deletions images/node-distroless/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
FROM node:20-alpine AS init
RUN apk add --no-cache dumb-init

FROM gcr.io/distroless/nodejs22 AS runtime

Check warning on line 4 in images/node-distroless/Dockerfile

View check run for this annotation

codefactor.io / CodeFactor

images/node-distroless/Dockerfile#L4

Always tag the version of an image explicitly. (DL3006)
COPY --from=init /usr/bin/dumb-init /usr/bin/dumb-init
ENTRYPOINT [ "/usr/bin/dumb-init", "--", "/nodejs/bin/node" ]
7 changes: 7 additions & 0 deletions images/node-distroless/Dockerfile.test
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
FROM node-distroless:edge

WORKDIR /usr/src/app

COPY images/node-distroless/main.js .

CMD [ "main.js" ]
16 changes: 16 additions & 0 deletions images/node-distroless/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
# node-distroless

This image combines the compactness and security of distroless with the convenience of dumb-init for process management, making Node.js applications run more stably in a container environment.

> This image is maintained with node latest LTS version
## Usage

The simple usage example

```dockerfile
FROM ghcr.io/ebizbase/node-distroless
WORKDIR /usr/src/app
COPY . .
CMD [ "index.js" ]
```
1 change: 1 addition & 0 deletions images/node-distroless/main.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
console.log('NODE VERSION:' + process.version);
41 changes: 41 additions & 0 deletions images/node-distroless/project.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
{
"name": "node-distroless",
"$schema": "../../node_modules/nx/schemas/project-schema.json",
"projectType": "library",
"metadata": {
"version": "0.0.0"
},
"tags": [],
"targets": {
"build": {
"executor": "@ebizbase/nx-docker:build",
"options": {
"tags": ["node-distroless:edge"],
"outputs": ["type=image"]
}
},
"build-test": {
"dependsOn": ["build"],
"executor": "@ebizbase/nx-docker:build",
"options": {
"file": "images/node-distroless/Dockerfile.test",
"tags": ["node-distroless:test"],
"outputs": ["type=image"]
}
},
"test": {
"dependsOn": ["build-test"],
"executor": "nx:run-commands",
"options": {
"command": "docker run --rm node-distroless:test"
}
},
"publish": {
"executor": "@ebizbase/nx-docker:build",
"options": {
"tags": ["ghcr.io/ebizbase/node-distroless"],
"outputs": ["type=image"]
}
}
}
}
10 changes: 10 additions & 0 deletions release-config.json
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,16 @@
"jsonpath": "$.metadata.version"
}
]
},
"images/node-distroless": {
"package-name": "node-distroless",
"extra-files": [
{
"type": "json",
"path": "project.json",
"jsonpath": "$.metadata.version"
}
]
}
}
}
3 changes: 2 additions & 1 deletion release-manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,6 @@
"devcontainer-images/node-devcontainer": "1.0.0",
"devcontainer-images/node-dind-devcontainer": "1.0.0",
"devcontainer-images/node-dind-playwright-devcontainer": "1.0.0",
"devcontainer-images/node-playwright-devcontainer": "1.0.0"
"devcontainer-images/node-playwright-devcontainer": "1.0.0",
"images/node-distroless": "0.0.0"
}

0 comments on commit 5bb0886

Please sign in to comment.