Repository navigation
Expand file tree
/
Copy pathMakefile
More file actions
93 lines (77 loc) · 4.01 KB
/
Copy pathMakefile
File metadata and controls
93 lines (77 loc) · 4.01 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
## ========================================
## Commands for building and testing OMF website deployment
## ========================================
# Settings
MAKEFILE_COMMANDS=Makefile $(wildcard *.mk)
UID=$(shell id -u)
GID=$(shell id -g)
DOCKER_COMPOSE=docker compose
HUGO_SERVICE=hugo
HUGO_RUN_SH=$(DOCKER_COMPOSE) run --rm --no-deps --entrypoint sh
HUGO_IMAGE=openmodelingfoundation/omf:latest
HUGO_CACHE_CONTAINER_DIR ?= /src/.hugo_cache
HUGO_ISOLATED_CACHE_HOST_DIR ?= $(CURDIR)/.hugo_cache
HUGO_ISOLATED_CACHE_CONTAINER_DIR ?= /tmp/.hugo_cache
RENDER_OUTPUT_DIR ?= /src/public
RENDER_BASE_URL ?=
HUGO_USER_ENV=--user "$(UID):$(GID)" -e HOME=/tmp -e npm_config_cache=/tmp/.npm
PUBLICATIONS_BIB_PATH ?= assets/bibliographies/publications.bib
PUBLICATIONS_JSON_PATH ?= data/publications.json
# Controls
.PHONY : all commands build clean stop serve render render-site render-site-isolated shell publications-json deps-docsy deps-pack deps-lock deps-fonts
all : commands
## commands : show all commands.
commands :
@grep -h -E '^##' ${MAKEFILE_COMMANDS} | sed -e 's/## //g'
## build : build files but do not run a server.
build :
$(DOCKER_COMPOSE) build --pull $(HUGO_SERVICE)
## serve : start and run a local server.
serve : build
@$(DOCKER_COMPOSE) up -d $(HUGO_SERVICE)
## render : run the production-style site render locally.
render :
$(HUGO_RUN_SH) $(HUGO_SERVICE) -c 'rm -f /src/.hugo_build.lock && rm -rf /src/public /src/resources/_gen'
$(MAKE) render-site
## render-site : run the shared production build script in the container.
render-site : build
$(HUGO_RUN_SH) $(HUGO_USER_ENV) \
-e HUGO_CACHEDIR="$(HUGO_CACHE_CONTAINER_DIR)" \
-e OUTPUT_DIR="$(RENDER_OUTPUT_DIR)" \
-e BASE_URL="$(RENDER_BASE_URL)" \
$(HUGO_SERVICE) -c '.github/scripts/build-site.sh'
## render-site-isolated : run production-style render in isolated container workspace with persistent cache.
render-site-isolated : build
@mkdir -p "$(HUGO_ISOLATED_CACHE_HOST_DIR)"
docker run --rm --entrypoint sh \
-v "$(CURDIR)":/workspace:ro \
-v "$(HUGO_ISOLATED_CACHE_HOST_DIR)":"$(HUGO_ISOLATED_CACHE_CONTAINER_DIR)":rw \
-w /tmp \
$(HUGO_IMAGE) \
-lc 'cp -a /workspace /tmp/src && git config --global --add safe.directory /tmp/src && cd /tmp/src && ln -s /tmp/node_modules node_modules && hugo build --gc --minify --cacheDir "$(HUGO_ISOLATED_CACHE_CONTAINER_DIR)" -d /tmp/public --noBuildLock'
## publications-json: generate Hugo data/publications.json from BibTeX.
publications-json : build
$(HUGO_RUN_SH) $(HUGO_USER_ENV) $(HUGO_SERVICE) -c 'uv run .github/scripts/bibtex_to_json.py --input "$(PUBLICATIONS_BIB_PATH)" --output "$(PUBLICATIONS_JSON_PATH)"'
## deps-docsy : update the Docsy Hugo module; set DOCSY_VERSION=vX.Y.Z.
deps-docsy :
@test -n "$(DOCSY_VERSION)" || { echo 'Set DOCSY_VERSION=vX.Y.Z'; exit 1; }
$(HUGO_RUN_SH) $(HUGO_USER_ENV) $(HUGO_SERVICE) -c 'git config --global --add safe.directory /src && hugo mod get github.com/google/docsy/theme@$(DOCSY_VERSION)'
## deps-pack : regenerate Hugo module npm workspace using the existing image.
deps-pack :
$(HUGO_RUN_SH) $(HUGO_USER_ENV) $(HUGO_SERVICE) -c 'git config --global --add safe.directory /src && hugo mod npm pack'
## deps-lock : update npm lockfile using the existing image.
deps-lock :
$(HUGO_RUN_SH) $(HUGO_USER_ENV) $(HUGO_SERVICE) -c 'npm install --package-lock-only --ignore-scripts --no-audit --no-fund'
## deps-fonts : regenerate pinned self-hosted fonts in the Hugo container.
deps-fonts :
$(HUGO_RUN_SH) $(HUGO_SERVICE) -c 'apk add --no-cache bash curl openssl su-exec && su-exec "$(UID):$(GID)" env HOME=/tmp npm_config_cache=/tmp/.npm bash .github/scripts/download-fonts.sh'
## shell : open a hugo shell
shell : build
$(DOCKER_COMPOSE) run --rm --no-deps $(HUGO_SERVICE) shell
## stop : stop the docker server and clean up
stop :
$(DOCKER_COMPOSE) down -v
## clean : clean up junk files.
clean :
@rm -rf ./resources/_gen
@find . \( -name .DS_Store -o -name '*~' \) -print -exec rm {} +