Fix the Dockerfile (#630)

# Changelog

The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/).

## Added

- Ignore the `.pnpm-store` directory generated by the `pnpm` package manager.
- Make the `eleventy` command render changes incrementally when in dev ("serve") mode.

## Changed

- Rename the npm script `serve` to `dev` to improve clarity.
- Update documentation to reflect new npm script name and Dockerfile volume mount point.

## Fixed

- Update the `Dockerfile` to fix errors when building the documentation container.

---

## 1st problem

The current version of the `README.md` tells to run this command:

`docker build -t Codeberg/Documentation-server .`

Unfortunately, it returns this error:

```bash
docker build -t Codeberg/Documentation-server .
[+] Building 0.0s (0/0) docker:default
ERROR: invalid tag "Codeberg/Documentation-server": repository name must be lowercase
```

## 2nd problem

If you try to build an image with the current version of `Dockerfile`, this error occurs:

```bash
[+] Building 2.7s (5/10)                                docker:default
 => [internal] load build definition from Dockerfile              0.0s
 => => transferring dockerfile: 409B                              0.0s
 => [internal] load metadata for docker.io/library/node:16.15.1-  1.1s
 => [internal] load .dockerignore                                 0.0s
 => => transferring context: 2B                                   0.0s
 => CACHED [1/7] FROM docker.io/library/node:16.15.1-stretch-sli  0.0s
 => ERROR [2/7] RUN apt-get update && apt-get -y upgrade          1.4s
------
 > [2/7] RUN apt-get update && apt-get -y upgrade:
0.235 Ign:1 http://security.debian.org/debian-security stretch/updates InRelease
0.278 Ign:2 http://security.debian.org/debian-security stretch/updates Release
0.280 Ign:3 http://deb.debian.org/debian stretch InRelease
0.293 Ign:4 http://security.debian.org/debian-security stretch/updates/main all Packages
0.308 Ign:5 http://security.debian.org/debian-security stretch/updates/main amd64 Packages
0.320 Ign:6 http://deb.debian.org/debian stretch-updates InRelease
0.323 Ign:4 http://security.debian.org/debian-security stretch/updates/main all Packages
0.339 Ign:5 http://security.debian.org/debian-security stretch/updates/main amd64 Packages
0.356 Ign:4 http://security.debian.org/debian-security stretch/updates/main all Packages
0.363 Ign:7 http://deb.debian.org/debian stretch Release
0.378 Ign:5 http://security.debian.org/debian-security stretch/updates/main amd64 Packages
0.408 Ign:4 http://security.debian.org/debian-security stretch/updates/main all Packages
0.415 Ign:8 http://deb.debian.org/debian stretch-updates Release
0.441 Ign:5 http://security.debian.org/debian-security stretch/updates/main amd64 Packages
0.463 Ign:9 http://deb.debian.org/debian stretch/main amd64 Packages
0.465 Ign:4 http://security.debian.org/debian-security stretch/updates/main all Packages
0.482 Ign:5 http://security.debian.org/debian-security stretch/updates/main amd64 Packages
0.496 Ign:4 http://security.debian.org/debian-security stretch/updates/main all Packages
0.503 Ign:10 http://deb.debian.org/debian stretch/main all Packages
0.511 Err:5 http://security.debian.org/debian-security stretch/updates/main amd64 Packages
0.511   404  Not Found [IP: 151.101.2.132 80]
0.542 Ign:11 http://deb.debian.org/debian stretch-updates/main all Packages
0.583 Ign:12 http://deb.debian.org/debian stretch-updates/main amd64 Packages
0.623 Ign:9 http://deb.debian.org/debian stretch/main amd64 Packages
0.662 Ign:10 http://deb.debian.org/debian stretch/main all Packages
0.701 Ign:11 http://deb.debian.org/debian stretch-updates/main all Packages
0.741 Ign:12 http://deb.debian.org/debian stretch-updates/main amd64 Packages
0.781 Ign:9 http://deb.debian.org/debian stretch/main amd64 Packages
0.825 Ign:10 http://deb.debian.org/debian stretch/main all Packages
0.872 Ign:11 http://deb.debian.org/debian stretch-updates/main all Packages
0.912 Ign:12 http://deb.debian.org/debian stretch-updates/main amd64 Packages
0.953 Ign:9 http://deb.debian.org/debian stretch/main amd64 Packages
0.994 Ign:10 http://deb.debian.org/debian stretch/main all Packages
1.033 Ign:11 http://deb.debian.org/debian stretch-updates/main all Packages
1.073 Ign:12 http://deb.debian.org/debian stretch-updates/main amd64 Packages
1.112 Ign:9 http://deb.debian.org/debian stretch/main amd64 Packages
1.152 Ign:10 http://deb.debian.org/debian stretch/main all Packages
1.193 Ign:11 http://deb.debian.org/debian stretch-updates/main all Packages
1.233 Ign:12 http://deb.debian.org/debian stretch-updates/main amd64 Packages
1.274 Err:9 http://deb.debian.org/debian stretch/main amd64 Packages
1.274   404  Not Found
1.316 Ign:10 http://deb.debian.org/debian stretch/main all Packages
1.357 Ign:11 http://deb.debian.org/debian stretch-updates/main all Packages
1.397 Err:12 http://deb.debian.org/debian stretch-updates/main amd64 Packages
1.397   404  Not Found
1.401 Reading package lists...
1.407 W: The repository 'http://security.debian.org/debian-security stretch/updates Release' does not have a Release file.
1.407 W: The repository 'http://deb.debian.org/debian stretch Release' does not have a Release file.
1.407 W: The repository 'http://deb.debian.org/debian stretch-updates Release' does not have a Release file.
1.407 E: Failed to fetch http://security.debian.org/debian-security/dists/stretch/updates/main/binary-amd64/Packages  404  Not Found [IP: 151.101.2.132 80]
1.407 E: Failed to fetch http://deb.debian.org/debian/dists/stretch/main/binary-amd64/Packages  404  Not Found
1.407 E: Failed to fetch http://deb.debian.org/debian/dists/stretch-updates/main/binary-amd64/Packages  404  Not Found
1.407 E: Some index files failed to download. They have been ignored, or old ones used instead.
------
Dockerfile:3
--------------------
   1 |     FROM node:16.15.1-stretch-slim
   2 |
   3 | >>> RUN apt-get update && apt-get -y upgrade
   4 |
   5 |     RUN apt-get install -y git curl
--------------------
ERROR: failed to solve: process "/bin/sh -c apt-get update && apt-get -y upgrade" did not complete successfully: exit code: 100
```

