From 5bb197cd304d6cab32c39782b60391f9b399541b Mon Sep 17 00:00:00 2001 From: kj_sh604 Date: Thu, 7 May 2026 00:15:11 -0400 Subject: refactor: kj-ify the repo with a makefile --- .dockerignore | 4 ++++ Dockerfile | 22 ++++++++------------- Makefile | 62 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 74 insertions(+), 14 deletions(-) create mode 100644 Makefile diff --git a/.dockerignore b/.dockerignore index 6472839..ce47f14 100644 --- a/.dockerignore +++ b/.dockerignore @@ -17,3 +17,7 @@ **/build **/dist **/node_modules + +# include prebuilt app assets for static serving image +!excalidraw-app/build/ +!excalidraw-app/build/** diff --git a/Dockerfile b/Dockerfile index 2716803..91a6401 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,19 +1,13 @@ -FROM node:18 AS build +FROM ubuntu:22.04 -WORKDIR /opt/node_app +WORKDIR /srv/www -COPY . . +RUN apt-get update \ + && apt-get install -y --no-install-recommends python3 \ + && rm -rf /var/lib/apt/lists/* -# do not ignore optional dependencies: -# Error: Cannot find module @rollup/rollup-linux-x64-gnu -RUN yarn --network-timeout 600000 +COPY ./excalidraw-app/build/ /srv/www/ -ARG NODE_ENV=production +EXPOSE 8000 -RUN yarn build:app:docker - -FROM nginx:1.27-alpine - -COPY --from=build /opt/node_app/excalidraw-app/build /usr/share/nginx/html - -HEALTHCHECK CMD wget -q -O /dev/null http://localhost || exit 1 +CMD ["python3", "-m", "http.server", "8000"] \ No newline at end of file diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..1347b73 --- /dev/null +++ b/Makefile @@ -0,0 +1,62 @@ +SHELL := /bin/sh + +IMAGE ?= kj-diagramming:latest +BUILD_DIR := excalidraw-app/build +PROJECT_MARKER := excalidraw-app/App.tsx +CONTAINER_ENGINE := $(shell if command -v docker >/dev/null 2>&1; then printf '%s' docker; elif command -v podman >/dev/null 2>&1; then printf '%s' podman; fi) + +.PHONY: help build clean container check-yarn check-container-engine check-build-dir + +help: + @echo "targets:" + @echo " make build build static assets into $(BUILD_DIR)" + @echo " make clean rm $(BUILD_DIR) (with checks)" + @echo " make container build kj-diagramming image" + +check-yarn: + @if ! command -v yarn >/dev/null 2>&1; then \ + echo "warning: yarn is not installed."; \ + echo "install yarn to use: make build"; \ + fi + +check-container-engine: + @if [ -z "$(CONTAINER_ENGINE)" ]; then \ + echo "error: neither docker nor podman is installed."; \ + echo "install docker or podman, then run: make container"; \ + exit 1; \ + fi + @echo "using container engine: $(CONTAINER_ENGINE)" + +check-build-dir: + @if [ ! -d "$(BUILD_DIR)" ]; then \ + echo "error: $(BUILD_DIR) is missing."; \ + echo "run: make build"; \ + exit 1; \ + fi + +build: + @if ! command -v yarn >/dev/null 2>&1; then \ + echo "error: yarn is not installed."; \ + echo "install yarn, then run: make build"; \ + exit 1; \ + fi + @echo "building static assets into $(BUILD_DIR)..." + @NODE_ENV=production yarn build:app:docker + +clean: + @if [ -f "$(PROJECT_MARKER)" ] || [ -d "$(BUILD_DIR)" ]; then \ + if [ -d "$(BUILD_DIR)" ]; then \ + echo "removing $(BUILD_DIR)..."; \ + rm -rf "$(BUILD_DIR)"; \ + else \ + echo "nothing to clean: $(BUILD_DIR) does not exist."; \ + fi; \ + else \ + echo "safety check failed: not in kj-diagramming repo root and $(BUILD_DIR) was not found."; \ + echo "refusing to run rm."; \ + exit 1; \ + fi + +container: check-yarn check-container-engine clean build + @echo "building image $(IMAGE)..." + @$(CONTAINER_ENGINE) build -f Dockerfile -t "$(IMAGE)" . \ No newline at end of file -- cgit v1.2.3