Skip to content

Commit dd7c85a

Browse files
committed
Initial commit
0 parents  commit dd7c85a

11 files changed

+287
-0
lines changed

.github/dependabot.yml

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
version: 2
2+
updates:
3+
- package-ecosystem: "github-actions"
4+
directory: "/"
5+
schedule:
6+
interval: weekly
7+
open-pull-requests-limit: 10

.github/workflows/build-push.yml

+17
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
name: Build and push
2+
3+
permissions:
4+
contents: read
5+
packages: write
6+
7+
on:
8+
push:
9+
branches:
10+
- main
11+
schedule:
12+
- cron: '30 2 * * SUN'
13+
14+
jobs:
15+
build-and-push:
16+
uses: ./.github/workflows/docker.yml
17+
secrets: inherit

.github/workflows/check.yml

+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
name: Checks
2+
3+
permissions:
4+
contents: read
5+
6+
on:
7+
pull_request:
8+
9+
jobs:
10+
build:
11+
uses: ./.github/workflows/docker.yml
12+
secrets: inherit

.github/workflows/container-cleanup.yml

Whitespace-only changes.

.github/workflows/docker-images.yml

+57
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
name: Docker
2+
3+
on:
4+
workflow_call:
5+
inputs:
6+
node_version:
7+
type: string
8+
latest:
9+
type: boolean
10+
lts:
11+
type: boolean
12+
debian_version:
13+
type: string
14+
postgresql_version:
15+
type: string
16+
17+
jobs:
18+
base:
19+
uses: "tweedegolf/actions-container-helpers/.github/workflows/container-image.yml@main"
20+
with:
21+
push: ${{ github.ref == 'refs/heads/main' }}
22+
platforms: "linux/amd64,linux/arm64"
23+
build-args: |
24+
DEBIAN_VERSION=${{ inputs.debian_version }}
25+
NODE_VERSION=${{ inputs.node_version }}
26+
POSTGRESQL_VERSION=${{ inputs.postgresql_version }}
27+
tags: |
28+
ghcr.io/tweedegolf/node:${{inputs.node_version}}
29+
${{ inputs.latest && 'ghcr.io/tweedegolf/node:latest' || '' }}
30+
${{ inputs.lts && 'ghcr.io/tweedegolf/node:lts' || '' }}
31+
extended:
32+
uses: "tweedegolf/actions-container-helpers/.github/workflows/container-image.yml@main"
33+
with:
34+
file: Dockerfile-extended
35+
push: ${{ github.ref == 'refs/heads/main' }}
36+
platforms: "linux/amd64,linux/arm64"
37+
build-args: |
38+
DEBIAN_VERSION=${{ inputs.debian_version }}
39+
NODE_VERSION=${{ inputs.node_version }}
40+
tags: |
41+
ghcr.io/tweedegolf/node:${{inputs.node_version}}-extended
42+
${{ inputs.latest && 'ghcr.io/tweedegolf/node:latest-extended' || '' }}
43+
${{ inputs.lts && 'ghcr.io/tweedegolf/node:lts-extended' || '' }}
44+
45+
full:
46+
uses: "tweedegolf/actions-container-helpers/.github/workflows/container-image.yml@main"
47+
with:
48+
file: Dockerfile-full
49+
push: ${{ github.ref == 'refs/heads/main' }}
50+
platforms: "linux/amd64,linux/arm64"
51+
build-args: |
52+
DEBIAN_VERSION=${{ inputs.debian_version }}
53+
NODE_VERSION=${{ inputs.node_version }}
54+
tags: |
55+
ghcr.io/tweedegolf/node:${{inputs.node_version}}-full
56+
${{ inputs.latest && 'ghcr.io/tweedegolf/node:latest-full' || '' }}
57+
${{ inputs.lts && 'ghcr.io/tweedegolf/node:lts-full' || '' }}

.github/workflows/docker.yml