I have fixed both issues and tested building the image and running the container to build the docs site locally.

Reviewed-on: https://codeberg.org/Codeberg/Documentation/pulls/630
Reviewed-by: Gusted <gusted@noreply.codeberg.org>
Co-authored-by: Javier Pérez <walpo@noreply.codeberg.org>
Co-committed-by: Javier Pérez <walpo@noreply.codeberg.org>
This commit is contained in:
Javier Pérez 2025-11-21 21:40:44 +01:00 committed by Gusted
parent 5e35a19745
commit 9a4e3cdc27
6 changed files with 33 additions and 19 deletions

4
.gitignore vendored
View file

@ -3,6 +3,7 @@
_site/ _site/
.cache/ .cache/
# Integrated development environments (IDEs) and text editors # Integrated development environments (IDEs) and text editors
## JetBrains ## JetBrains
.idea/ .idea/
@ -15,6 +16,9 @@ _site/
## npm - Node.js ## npm - Node.js
node_modules/ node_modules/
## pnpm - Node.js
.pnpm-store/
# Web servers # Web servers
## Codeberg Pages ## Codeberg Pages

View file

@ -1,2 +1 @@
pnpm-lock.yaml pnpm-lock.yaml
.pnpm-store/

View file

@ -1,16 +1,21 @@
FROM node:16.15.1-stretch-slim # The main purpose of this Dockerfile is to install the `pnpm` package manager in the official Node.js image
# and use an init script as the entrypoint of a custom image to build and run the documentation site.
FROM node:lts-slim@sha256:0afb7822fac7bf9d7c1bf3b6e6c496dee6b2b64d8dfa365501a3c68e8eba94b2
RUN apt-get update && apt-get -y upgrade EXPOSE 8080/tcp
SHELL [ "bash", "-c" ]
ENTRYPOINT [ "./container-init.sh" ]
RUN apt-get install -y git curl ENV CI="true"
RUN curl -fsSL https://get.pnpm.io/install.sh | sh -
RUN mkdir /opt/documentation && chown node: /opt/documentation # renovate: datasource=npm depName=pnpm
ENV PNPM_VERSION="10.23.0"
RUN apt-get update \
&& DEBIAN_FRONTEND=noninteractive apt-get --assume-yes upgrade \
&& rm --recursive --force /var/lib/apt/lists/*
RUN npm install --global pnpm@${PNPM_VERSION}
USER node USER node
WORKDIR /docs
WORKDIR /opt/documentation
RUN pnpm install
CMD [ "pnpm", "run", "serve"]

View file

@ -28,7 +28,7 @@ You only have to do this once.
Then run Then run
`pnpm run serve` `pnpm run dev`
to start a development web server that by default is listening at `http://localhost:8080`. to start a development web server that by default is listening at `http://localhost:8080`.
@ -48,14 +48,14 @@ You must have a container-engine installed (docker, podman, etc.)
First build the container image: First build the container image:
```shell ```shell
docker build -t Codeberg/Documentation-server . docker build --tag codeberg-docs:dev .
``` ```
You do not have to rebuild the image every time. Once you build the image you can always start the development You do not have to rebuild the image every time. Once you build the image you can always start the development
webserver using the container engine: webserver using the container engine:
```shell ```shell
docker run --rm -v $PWD:/opt/documentation Codeberg/Documentation-server:latest docker run --name "codeberg-docs" --rm --tty --interactive --volume "${PWD}:/docs" --publish "127.0.0.1:8080:8080/tcp" codeberg-docs:dev
``` ```
Use the "External" URL the container outputs on startup to access your documentation. Use the "External" URL the container outputs on startup to access your documentation.
@ -67,9 +67,9 @@ Use `Ctrl-C` to exit / end the container.
The parameters are: The parameters are:
`--rm` removes the container after it's use `--rm` removes the container after it's use
`-v` mounts the current (documentation repository root) folder to `/opt/documentation` in the container. `--volume` mounts the current (documentation repository root) folder to `/docs` in the container.
`Codeberg/Documentation-server:latest` refers to the container image built in the first step (using `docker build`). `codeberg-docs:dev` refers to the container image built in the first step (using `docker build`).
### Build & Deployment ### Build & Deployment

6
container-init.sh Executable file
View file

@ -0,0 +1,6 @@
#!/usr/bin/env bash
# This script allows developers to easily build and preview the
# Codeberg documentation locally when using containers.
pnpm install
pnpm run dev

View file

@ -3,8 +3,8 @@
"description": "The documentation site for Codeberg", "description": "The documentation site for Codeberg",
"private": true, "private": true,
"scripts": { "scripts": {
"build": "rm -rf _site/ && eleventy", "build": "eleventy",
"serve": "eleventy --serve" "dev": "eleventy --serve --incremental"
}, },
"devDependencies": { "devDependencies": {
"@11ty/eleventy": "3.1.2", "@11ty/eleventy": "3.1.2",