-
Notifications
You must be signed in to change notification settings - Fork 36
Expand file tree
/
Copy pathMakefile
More file actions
76 lines (64 loc) · 2.92 KB
/
Makefile
File metadata and controls
76 lines (64 loc) · 2.92 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
## ========================================
## 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
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 && 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)"'
## 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 {} +