diff options
| author | kj_sh604 | 2026-05-07 00:15:11 -0400 |
|---|---|---|
| committer | kj_sh604 | 2026-05-07 00:15:11 -0400 |
| commit | 5bb197cd304d6cab32c39782b60391f9b399541b (patch) | |
| tree | bb47ad11d36dce8a4c8ec4a8d14acd1a0fd72c65 | |
| parent | 52b8d65631f71a51e7118af140855f936c2a4db7 (diff) | |
refactor: kj-ify the repo with a makefile
| -rw-r--r-- | .dockerignore | 4 | ||||
| -rw-r--r-- | Dockerfile | 22 | ||||
| -rw-r--r-- | Makefile | 62 |
3 files changed, 74 insertions, 14 deletions
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/** @@ -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 |