+23
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
name: Docker
2+
3+
on:
4+
workflow_call:
5+
6+
jobs:
7+
build:
8+
strategy:
9+
matrix:
10+
include:
11+
- node_version: 20
12+
latest: true
13+
lts: true
14+
- node_version: 18
15+
latest: false
16+
lts: false
17+
uses: "./.github/workflows/docker-images.yml"
18+
with:
19+
node_version: ${{ matrix.node_version }}
20+
latest: ${{ matrix.latest }}
21+
lts: ${{ matrix.lts }}
22+
debian_version: bookworm
23+
postgresql_version: "16"

Dockerfile

+39
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
ARG DEBIAN_VERSION
2+
FROM ghcr.io/tweedegolf/debian:${DEBIAN_VERSION}
3+
ARG DEBIAN_VERSION
4+
5+
# Add additional build tools for node.js (and node-gyp)
6+
RUN apt-get update \
7+
&& DEBIAN_FRONTEND=noninteractive apt-get install -y --no-install-recommends \
8+
build-essential \
9+
pkg-config \
10+
python3 \
11+
&& rm -rf /var/lib/apt/lists/*
12+
13+
# Install node.js
14+
ARG NODE_VERSION
15+
ENV NODE_VERSION ${NODE_VERSION}
16+
RUN curl -s -L https://deb.nodesource.com/gpgkey/nodesource-repo.gpg.key | gpg --dearmor -o /usr/share/keyrings/nodesource.gpg \
17+
&& echo "deb [arch=amd64 signed-by=/usr/share/keyrings/nodesource.gpg] https://deb.nodesource.com/node_$NODE_VERSION.x nodistro main" > /etc/apt/sources.list.d/nodesource.list \
18+
&& apt-get update \
19+
&& DEBIAN_FRONTEND=noninteractive apt-get install -y --no-install-recommends \
20+
nodejs \
21+
&& rm -rf /var/lib/apt/lists/*
22+
23+
# Install yarn
24+
RUN curl -sS https://dl.yarnpkg.com/debian/pubkey.gpg | apt-key add - \
25+
&& echo "deb https://dl.yarnpkg.com/debian/ stable main" | tee /etc/apt/sources.list.d/yarn.list \
26+
&& apt-get update \
27+
&& DEBIAN_FRONTEND=noninteractive apt-get install -y --no-install-recommends \
28+
yarn \
29+
&& rm -rf /var/lib/apt/lists/*
30+
31+
# Install postgresql client
32+
ARG POSTGRESQL_VERSION
33+
ENV POSTGRESQL_VERSION ${POSTGRESQL_VERSION}
34+
RUN curl -s -L https://www.postgresql.org/media/keys/ACCC4CF8.asc | apt-key add - \
35+
&& echo "deb http://apt.postgresql.org/pub/repos/apt/ $DEBIAN_VERSION-pgdg main" > /etc/apt/sources.list.d/pgdg.list \
36+
&& apt-get update \
37+
&& DEBIAN_FRONTEND=noninteractive apt-get install -y --no-install-recommends \
38+
postgresql-client-$POSTGRESQL_VERSION \
39+
&& rm -rf /var/lib/apt/lists/*

Dockerfile-extended

+51
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
ARG NODE_VERSION
2+
FROM ghcr.io/tweedegolf/node:${NODE_VERSION}
3+
4+
# Install dependencies for extended install
5+
RUN apt-get update \
6+
&& DEBIAN_FRONTEND=noninteractive apt-get install -y --no-install-recommends \
7+
ghostscript \
8+
python3 \
9+
python3-dev \
10+
python3-pip \
11+
python3-venv \
12+
gconf-service \
13+
libasound2 \
14+
libatk1.0-0 \
15+
libc6 \
16+
libcairo2 \
17+
libcups2 \
18+
libdbus-1-3 \
19+
libexpat1 \
20+
libfontconfig1 \
21+
libgbm-dev \
22+
libgcc1 \
23+
libgconf-2-4 \
24+
libgdk-pixbuf2.0-0 \
25+
libglib2.0-0 \
26+
libgtk-3-0 \
27+
libnspr4 \
28+
libpango-1.0-0 \
29+
libpangocairo-1.0-0 \
30+
libstdc++6 \
31+
libx11-6 \
32+
libx11-xcb1 \
33+
libxcb1 \
34+
libxcomposite1 \
35+
libxcursor1 \
36+
libxdamage1 \
37+
libxext6 \
38+
libxfixes3 \
39+
libxi6 \
40+
libxrandr2 \
41+
libxrender1 \
42+
libxshmfence-dev \
43+
libxss1 \
44+
libxtst6 \
45+
fonts-liberation \
46+
fonts-freefont-ttf \
47+
libayatana-appindicator1 \
48+
libnss3 \
49+
xdg-utils \
50+
libdrm2 \
51+
&& rm -rf /var/lib/apt/lists/*

Dockerfile-full

+19
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
ARG NODE_VERSION
2+
FROM ghcr.io/tweedegolf/node:${NODE_VERSION}-extended
3+
4+
RUN apt-get update \
5+
&& DEBIAN_FRONTEND=noninteractive apt-get install -y --no-install-recommends \
6+
chromium \
7+
firefox-esr \
8+
x11-utils \
9+
xvfb \
10+
dbus \
11+
udev \
12+
fluxbox \
13+
procps \
14+
tzdata \
15+
libosmesa6 \
16+
libglapi-mesa \
17+
libgl1-mesa-dri \
18+
mesa-utils \
19+
&& rm -rf /var/lib/apt/lists/*

LICENSE

Whitespace-only changes.

README.md

+62
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
# Node.js Docker images
2+
This image contains Node.js, yarn and a postgresql client and basic build
3+
tools. For yarn we use the 1.0 version distributed from their apt repository.
4+
Currently these tags are available:
5+
6+
* Node.js 18: `18`
7+
* Node.js 20: `20`, `lts`, `latest`
8+
9+
All versions contain node.js at the specified version, npm and yarn. They also
10+
include the postgresql client applications (e.g. psql and others) and include
11+
basic build tools allowing you to build C/C++ node.js extensions as well.
12+
13+
## Extended images
14+
You can also use the extended images (with the postfix `-extended`). These
15+
variants include dependencies for running browsers such as for usage with
16+
puppeteer.
17+
18+
## Full images
19+
A larger variant still is also available (with the postfix `-full`). These
20+
images include preinstalled firefox and chromium browsers, making them suitable
21+
for end-to-end testing.
22+
23+
## Usage
24+
For basic usage instructions, also see our [debian image] detailed usage
25+
instructions. Basic usage when using docker compose is shown below:
26+
27+
```yaml
28+
services:
29+
# ...
30+
app:
31+
image: ghcr.io/tweedegolf/node:lts
32+
user: "$USER_ID:$GROUP_ID"
33+
command: [npm, run, server]
34+
volumes: [".:/app"]
35+
working_dir: /app
36+
# ...
37+
```
38+
39+
## Extending for production
40+
When running this image in a production setting, you should set up a few things:
41+
42+
* Create a user that your application will run under
43+
* Make sure that user will be the default user
44+
* Set the `ROOT_SWITCH_USER` environment variable to your user as well to
45+
prevent the application accidentally running as root
46+
* Copy the full appllication and its dependencies into the image
47+
* Set a command that will run the application
48+
49+
See for example the Dockerfile below:
50+
51+
```Dockerfile
52+
FROM ghcr.io/tweedegolf/node:lts
53+
RUN useradd -C Application -m -U app
54+
ENV ROOT_SWITCH_USER app
55+
ENV NODE_ENV production
56+
COPY --chown=app:app ./build /opt/application
57+
WORKDIR /opt/application
58+
CMD ["node", "index.js"]
59+
USER app
60+
```
61+
62+
[debian image]: https://github.com/tweedegolf/docker-debian-image

0 commit comments

Comments
 (0)