From 9d1d3323cd79989ffc7485370c9edbf728b594e5 Mon Sep 17 00:00:00 2001 From: Patrice Chalin Date: Sat, 16 Nov 2024 08:11:29 -0500 Subject: [PATCH] Container build with NPM deps and fixed build cmd --- .dockerignore | 2 ++ Dockerfile | 5 +++-- Makefile | 10 ++++++++-- 3 files changed, 13 insertions(+), 4 deletions(-) diff --git a/.dockerignore b/.dockerignore index 1d085cacc9..be2f2c26c4 100644 --- a/.dockerignore +++ b/.dockerignore @@ -1 +1,3 @@ ** +!package.json +!package-lock.json diff --git a/Dockerfile b/Dockerfile index 1c95bbed12..14f7d4dad8 100644 --- a/Dockerfile +++ b/Dockerfile @@ -31,8 +31,7 @@ RUN apk add --no-cache \ git \ openssh-client \ rsync \ - npm && \ - npm install -D autoprefixer postcss-cli + npm RUN mkdir -p /var/hugo && \ addgroup -Sg 1000 hugo && \ @@ -43,6 +42,8 @@ RUN mkdir -p /var/hugo && \ COPY --from=0 /go/bin/hugo /usr/local/bin/hugo WORKDIR /src +COPY package.json package-lock.json ./ +RUN npm ci USER hugo:hugo diff --git a/Makefile b/Makefile index cff50172cb..b97e9a45b3 100644 --- a/Makefile +++ b/Makefile @@ -97,11 +97,17 @@ docker-push: ## Build a multi-architecture image and push that into the registry rm Dockerfile.cross container-build: module-check - $(CONTAINER_RUN) --read-only --mount type=tmpfs,destination=/tmp,tmpfs-mode=01777 $(CONTAINER_IMAGE) sh -c "npm ci && hugo --minify --environment development" + mkdir -p public + $(CONTAINER_RUN) --read-only \ + --mount type=tmpfs,destination=/tmp,tmpfs-mode=01777 \ + --mount type=bind,source=$(CURDIR)/public,target=/src/public $(CONTAINER_IMAGE) \ + hugo --cleanDestinationDir --buildDrafts --buildFuture --environment preview --noBuildLock # no build lock to allow for read-only mounts container-serve: module-check ## Boot the development server using container. - $(CONTAINER_RUN) --cap-drop=ALL --cap-add=AUDIT_WRITE --read-only --mount type=tmpfs,destination=/tmp,tmpfs-mode=01777 -p 1313:1313 $(CONTAINER_IMAGE) hugo server --buildFuture --environment development --bind 0.0.0.0 --destination /tmp/hugo --cleanDestinationDir --noBuildLock + $(CONTAINER_RUN) --cap-drop=ALL --cap-add=AUDIT_WRITE --read-only \ + --mount type=tmpfs,destination=/tmp,tmpfs-mode=01777 -p 1313:1313 $(CONTAINER_IMAGE) \ + hugo server --buildFuture --environment development --bind 0.0.0.0 --destination /tmp/public --cleanDestinationDir --noBuildLock test-examples: scripts/test_examples.sh install