Docker
This commit is contained in:
9
Pottery-website/.dockerignore
Normal file
9
Pottery-website/.dockerignore
Normal file
@@ -0,0 +1,9 @@
|
||||
node_modules
|
||||
dist
|
||||
.git
|
||||
.gitignore
|
||||
README.md
|
||||
npm-debug.log
|
||||
server/node_modules
|
||||
server/.env
|
||||
.env
|
||||
4
Pottery-website/.env.example
Normal file
4
Pottery-website/.env.example
Normal file
@@ -0,0 +1,4 @@
|
||||
SITE_HOST=example.com
|
||||
POSTGRES_DB=pottery_db
|
||||
POSTGRES_USER=pottery
|
||||
POSTGRES_PASSWORD=change-this-password
|
||||
10
Pottery-website/Caddyfile
Normal file
10
Pottery-website/Caddyfile
Normal file
@@ -0,0 +1,10 @@
|
||||
{$SITE_HOST:localhost} {
|
||||
encode zstd gzip
|
||||
|
||||
@api path /api/* /health
|
||||
reverse_proxy @api backend:5000
|
||||
|
||||
root * /srv
|
||||
try_files {path} /index.html
|
||||
file_server
|
||||
}
|
||||
12
Pottery-website/Dockerfile.frontend
Normal file
12
Pottery-website/Dockerfile.frontend
Normal file
@@ -0,0 +1,12 @@
|
||||
FROM node:22-alpine AS build
|
||||
WORKDIR /app
|
||||
|
||||
COPY package*.json ./
|
||||
RUN npm ci
|
||||
|
||||
COPY . .
|
||||
RUN npm run build:docker
|
||||
|
||||
FROM caddy:2-alpine
|
||||
COPY Caddyfile /etc/caddy/Caddyfile
|
||||
COPY --from=build /app/dist /srv
|
||||
@@ -116,3 +116,29 @@ Access the dashboard by navigating to `/admin`.
|
||||
---
|
||||
|
||||
**Crafted with care by Antigravity.**
|
||||
|
||||
## Docker Deployment with Caddy
|
||||
|
||||
For a self-hosted deployment, this repository now includes:
|
||||
|
||||
- `Dockerfile.frontend`: Builds the Vite frontend and serves it with Caddy.
|
||||
- `server/Dockerfile`: Runs the Node/Express API.
|
||||
- `docker-compose.yml`: Starts Caddy, the API, and PostgreSQL together.
|
||||
- `server/init.sql`: Initializes the database schema on first startup.
|
||||
|
||||
### Quick Start
|
||||
|
||||
1. Copy `.env.example` to `.env`.
|
||||
2. Set `SITE_HOST` to your domain name.
|
||||
3. Set a strong `POSTGRES_PASSWORD`.
|
||||
4. Start the stack:
|
||||
|
||||
```bash
|
||||
docker compose up -d --build
|
||||
```
|
||||
|
||||
### Notes
|
||||
|
||||
- Caddy terminates TLS automatically when `SITE_HOST` points to a public domain with correct DNS.
|
||||
- The frontend uses `/api` in production, and Caddy proxies that path to the backend container.
|
||||
- PostgreSQL data is stored in the `postgres_data` Docker volume.
|
||||
|
||||
63
Pottery-website/docker-compose.yml
Normal file
63
Pottery-website/docker-compose.yml
Normal file
@@ -0,0 +1,63 @@
|
||||
services:
|
||||
caddy:
|
||||
build:
|
||||
context: .
|
||||
dockerfile: Dockerfile.frontend
|
||||
container_name: pottery-caddy
|
||||
depends_on:
|
||||
backend:
|
||||
condition: service_healthy
|
||||
environment:
|
||||
SITE_HOST: ${SITE_HOST}
|
||||
ports:
|
||||
- "80:80"
|
||||
- "443:443"
|
||||
volumes:
|
||||
- caddy_data:/data
|
||||
- caddy_config:/config
|
||||
restart: unless-stopped
|
||||
|
||||
backend:
|
||||
build:
|
||||
context: ./server
|
||||
dockerfile: Dockerfile
|
||||
container_name: pottery-backend
|
||||
depends_on:
|
||||
db:
|
||||
condition: service_healthy
|
||||
environment:
|
||||
PORT: 5000
|
||||
DB_USER: ${POSTGRES_USER}
|
||||
DB_HOST: db
|
||||
DB_NAME: ${POSTGRES_DB}
|
||||
DB_PASSWORD: ${POSTGRES_PASSWORD}
|
||||
DB_PORT: 5432
|
||||
restart: unless-stopped
|
||||
healthcheck:
|
||||
test: ["CMD", "wget", "-qO-", "http://127.0.0.1:5000/health"]
|
||||
interval: 10s
|
||||
timeout: 5s
|
||||
retries: 10
|
||||
start_period: 15s
|
||||
|
||||
db:
|
||||
image: postgres:16-alpine
|
||||
container_name: pottery-db
|
||||
environment:
|
||||
POSTGRES_DB: ${POSTGRES_DB}
|
||||
POSTGRES_USER: ${POSTGRES_USER}
|
||||
POSTGRES_PASSWORD: ${POSTGRES_PASSWORD}
|
||||
volumes:
|
||||
- postgres_data:/var/lib/postgresql/data
|
||||
- ./server/init.sql:/docker-entrypoint-initdb.d/00-init.sql:ro
|
||||
restart: unless-stopped
|
||||
healthcheck:
|
||||
test: ["CMD-SHELL", "pg_isready -U ${POSTGRES_USER} -d ${POSTGRES_DB}"]
|
||||
interval: 10s
|
||||
timeout: 5s
|
||||
retries: 10
|
||||
|
||||
volumes:
|
||||
postgres_data:
|
||||
caddy_data:
|
||||
caddy_config:
|
||||
@@ -6,6 +6,7 @@
|
||||
"scripts": {
|
||||
"dev": "vite",
|
||||
"build": "vite build",
|
||||
"build:docker": "vite build",
|
||||
"postbuild": "react-snap",
|
||||
"preview": "vite preview"
|
||||
},
|
||||
|
||||
11
Pottery-website/server/Dockerfile
Normal file
11
Pottery-website/server/Dockerfile
Normal file
@@ -0,0 +1,11 @@
|
||||
FROM node:22-alpine
|
||||
WORKDIR /app
|
||||
|
||||
COPY package*.json ./
|
||||
RUN npm ci --omit=dev
|
||||
|
||||
COPY . .
|
||||
|
||||
EXPOSE 5000
|
||||
|
||||
CMD ["node", "index.js"]
|
||||
@@ -25,6 +25,16 @@ pool.on('error', (err) => {
|
||||
process.exit(-1);
|
||||
});
|
||||
|
||||
app.get('/health', async (_req, res) => {
|
||||
try {
|
||||
await pool.query('SELECT 1');
|
||||
res.json({ ok: true });
|
||||
} catch (err) {
|
||||
console.error('Healthcheck failed', err);
|
||||
res.status(500).json({ ok: false });
|
||||
}
|
||||
});
|
||||
|
||||
// Routes
|
||||
|
||||
// --- PRODUCTS ---
|
||||
|
||||
36
Pottery-website/server/init.sql
Normal file
36
Pottery-website/server/init.sql
Normal file
@@ -0,0 +1,36 @@
|
||||
CREATE TABLE IF NOT EXISTS products (
|
||||
id SERIAL PRIMARY KEY,
|
||||
title VARCHAR(255) NOT NULL,
|
||||
price DECIMAL(10, 2) NOT NULL,
|
||||
image TEXT NOT NULL,
|
||||
description TEXT,
|
||||
gallery JSONB DEFAULT '[]'::jsonb,
|
||||
slug TEXT,
|
||||
number TEXT,
|
||||
aspect_ratio TEXT,
|
||||
details JSONB DEFAULT '[]'::jsonb
|
||||
);
|
||||
|
||||
CREATE TABLE IF NOT EXISTS articles (
|
||||
id SERIAL PRIMARY KEY,
|
||||
title VARCHAR(255) NOT NULL,
|
||||
date VARCHAR(50) NOT NULL,
|
||||
image TEXT NOT NULL,
|
||||
sections JSONB DEFAULT '[]'::jsonb,
|
||||
slug TEXT,
|
||||
category TEXT,
|
||||
description TEXT,
|
||||
is_featured BOOLEAN DEFAULT FALSE
|
||||
);
|
||||
|
||||
CREATE TABLE IF NOT EXISTS orders (
|
||||
id SERIAL PRIMARY KEY,
|
||||
customer_email TEXT NOT NULL,
|
||||
customer_name TEXT NOT NULL,
|
||||
shipping_address JSONB NOT NULL,
|
||||
items JSONB NOT NULL,
|
||||
total_amount DECIMAL(10, 2) NOT NULL,
|
||||
payment_status TEXT DEFAULT 'pending',
|
||||
shipping_status TEXT DEFAULT 'pending',
|
||||
created_at TIMESTAMP WITH TIME ZONE DEFAULT CURRENT_TIMESTAMP
|
||||
);
|
||||
@@ -43,7 +43,7 @@ interface StoreContextType {
|
||||
|
||||
const StoreContext = createContext<StoreContextType | undefined>(undefined);
|
||||
|
||||
const API_URL = 'http://localhost:5000/api';
|
||||
const API_URL = import.meta.env.VITE_API_URL || '/api';
|
||||
|
||||
export const StoreProvider: React.FC<{ children: ReactNode }> = ({ children }) => {
|
||||
const [products, setProducts] = useState<CollectionItem[]>([]);
|
||||
@@ -97,8 +97,8 @@ export const StoreProvider: React.FC<{ children: ReactNode }> = ({ children }) =
|
||||
]);
|
||||
const prods = await prodRes.json();
|
||||
const arts = await artRes.json();
|
||||
setProducts(prods);
|
||||
setArticles(arts);
|
||||
setProducts(Array.isArray(prods) && prods.length > 0 ? prods : COLLECTIONS);
|
||||
setArticles(Array.isArray(arts) && arts.length > 0 ? arts : JOURNAL_ENTRIES);
|
||||
} catch (err) {
|
||||
console.error('Failed to fetch data from backend, falling back to static data', err);
|
||||
setProducts(COLLECTIONS);
|
||||
|
||||
Reference in New Issue
Block a user