Skip to content

Commit b75ad4b

Browse files
authored
Docker-based build process (#34)
moves to a docker-based, reproducible build environment
1 parent e8c57d8 commit b75ad4b

File tree

4 files changed

+39
-38
lines changed

4 files changed

+39
-38
lines changed

.github/workflows/deploy.yml

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -14,15 +14,8 @@ jobs:
1414
runs-on: ubuntu-22.04
1515
steps:
1616
- uses: actions/checkout@v4
17-
- name: Install requirements
18-
run: |
19-
pip install -r requirements.txt
20-
wget https://github.com/gohugoio/hugo/releases/download/v0.128.2/hugo_extended_0.128.2_linux-amd64.deb -O /tmp/hugo.deb
21-
sudo dpkg -i /tmp/hugo.deb
2217
- name: Build Website
23-
run: |
24-
./grabrepos.py
25-
hugo
18+
run: ./build.sh
2619
- if: github.event_name == 'push' || github.event_name == 'workflow_dispatch' || github.event_name == 'repository_dispatch' && always()
2720
name: Deploy website
2821
uses: peaceiris/actions-gh-pages@v4

README.md

Lines changed: 10 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -4,34 +4,24 @@ This repository contains the website sources for the [Homie Website](https://hom
44
including the online validator javascript tool.
55

66
The build is triggered by a change in any of the Homie specification respositories
7-
and performed by Travis CI. The resulting webpage is uploaded to
7+
and performed by GitHub Actions. The resulting webpage is uploaded to
88
https://github.com/homieiot/homieiot.github.io/tree/master and is served by GitHub.
99

1010
The generator in use is [Hugo](https://gohugo.io/).
1111

12-
You can just call the `./build.sh` script within this directory
13-
and find the page in the output directory `site`.
12+
## How to build locally
1413

15-
## Manually generate the webpage
14+
Just call the `./build.sh` script within this repository. The built website
15+
will be available in the `./public` directory.
1616

17-
You need Hugo in the extended version (with sass/scss support).
17+
The only dependency required by the `./build.sh` script is [Docker],
18+
which is used to create a builder image with the actual dependencies
19+
required to build the website (Git, Hugo, Python and the dependencies
20+
for the `./grabrepos.py` script).
1821

19-
The git grab utility requires python3. For a non-root environment,
20-
it is recommended to create a python virtual environment:
22+
The builder image is then used to build the website.
2123

22-
```sh
23-
python3 -m venv dependencies
24-
source dependencies/bin/activate
25-
```
26-
27-
Install the dependencies `gitpython`, `pyyaml`,
28-
then run the git grab utility and and hugo last:
29-
30-
```
31-
pip install -r requirements.txt
32-
./grabrepos.py
33-
hugo
34-
```
24+
[Docker]: https://www.docker.com
3525

3626
## Upload a manually generated webpage
3727

build.sh

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,10 @@
1-
#!/usr/bin/env bash
2-
set -euo pipefail
1+
#!/usr/bin/env sh
2+
set -euo
33

4-
echo "Manually building webpage"
4+
# As long as no changes are made to the Dockerfile, the built image
5+
# will be cached and reused in all builds after the first one.
6+
docker build -t homie-website-builder -f ./docker/Dockerfile-builder .
57

6-
python3 -m venv dependencies
7-
source dependencies/bin/activate
8-
pip install -r requirements.txt
9-
./grabrepos.py
10-
hugo
11-
12-
echo "Webpage available at ./site"
8+
# No need for a dedicated entrypoint script, we can specify the commands
9+
# to run as arguments to `docker run`. This keeps our image more flexible.
10+
docker run --rm -v "$(pwd):/data" homie-website-builder sh -c "cd /data && ./grabrepos.py && hugo"

docker/Dockerfile-builder

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
2+
# This Dockerfile is not meant to be used directly but, rather,
3+
# through the ../build.sh script.
4+
5+
# Build upon an official Python image using Alpine Linux as its base, which
6+
# tends to result in smaller images and faster builds. As we want our build
7+
# environment to be as reproducible as possible, we pin both the Python version
8+
# and the Alpine Linux version to ensure consistent builds.
9+
FROM python:3.12-alpine3.21
10+
11+
# Update Alpine's package list.
12+
RUN apk update
13+
14+
# Install OS-level dependencies (Git and Hugo). The versions of these packages
15+
# are implicitly pinned to the Alpine Linux version used in the FROM statement.
16+
RUN apk add --no-cache git hugo
17+
18+
# Copy list of Python dependencies and install them.
19+
COPY ./requirements.txt /requirements.txt
20+
RUN pip install -r /requirements.txt

0 commit comments

Comments
 (0)