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
|
||||||
@@ -115,4 +115,30 @@ Access the dashboard by navigating to `/admin`.
|
|||||||
|
|
||||||
---
|
---
|
||||||
|
|
||||||
**Crafted with care by Antigravity.**
|
**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:
|
||||||
@@ -3,12 +3,13 @@
|
|||||||
"private": true,
|
"private": true,
|
||||||
"version": "0.0.0",
|
"version": "0.0.0",
|
||||||
"type": "module",
|
"type": "module",
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"dev": "vite",
|
"dev": "vite",
|
||||||
"build": "vite build",
|
"build": "vite build",
|
||||||
"postbuild": "react-snap",
|
"build:docker": "vite build",
|
||||||
"preview": "vite preview"
|
"postbuild": "react-snap",
|
||||||
},
|
"preview": "vite preview"
|
||||||
|
},
|
||||||
"reactSnap": {
|
"reactSnap": {
|
||||||
"source": "dist",
|
"source": "dist",
|
||||||
"include": [
|
"include": [
|
||||||
|
|||||||
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"]
|
||||||
@@ -3,8 +3,8 @@ const { Pool } = require('pg');
|
|||||||
const cors = require('cors');
|
const cors = require('cors');
|
||||||
require('dotenv').config();
|
require('dotenv').config();
|
||||||
|
|
||||||
const app = express();
|
const app = express();
|
||||||
const port = process.env.PORT || 5000;
|
const port = process.env.PORT || 5000;
|
||||||
|
|
||||||
// Middleware
|
// Middleware
|
||||||
app.use(cors());
|
app.use(cors());
|
||||||
@@ -20,12 +20,22 @@ const pool = new Pool({
|
|||||||
port: process.env.DB_PORT,
|
port: process.env.DB_PORT,
|
||||||
});
|
});
|
||||||
|
|
||||||
pool.on('error', (err) => {
|
pool.on('error', (err) => {
|
||||||
console.error('Unexpected error on idle client', err);
|
console.error('Unexpected error on idle client', err);
|
||||||
process.exit(-1);
|
process.exit(-1);
|
||||||
});
|
});
|
||||||
|
|
||||||
// Routes
|
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 ---
|
// --- PRODUCTS ---
|
||||||
app.get('/api/products', async (req, res) => {
|
app.get('/api/products', async (req, res) => {
|
||||||
|
|||||||
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 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 }) => {
|
export const StoreProvider: React.FC<{ children: ReactNode }> = ({ children }) => {
|
||||||
const [products, setProducts] = useState<CollectionItem[]>([]);
|
const [products, setProducts] = useState<CollectionItem[]>([]);
|
||||||
@@ -95,10 +95,10 @@ export const StoreProvider: React.FC<{ children: ReactNode }> = ({ children }) =
|
|||||||
fetch(`${API_URL}/products`),
|
fetch(`${API_URL}/products`),
|
||||||
fetch(`${API_URL}/articles`)
|
fetch(`${API_URL}/articles`)
|
||||||
]);
|
]);
|
||||||
const prods = await prodRes.json();
|
const prods = await prodRes.json();
|
||||||
const arts = await artRes.json();
|
const arts = await artRes.json();
|
||||||
setProducts(prods);
|
setProducts(Array.isArray(prods) && prods.length > 0 ? prods : COLLECTIONS);
|
||||||
setArticles(arts);
|
setArticles(Array.isArray(arts) && arts.length > 0 ? arts : JOURNAL_ENTRIES);
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
console.error('Failed to fetch data from backend, falling back to static data', err);
|
console.error('Failed to fetch data from backend, falling back to static data', err);
|
||||||
setProducts(COLLECTIONS);
|
setProducts(COLLECTIONS);
|
||||||
|
|||||||
Reference in New Issue
Block a user