Add Docker build and run workflow

This commit is contained in:
2026-06-01 15:40:23 -06:00
parent c7fc90204e
commit c84cbcdfba
4 changed files with 117 additions and 0 deletions

10
.dockerignore Normal file
View File

@@ -0,0 +1,10 @@
.git/
node_modules/
dist/
.vite.log
*.log
.DS_Store
Dockerfile
README.md

25
Dockerfile Normal file
View File

@@ -0,0 +1,25 @@
# syntax=docker/dockerfile:1
FROM node:22-alpine AS build
WORKDIR /app
COPY package*.json ./
RUN npm ci
COPY index.html vite.config.js ./
COPY src ./src
RUN npm run build
FROM nginx:1.27-alpine
ENV NOTES_API_UPSTREAM=http://host.docker.internal:8080
COPY nginx.conf.template /etc/nginx/templates/default.conf.template
COPY --from=build /app/dist /usr/share/nginx/html
EXPOSE 80
HEALTHCHECK --interval=30s --timeout=3s --start-period=5s --retries=3 \
CMD wget -qO- http://127.0.0.1/ >/dev/null || exit 1

56
Makefile Normal file
View File

@@ -0,0 +1,56 @@
IMAGE_NAME ?= notes-vault-client
IMAGE_TAG ?= latest
CONTAINER_NAME ?= notes-vault-client
HOST_PORT ?= 8081
NOTES_API_UPSTREAM ?= http://host.docker.internal:8080
IMAGE := $(IMAGE_NAME):$(IMAGE_TAG)
.PHONY: help install build docker-build docker-run docker-stop docker-restart docker-logs docker-clean
help:
@echo "Targets:"
@echo " make install Install Node dependencies"
@echo " make build Build the Vite app into dist/"
@echo " make docker-build Build the Docker image"
@echo " make docker-run Run the Docker container"
@echo " make docker-stop Stop the running Docker container"
@echo " make docker-restart Rebuild and restart the Docker container"
@echo " make docker-logs Follow container logs"
@echo " make docker-clean Remove the Docker image"
@echo ""
@echo "Variables:"
@echo " IMAGE_NAME=$(IMAGE_NAME)"
@echo " IMAGE_TAG=$(IMAGE_TAG)"
@echo " CONTAINER_NAME=$(CONTAINER_NAME)"
@echo " HOST_PORT=$(HOST_PORT)"
@echo " NOTES_API_UPSTREAM=$(NOTES_API_UPSTREAM)"
install:
npm ci
build:
npm run build
docker-build:
docker build -t $(IMAGE) .
docker-run:
docker rm -f $(CONTAINER_NAME) >/dev/null 2>&1 || true
docker run --rm -d \
--name $(CONTAINER_NAME) \
-p $(HOST_PORT):80 \
-e NOTES_API_UPSTREAM=$(NOTES_API_UPSTREAM) \
$(IMAGE)
@echo "Running $(IMAGE) at http://localhost:$(HOST_PORT)"
docker-stop:
docker stop $(CONTAINER_NAME)
docker-restart: docker-build docker-run
docker-logs:
docker logs -f $(CONTAINER_NAME)
docker-clean:
docker image rm $(IMAGE)

26
nginx.conf.template Normal file
View File

@@ -0,0 +1,26 @@
server {
listen 80;
server_name _;
root /usr/share/nginx/html;
index index.html;
location /api/ {
proxy_http_version 1.1;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
proxy_pass ${NOTES_API_UPSTREAM}/;
}
location /assets/ {
try_files $uri =404;
expires 1y;
add_header Cache-Control "public, immutable";
}
location / {
try_files $uri $uri/ /index.html;
}
}