Skip to content

Commit f0e42b8

Browse files
committed
Handle specific hugo version instead of the local one
Signed-off-by: Alban Dericbourg <alban@dericbourg.dev>
1 parent 02b3f4b commit f0e42b8

8 files changed

Lines changed: 189 additions & 7 deletions

File tree

.github/workflows/hugo.yaml

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -31,20 +31,23 @@ jobs:
3131
# Build job
3232
build:
3333
runs-on: ubuntu-latest
34-
env:
35-
HUGO_VERSION: 0.148.2
3634
steps:
35+
- name: Checkout
36+
uses: actions/checkout@v4
37+
with:
38+
submodules: recursive
39+
fetch-depth: 0
40+
- name: Read Hugo version
41+
id: hugo-version
42+
run: echo "version=$(cat .hugo-version)" >> $GITHUB_OUTPUT
3743
- name: Install Hugo CLI
44+
env:
45+
HUGO_VERSION: ${{ steps.hugo-version.outputs.version }}
3846
run: |
3947
wget -O ${{ runner.temp }}/hugo.deb https://github.com/gohugoio/hugo/releases/download/v${HUGO_VERSION}/hugo_extended_${HUGO_VERSION}_linux-amd64.deb \
4048
&& sudo dpkg -i ${{ runner.temp }}/hugo.deb
4149
- name: Install Dart Sass
4250
run: sudo snap install dart-sass
43-
- name: Checkout
44-
uses: actions/checkout@v4
45-
with:
46-
submodules: recursive
47-
fetch-depth: 0
4851
- name: Setup Pages
4952
id: pages
5053
uses: actions/configure-pages@v5

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,3 +4,6 @@
44
.hugo_build.lock
55
/node_modules
66
public/
7+
8+
# Generated env file for docker-compose
9+
.env

.go-version

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
1.24.4

.hugo-version

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
0.148.2

