From cbe13f1d84ee02bb7ea1006e4170f9b0f9d443cf Mon Sep 17 00:00:00 2001 From: 0x1d Date: Mon, 27 Oct 2025 15:19:10 +0100 Subject: [PATCH] feat: add Docker build --- .dockerignore | 11 +++++++++++ Dockerfile | 41 +++++++++++++++++++++++++++++++++++++++++ Makefile | 40 ++++++++++++++++++++++++++++++++++++++++ 3 files changed, 92 insertions(+) create mode 100644 .dockerignore create mode 100644 Dockerfile create mode 100644 Makefile diff --git a/.dockerignore b/.dockerignore new file mode 100644 index 0000000..ae5315f --- /dev/null +++ b/.dockerignore @@ -0,0 +1,11 @@ +.git +.gitignore +.cursor +*.md +node_modules +README.md +docs +test +openapitools.json +*.backup + diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..5b160e1 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,41 @@ +# Build stage +FROM node:20-alpine AS builder + +WORKDIR /app + +# Copy package files +COPY package*.json ./ + +# Install dependencies +RUN npm ci --only=production + +# Runtime stage +FROM node:20-alpine + +# Install wget for health checks +RUN apk --no-cache add wget + +WORKDIR /app + +# Copy dependencies from builder +COPY --from=builder /app/node_modules ./node_modules + +# Copy application files +COPY package*.json ./ +COPY index.js index-standalone.js ./ +COPY public ./public +COPY src ./src + +# Create non-root user (let Alpine assign available GID/UID) +RUN addgroup spore && \ + adduser -D -s /bin/sh -G spore spore && \ + chown -R spore:spore /app + +USER spore + +# Expose port +EXPOSE 3000 + +# Run the application +CMD ["node", "index.js"] + diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..a445127 --- /dev/null +++ b/Makefile @@ -0,0 +1,40 @@ +.PHONY: install build run clean docker-build docker-run docker-push + +# Install dependencies +install: + npm install + +# Build the application (if needed) +build: install + +# Run the application +run: + node index.js + +# Start in development mode +dev: + node index.js + +# Clean build artifacts +clean: + rm -rf node_modules + rm -f package-lock.json + +# Docker variables +DOCKER_REGISTRY ?= +IMAGE_NAME = wirelos/spore-ui +IMAGE_TAG ?= latest +FULL_IMAGE_NAME = $(if $(DOCKER_REGISTRY),$(DOCKER_REGISTRY)/$(IMAGE_NAME),$(IMAGE_NAME)):$(IMAGE_TAG) + +# Build Docker image +docker-build: + docker build -t $(FULL_IMAGE_NAME) . + +# Run Docker container +docker-run: + docker run -p 3000:3000 --rm $(FULL_IMAGE_NAME) + +# Push Docker image +docker-push: + docker push $(FULL_IMAGE_NAME) +