Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 6 additions & 4 deletions build-locally.sh
Original file line number Diff line number Diff line change
Expand Up @@ -59,17 +59,19 @@ REPOS=(
serve_site() {
local site_dir="$DOC_WORK/generator/_site"
local server_js="$WORK_DIR/infra/services/docs-cfengine-com/search-server/server.js"
local flex_pkg="$WORK_DIR/nt-docs/scripts/search/index/package.json"
local search_deps="$WORK_DIR/nt-docs/scripts/search/server"
local label="$BRANCH"
[ -n "$LTS_VERSION" ] && label="lts"

if [ ! -f "$server_js" ] || [ ! -d "$site_dir/assets/searchIndex" ]; then
echo "error: no built site (or no infra checkout) under tmp/; run a full build first" >&2
if [ ! -f "$server_js" ] || [ ! -f "$search_deps/package-lock.json" ] || [ ! -d "$site_dir/assets/searchIndex" ]; then
echo "error: no built site (or no infra/nt-docs checkout) under tmp/; run a full build first" >&2
return 1
fi

echo "==> Building serve image $SERVE_IMAGE"
"$DOCKER" build --tag "$SERVE_IMAGE" "$SCRIPT_DIR/generator/serve"
"$DOCKER" build --tag "$SERVE_IMAGE" \
--build-context search-deps="$search_deps" \
"$SCRIPT_DIR/generator/serve"

echo "==> Starting serve container $SERVE_CONTAINER on port $SITE_PORT"
"$DOCKER" rm -f "$SERVE_CONTAINER" >/dev/null 2>&1 || true
Expand Down
15 changes: 8 additions & 7 deletions generator/serve/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -4,20 +4,21 @@
# Apache does in production. The search server itself is the server.js
# from NorthernTechHQ/infra.
#
# Expected build context (see serve_site in build-locally.sh):
# search-deps nt-docs scripts/search/server (package.json + lock)
#
# Expected mounts (see serve_site in build-locally.sh):
# /site built _site (nginx root)
# /docs/<branch> the same _site, where server.js looks for
# <branch>/assets/searchIndex under DOCS_PATH=/docs
# /search/server.js search server from the infra repo
FROM nginx:alpine

# flexsearch must match the version the search index was built with
# (nt-docs scripts/search/index)
ARG FLEXSEARCH_VERSION=0.7.31
RUN apk add --no-cache nodejs npm \
&& npm install --global "flexsearch@${FLEXSEARCH_VERSION}"
RUN apk add --no-cache nodejs npm

COPY --from=search-deps package.json package-lock.json /search/
RUN npm ci --prefix /search --omit=dev

COPY nginx.conf /etc/nginx/conf.d/default.conf

# server.js resolves flexsearch from the global node_modules via NODE_PATH
CMD ["sh", "-c", "NODE_PATH=$(npm root -g) node /search/server.js & exec nginx -g 'daemon off;'"]
CMD ["sh", "-c", "node /search/server.js & exec nginx -g 'daemon off;'"]
Loading