Dockerized version 2
This commit is contained in:
parent
a76b371bda
commit
1b013c4fe2
11
Dockerfile
11
Dockerfile
@ -3,26 +3,29 @@ ARG NODE_VERSION=20.15.0
|
|||||||
FROM node:${NODE_VERSION}-alpine AS build
|
FROM node:${NODE_VERSION}-alpine AS build
|
||||||
WORKDIR /app
|
WORKDIR /app
|
||||||
|
|
||||||
# Install deps first for better caching
|
# Install deps with cache leverage
|
||||||
COPY package*.json ./
|
COPY package*.json ./
|
||||||
RUN npm ci || npm install
|
RUN npm ci || npm install
|
||||||
|
|
||||||
# Build
|
# Build
|
||||||
COPY . .
|
COPY . .
|
||||||
ENV NODE_ENV=production
|
ENV NODE_ENV=production
|
||||||
# Limit Node heap during build to avoid OOM on small builders
|
|
||||||
ENV NODE_OPTIONS=--max-old-space-size=512
|
ENV NODE_OPTIONS=--max-old-space-size=512
|
||||||
RUN npm run build
|
RUN npm run build
|
||||||
|
|
||||||
# ---- Runtime (Nginx) ----
|
# ---- Runtime (Nginx) ----
|
||||||
FROM nginx:1.27-alpine AS runtime
|
FROM nginx:1.27-alpine AS runtime
|
||||||
|
# Install curl for healthcheck
|
||||||
|
RUN apk add --no-cache curl
|
||||||
# Remove default site content
|
# Remove default site content
|
||||||
RUN rm -rf /usr/share/nginx/html/*
|
RUN rm -rf /usr/share/nginx/html/*
|
||||||
# SPA config (history fallback)
|
# SPA config
|
||||||
COPY docker/nginx.conf /etc/nginx/conf.d/default.conf
|
COPY docker/nginx.conf /etc/nginx/conf.d/default.conf
|
||||||
# Static assets
|
# Static assets
|
||||||
COPY --from=build /app/dist /usr/share/nginx/html
|
COPY --from=build /app/dist /usr/share/nginx/html
|
||||||
|
|
||||||
EXPOSE 80
|
EXPOSE 80
|
||||||
HEALTHCHECK --interval=30s --timeout=5s --start-period=10s --retries=3 \
|
HEALTHCHECK --interval=30s --timeout=5s --start-period=10s --retries=3 \
|
||||||
CMD wget -qO- http://localhost/ >/dev/null 2>&1 || exit 1
|
CMD curl -fsS http://localhost/ >/dev/null || exit 1
|
||||||
|
|
||||||
CMD ["nginx", "-g", "daemon off;"]
|
CMD ["nginx", "-g", "daemon off;"]
|
||||||
|
|||||||
31
README.md
31
README.md
@ -1,31 +1,12 @@
|
|||||||
# Reading Goal App (Dockerized)
|
# Reading Goal App (Dockerized — healthcheck fix)
|
||||||
|
|
||||||
React + Vite + Tailwind. Dates use **DD/MM/YYYY** and the calendar week starts on **Monday**.
|
This bundle installs `curl` in the Nginx runtime and uses a curl-based HEALTHCHECK.
|
||||||
Includes a multi-stage Dockerfile: Node build → Nginx runtime with SPA fallback.
|
- Internal port: **80**
|
||||||
|
- SPA fallback via Nginx
|
||||||
|
- Build heap capped to avoid OOM
|
||||||
|
|
||||||
## Local Dev
|
## Build & Run
|
||||||
```bash
|
|
||||||
npm install
|
|
||||||
npm run dev
|
|
||||||
```
|
|
||||||
|
|
||||||
## Production Build (local)
|
|
||||||
```bash
|
|
||||||
npm run build
|
|
||||||
npm run preview
|
|
||||||
```
|
|
||||||
|
|
||||||
## Docker (build locally)
|
|
||||||
```bash
|
```bash
|
||||||
docker build -t reading-goal-app:latest .
|
docker build -t reading-goal-app:latest .
|
||||||
docker run -d --name reading-goal-app -p 8080:80 --restart unless-stopped reading-goal-app:latest
|
docker run -d --name reading-goal-app -p 8080:80 --restart unless-stopped reading-goal-app:latest
|
||||||
# Open http://localhost:8080
|
|
||||||
```
|
```
|
||||||
|
|
||||||
## Deploy in Coolify
|
|
||||||
- Deployment Type: **Dockerfile**
|
|
||||||
- Dockerfile path: `Dockerfile`
|
|
||||||
- **Internal Port**: `80` (Nginx)
|
|
||||||
- No extra start command needed.
|
|
||||||
|
|
||||||
The multi-stage image builds the app (`vite build`) and serves static files via Nginx with history API fallback.
|
|
||||||
|
|||||||
@ -1,15 +1,14 @@
|
|||||||
server {
|
server {
|
||||||
listen 80;
|
listen 80;
|
||||||
|
listen [::]:80;
|
||||||
server_name _;
|
server_name _;
|
||||||
root /usr/share/nginx/html;
|
root /usr/share/nginx/html;
|
||||||
index index.html;
|
index index.html;
|
||||||
|
|
||||||
# Serve files if they exist, else fallback to index.html (SPA)
|
|
||||||
location / {
|
location / {
|
||||||
try_files $uri $uri/ /index.html;
|
try_files $uri $uri/ /index.html;
|
||||||
}
|
}
|
||||||
|
|
||||||
# Static assets (cache-friendly)
|
|
||||||
location ~* \.(?:js|css|png|jpg|jpeg|gif|svg|ico|woff2?)$ {
|
location ~* \.(?:js|css|png|jpg|jpeg|gif|svg|ico|woff2?)$ {
|
||||||
expires 30d;
|
expires 30d;
|
||||||
add_header Cache-Control "public, immutable";
|
add_header Cache-Control "public, immutable";
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user