Dockerfile

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
FROM debian:bookworm-slim
2+
3+
ARG HUGO_VERSION
4+
ARG GO_VERSION
5+
ARG TARGETARCH
6+
7+
RUN apt-get update && apt-get install -y --no-install-recommends \
8+
ca-certificates \
9+
wget \
10+
git \
11+
&& rm -rf /var/lib/apt/lists/*
12+
13+
RUN ARCH=$(echo ${TARGETARCH} | sed 's/amd64/amd64/;s/arm64/arm64/') && \
14+
wget -O /tmp/go.tar.gz "https://go.dev/dl/go${GO_VERSION}.linux-${ARCH}.tar.gz" && \
15+
tar -C /usr/local -xzf /tmp/go.tar.gz && \
16+
rm /tmp/go.tar.gz
17+
18+
ENV PATH="/usr/local/go/bin:${PATH}"
19+
20+
RUN ARCH=$(echo ${TARGETARCH} | sed 's/amd64/amd64/;s/arm64/arm64/') && \
21+
wget -O /tmp/hugo.deb "https://github.com/gohugoio/hugo/releases/download/v${HUGO_VERSION}/hugo_extended_${HUGO_VERSION}_linux-${ARCH}.deb" && \
22+
dpkg -i /tmp/hugo.deb && \
23+
rm /tmp/hugo.deb
24+
25+
WORKDIR /site
26+
EXPOSE 1313
27+
28+
CMD ["hugo", "server", "--bind", "0.0.0.0"]

Makefile

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
HUGO_VERSION := $(shell cat .hugo-version)
2+
GO_VERSION := $(shell cat .go-version)
3+
export HUGO_VERSION GO_VERSION
4+
5+
.PHONY: build serve shell clean env
6+
7+
env:
8+
@echo "HUGO_VERSION=$(HUGO_VERSION)" > .env
9+
@echo "GO_VERSION=$(GO_VERSION)" >> .env
10+
11+
build: env
12+
docker compose build
13+
14+
serve: build
15+
docker compose up hugo
16+
17+
shell: build
18+
docker compose run --rm shell
19+
20+
clean:
21+
docker compose down --rmi local

README.md

Lines changed: 101 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,101 @@
1+
# dericbourg.dev
2+
3+
Professional website, built with [Hugo](https://gohugo.io/).
4+
5+
## Prerequisites
6+
7+
- [Docker](https://docs.docker.com/get-docker/) and Docker Compose
8+
- Make (optional, but recommended)
9+
10+
## Local development
11+
12+
### With Make (recommended)
13+
14+
```bash
15+
# Start the development server (http://localhost:1313)
16+
make serve
17+
18+
# Get an interactive shell with Hugo
19+
make shell
20+
21+
# Rebuild the Docker image
22+
make build
23+
24+
# Clean up Docker images
25+
make clean
26+
```
27+
28+
### Without Make
29+
30+
```bash
31+
# Generate the .env file (needed once)
32+
echo "HUGO_VERSION=$(cat .hugo-version)" > .env
33+
echo "GO_VERSION=$(cat .go-version)" >> .env
34+
35+
# Start the development server
36+
docker compose up hugo
37+
38+
# Get an interactive shell
39+
docker compose run --rm shell
40+
```
41+
42+
### Useful Hugo commands
43+
44+
Once in the shell (`make shell`), you can use Hugo directly:
45+
46+
```bash
47+
# Create new content
48+
hugo new content/posts/my-article.md
49+
50+
# Build the site (generates in /public)
51+
hugo
52+
53+
# Build with minification
54+
hugo --minify
55+
```
56+
57+
## Version management
58+
59+
The Hugo and Go versions are centralized in dedicated files:
60+
61+
| File | Description |
62+
|------|-------------|
63+
| `.hugo-version` | Hugo version (used by Makefile and GitHub Actions) |
64+
| `.go-version` | Go version (required for Hugo Modules) |
65+
66+
To update versions:
67+
68+
```bash
69+
echo "0.150.0" > .hugo-version
70+
echo "1.24.5" > .go-version
71+
make build # Rebuild the Docker image
72+
```
73+
74+
## Deployment
75+
76+
The site is automatically deployed to GitHub Pages on push to the `main` branch.
77+
78+
### GitHub Actions workflow
79+
80+
The `.github/workflows/hugo.yaml` file defines the deployment pipeline:
81+
82+
1. **Checkout**: Retrieves the source code with submodules (theme)
83+
2. **Read Hugo version**: Reads `.hugo-version` to ensure consistency with local development
84+
3. **Install Hugo**: Downloads and installs Hugo Extended
85+
4. **Build**: Generates the static site with `hugo --gc --minify`
86+
5. **Deploy**: Publishes to GitHub Pages
87+
88+
## Project structure
89+
90+
```
91+
.
92+
├── .hugo-version # Hugo version (single source of truth)
93+
├── .go-version # Go version (for Hugo Modules)
94+
├── hugo.toml # Hugo configuration
95+
├── go.mod # Hugo Modules dependencies
96+
├── content/ # Site content (Markdown)
97+
├── static/ # Static files (images, etc.)
98+
├── Dockerfile # Docker image for Hugo + Go
99+
├── docker-compose.yaml # Docker services (hugo, shell)
100+
└── Makefile # Development commands
101+
```

docker-compose.yaml

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
services:
2+
hugo:
3+
build:
4+
context: .
5+
args:
6+
HUGO_VERSION: ${HUGO_VERSION}
7+
GO_VERSION: ${GO_VERSION}
8+
volumes:
9+
- .:/site
10+
ports:
11+
- "1313:1313"
12+
command: hugo server --bind 0.0.0.0 --disableFastRender
13+
14+
shell:
15+
build:
16+
context: .
17+
args:
18+
HUGO_VERSION: ${HUGO_VERSION}
19+
GO_VERSION: ${GO_VERSION}
20+
volumes:
21+
- .:/site
22+
stdin_open: true
23+
tty: true
24+
command: /bin/bash

0 commit comments

Comments
 (0)