feat(val-blog): add 2026-04-30 dream journey post
This commit is contained in:
@@ -0,0 +1,39 @@
|
||||
# 多阶段构建
|
||||
FROM node:20-alpine AS builder
|
||||
|
||||
WORKDIR /app
|
||||
|
||||
# 复制依赖文件
|
||||
COPY package*.json ./
|
||||
RUN npm ci --only=production
|
||||
|
||||
# 生产阶段
|
||||
FROM node:20-alpine
|
||||
|
||||
WORKDIR /app
|
||||
|
||||
# 安装必要工具(健康检查用)
|
||||
RUN apk add --no-cache wget
|
||||
|
||||
# 创建非 root 用户
|
||||
RUN addgroup -g 1001 -S nodejs && \
|
||||
adduser -S app -u 1001
|
||||
|
||||
# 复制依赖
|
||||
COPY --from=builder --chown=app:nodejs /app/node_modules ./node_modules
|
||||
|
||||
# 复制应用代码
|
||||
COPY --chown=app:nodejs . .
|
||||
|
||||
# 切换到非 root 用户
|
||||
USER app
|
||||
|
||||
# 暴露端口
|
||||
EXPOSE 3000
|
||||
|
||||
# 健康检查
|
||||
HEALTHCHECK --interval=30s --timeout=3s --start-period=5s --retries=3 \
|
||||
CMD wget --quiet --tries=1 --spider http://localhost:${PORT:-3000}/health || exit 1
|
||||
|
||||
# 启动应用
|
||||
CMD ["node", "server.js"]
|
||||
@@ -0,0 +1,13 @@
|
||||
{
|
||||
"name": "gch3n-app",
|
||||
"version": "1.0.0",
|
||||
"description": "gch3n.online 示例应用",
|
||||
"main": "server.js",
|
||||
"scripts": {
|
||||
"start": "node server.js",
|
||||
"dev": "node server.js"
|
||||
},
|
||||
"keywords": [],
|
||||
"author": "",
|
||||
"license": "MIT"
|
||||
}
|
||||
@@ -0,0 +1,70 @@
|
||||
const http = require('http');
|
||||
|
||||
const PORT = process.env.PORT || 3000;
|
||||
const COLOR = process.env.DEPLOY_COLOR || 'unknown';
|
||||
const VERSION = process.env.npm_package_version || '1.0.0';
|
||||
|
||||
const server = http.createServer((req, res) => {
|
||||
const url = req.url;
|
||||
|
||||
// 健康检查端点
|
||||
if (url === '/health') {
|
||||
res.writeHead(200, { 'Content-Type': 'application/json' });
|
||||
res.end(JSON.stringify({
|
||||
status: 'healthy',
|
||||
color: COLOR,
|
||||
version: VERSION,
|
||||
timestamp: new Date().toISOString(),
|
||||
uptime: process.uptime()
|
||||
}));
|
||||
return;
|
||||
}
|
||||
|
||||
// 主页
|
||||
res.writeHead(200, { 'Content-Type': 'text/html' });
|
||||
res.end(`
|
||||
<!DOCTYPE html>
|
||||
<html>
|
||||
<head>
|
||||
<title>gch3n.online</title>
|
||||
<style>
|
||||
body {
|
||||
font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
|
||||
max-width: 800px;
|
||||
margin: 0 auto;
|
||||
padding: 40px 20px;
|
||||
background: ${COLOR === 'blue' ? '#e3f2fd' : '#e8f5e9'};
|
||||
}
|
||||
.badge {
|
||||
display: inline-block;
|
||||
padding: 4px 12px;
|
||||
border-radius: 12px;
|
||||
font-size: 12px;
|
||||
font-weight: bold;
|
||||
text-transform: uppercase;
|
||||
background: ${COLOR === 'blue' ? '#1976d2' : '#388e3c'};
|
||||
color: white;
|
||||
}
|
||||
h1 { color: #333; }
|
||||
.info { color: #666; margin-top: 20px; }
|
||||
</style>
|
||||
</head>
|
||||
<body>
|
||||
<h1>🚀 gch3n.online</h1>
|
||||
<span class="badge">${COLOR}</span>
|
||||
<p>蓝绿部署示例应用</p>
|
||||
<div class="info">
|
||||
<p>版本: ${VERSION}</p>
|
||||
<p>端口: ${PORT}</p>
|
||||
<p>时间: ${new Date().toLocaleString('zh-CN')}</p>
|
||||
</div>
|
||||
</body>
|
||||
</html>
|
||||
`);
|
||||
});
|
||||
|
||||
server.listen(PORT, () => {
|
||||
console.log(`🚀 服务器运行在端口 ${PORT}`);
|
||||
console.log(`🎨 部署颜色: ${COLOR}`);
|
||||
console.log(`📦 版本: ${VERSION}`);
|
||||
});
|
||||
Reference in New Issue
Block a user