Merge branch 'feature/docker' into gray
Showing
13 changed files
with
123 additions
and
100 deletions
Dockerfile
0 → 100644
1 | +############################################################ | ||
2 | +# Dockerfile to build hystrix + turbin Installed Containers | ||
3 | +# Based on centos 6.7 | ||
4 | +# How to build new image: docker build -t yoho-hystrix-qcloud . | ||
5 | +# the hystrix alert need to post events to influxdb.yohoops.org. | ||
6 | +# nginx version: 1.12.0 | ||
7 | +############################################################ | ||
8 | + | ||
9 | +#base image : ccr.ccs.tencentyun.com/yoho-base/nodejs:8.9.1 | ||
10 | +FROM ccr.ccs.tencentyun.com/yoho-base/nodejs:8.9.1 | ||
11 | + | ||
12 | +MAINTAINER xiaoxiao.hao <xiaoxiao.hao@yoho.cn> | ||
13 | + | ||
14 | +ENV NODE_ENV=production \ | ||
15 | + NODE_HOME=/home | ||
16 | + | ||
17 | +# COPY turbine configuration files | ||
18 | +COPY yoho-yohobuy-wap.tar.gz /home | ||
19 | + | ||
20 | +RUN cd /home && \ | ||
21 | + mkdir -p /home/yoho-yohobuy-wap && \ | ||
22 | + tar -xzvf yoho-yohobuy-wap.tar.gz -C /home/yoho-yohobuy-wap && \ | ||
23 | + rm -rf yoho-yohobuy-wap.tar.gz | ||
24 | + | ||
25 | +WORKDIR /home/yoho-yohobuy-wap | ||
26 | + | ||
27 | +#expose port | ||
28 | +EXPOSE 6001 | ||
29 | + | ||
30 | +CMD ["node","/home/yoho-yohobuy-wap/app.js"] |
@@ -171,6 +171,11 @@ try { | @@ -171,6 +171,11 @@ try { | ||
171 | app.use(downloadBar()); | 171 | app.use(downloadBar()); |
172 | app.use(riskManagement()); | 172 | app.use(riskManagement()); |
173 | 173 | ||
174 | + // docker验证项目是否正常发布 | ||
175 | + app.use('/node/status.html', (req, res) => { | ||
176 | + return res.status(204).end(); | ||
177 | + }); | ||
178 | + | ||
174 | require('./dispatch')(app); | 179 | require('./dispatch')(app); |
175 | app.all('*', errorHanlder.notFound()); // 404 | 180 | app.all('*', errorHanlder.notFound()); // 404 |
176 | 181 |
@@ -44,5 +44,4 @@ router.get('/channel/2fb054e8315300a1ae1f80c3a4fda862.html', custom.zhihui); | @@ -44,5 +44,4 @@ router.get('/channel/2fb054e8315300a1ae1f80c3a4fda862.html', custom.zhihui); | ||
44 | // 自定义频道 | 44 | // 自定义频道 |
45 | router.get('/channel/:id.html', custom.index); | 45 | router.get('/channel/:id.html', custom.index); |
46 | 46 | ||
47 | - | ||
48 | module.exports = router; | 47 | module.exports = router; |
@@ -412,7 +412,7 @@ function getRealIP(req) { | @@ -412,7 +412,7 @@ function getRealIP(req) { | ||
412 | var realIP = req.headers['x-real-ip']; | 412 | var realIP = req.headers['x-real-ip']; |
413 | var forwardedFor = req.headers['x-forwarded-for'] || ''; | 413 | var forwardedFor = req.headers['x-forwarded-for'] || ''; |
414 | 414 | ||
415 | - return realIP || forwardedFor.split(',')[0] || req.connection.remoteAddress; | 415 | + return req.yoho.clientIp || forwardedFor.split(',')[0] || realIP || req.connection.remoteAddress; |
416 | } | 416 | } |
417 | 417 | ||
418 | const activateService = (req, res, next) => { | 418 | const activateService = (req, res, next) => { |
@@ -197,10 +197,13 @@ const common = { | @@ -197,10 +197,13 @@ const common = { | ||
197 | if (req.session2 && req.session2.reset) { | 197 | if (req.session2 && req.session2.reset) { |
198 | req.session2.reset(); | 198 | req.session2.reset(); |
199 | } | 199 | } |
200 | - if (req.session && req.session.regenerate) { | 200 | + |
201 | + if (req.session && req.session.regenerate && req.sessionStore) { | ||
201 | return req.session.regenerate(() => { | 202 | return req.session.regenerate(() => { |
202 | return next(); | 203 | return next(); |
203 | }); | 204 | }); |
205 | + } else { | ||
206 | + return next(); | ||
204 | } | 207 | } |
205 | 208 | ||
206 | // if (req.session) { | 209 | // if (req.session) { |
@@ -210,7 +213,6 @@ const common = { | @@ -210,7 +213,6 @@ const common = { | ||
210 | // delete req.session.TOKEN; | 213 | // delete req.session.TOKEN; |
211 | // delete req.session.LOGIN_UID; | 214 | // delete req.session.LOGIN_UID; |
212 | // } | 215 | // } |
213 | - // return next(); | ||
214 | }, | 216 | }, |
215 | isLoginUser: (req, res, next) => { | 217 | isLoginUser: (req, res, next) => { |
216 | // 微信里边已经登录的时候,不再跳转登录 | 218 | // 微信里边已经登录的时候,不再跳转登录 |
@@ -67,12 +67,6 @@ module.exports = { | @@ -67,12 +67,6 @@ module.exports = { | ||
67 | index: '//m.yohobuy.com' | 67 | index: '//m.yohobuy.com' |
68 | }, | 68 | }, |
69 | useCache: false, | 69 | useCache: false, |
70 | - memcache: { | ||
71 | - master: ['127.0.0.1:11211'], | ||
72 | - session: ['127.0.0.1:11211'], | ||
73 | - timeout: 1000, | ||
74 | - retries: 0 | ||
75 | - }, | ||
76 | interfaceShunt: { | 70 | interfaceShunt: { |
77 | open: false | 71 | open: false |
78 | }, | 72 | }, |
@@ -80,9 +74,12 @@ module.exports = { | @@ -80,9 +74,12 @@ module.exports = { | ||
80 | infoFile: { | 74 | infoFile: { |
81 | close: true, | 75 | close: true, |
82 | name: 'info', | 76 | name: 'info', |
83 | - level: 'error', | 77 | + level: 'info', |
84 | filename: 'logs/info.log', | 78 | filename: 'logs/info.log', |
85 | - maxFiles: 7 | 79 | + maxFiles: 7, |
80 | + timestamp() { | ||
81 | + return new Date().toString(); | ||
82 | + } | ||
86 | }, | 83 | }, |
87 | errorFile: { | 84 | errorFile: { |
88 | close: true, | 85 | close: true, |
@@ -90,7 +87,10 @@ module.exports = { | @@ -90,7 +87,10 @@ module.exports = { | ||
90 | level: 'error', | 87 | level: 'error', |
91 | filename: 'logs/error.log', | 88 | filename: 'logs/error.log', |
92 | handleExceptions: true, | 89 | handleExceptions: true, |
93 | - maxFiles: 7 | 90 | + maxFiles: 7, |
91 | + timestamp() { | ||
92 | + return new Date().toString(); | ||
93 | + } | ||
94 | }, | 94 | }, |
95 | console: { | 95 | console: { |
96 | level: 'debug', | 96 | level: 'debug', |
@@ -132,19 +132,26 @@ module.exports = { | @@ -132,19 +132,26 @@ module.exports = { | ||
132 | connect: { | 132 | connect: { |
133 | host: '127.0.0.1', | 133 | host: '127.0.0.1', |
134 | port: '6379', | 134 | port: '6379', |
135 | + enable_offline_queue: false, | ||
135 | retry_strategy(options) { | 136 | retry_strategy(options) { |
136 | if (options.error && options.error.code === 'ECONNREFUSED') { | 137 | if (options.error && options.error.code === 'ECONNREFUSED') { |
137 | - console.log('redis连接不成功'); | 138 | + console.log('connect redis server fail'); |
138 | } | 139 | } |
139 | - if (options.total_retry_time > 1000 * 60 * 60 * 6) { | ||
140 | - console.log('redis连接超时'); | ||
141 | - return; | ||
142 | - } | ||
143 | - if (options.attempt > 10) { | ||
144 | - return 1000 * 60 * 60 * 0.5; | 140 | + |
141 | + if (options.attempt < 10) { | ||
142 | + return Math.min(options.attempt * 100, 1000); | ||
143 | + } else if (options.attempt > 10 && options.attempt < 100) { | ||
144 | + return 1000; | ||
145 | + } else { | ||
146 | + return 1000 * 10; | ||
145 | } | 147 | } |
146 | - return Math.min(options.attempt * 100, 1000); | ||
147 | } | 148 | } |
149 | + }, | ||
150 | + session: { | ||
151 | + host: '127.0.0.1', | ||
152 | + port: '6379', | ||
153 | + pass: '', | ||
154 | + prefix: 'yohobuy_session:' | ||
148 | } | 155 | } |
149 | }, | 156 | }, |
150 | REQUEST_LIMIT: { | 157 | REQUEST_LIMIT: { |
@@ -180,24 +187,6 @@ if (isProduction) { | @@ -180,24 +187,6 @@ if (isProduction) { | ||
180 | extstore: 'http://extstore.yohobuy.com', | 187 | extstore: 'http://extstore.yohobuy.com', |
181 | yohoNowApi: 'http://new.yohoboys.com/' | 188 | yohoNowApi: 'http://new.yohoboys.com/' |
182 | }, | 189 | }, |
183 | - memcache: { | ||
184 | - master: [ | ||
185 | - 'memcache1.yohoops.org:12111', | ||
186 | - 'memcache2.yohoops.org:12111', | ||
187 | - 'memcache3.yohoops.org:12111', | ||
188 | - 'memcache4.yohoops.org:12111' | ||
189 | - ], | ||
190 | - session: [ | ||
191 | - 'memcache1.yohoops.org:12111', | ||
192 | - 'memcache2.yohoops.org:12111', | ||
193 | - 'memcache3.yohoops.org:12111', | ||
194 | - 'memcache4.yohoops.org:12111' | ||
195 | - ], | ||
196 | - poolSize: 100, | ||
197 | - reconnect: 5000, | ||
198 | - timeout: 1000, | ||
199 | - retries: 0 | ||
200 | - }, | ||
201 | useCache: true, | 190 | useCache: true, |
202 | interfaceShunt: { | 191 | interfaceShunt: { |
203 | open: false, | 192 | open: false, |
@@ -226,21 +215,28 @@ if (isProduction) { | @@ -226,21 +215,28 @@ if (isProduction) { | ||
226 | }, | 215 | }, |
227 | redis: { | 216 | redis: { |
228 | connect: { | 217 | connect: { |
229 | - host: 'web.redis.yohoops.org' | ||
230 | - }, | ||
231 | - port: '6379', | ||
232 | - retry_strategy(options) { | ||
233 | - if (options.error && options.error.code === 'ECONNREFUSED') { | ||
234 | - console.log('redis连接不成功'); | ||
235 | - } | ||
236 | - if (options.total_retry_time > 1000 * 60 * 60 * 6) { | ||
237 | - console.log('redis连接超时'); | ||
238 | - return; | ||
239 | - } | ||
240 | - if (options.attempt > 10) { | ||
241 | - return 1000 * 60 * 60 * 0.5; | 218 | + host: 'web.redis.yohoops.org', |
219 | + port: '6379', | ||
220 | + enable_offline_queue: false, | ||
221 | + retry_strategy(options) { | ||
222 | + if (options.error && options.error.code === 'ECONNREFUSED') { | ||
223 | + console.log('connect redis server fail'); | ||
224 | + } | ||
225 | + | ||
226 | + if (options.attempt < 10) { | ||
227 | + return Math.min(options.attempt * 100, 1000); | ||
228 | + } else if (options.attempt > 10 && options.attempt < 100) { | ||
229 | + return 1000; | ||
230 | + } else { | ||
231 | + return 1000 * 10; | ||
232 | + } | ||
242 | } | 233 | } |
243 | - return Math.min(options.attempt * 100, 1000); | 234 | + }, |
235 | + session: { | ||
236 | + host: 'redis.web.yohoops.org', | ||
237 | + port: '6379', | ||
238 | + pass: 'redis9646', | ||
239 | + prefix: 'yohobuy_session:' | ||
244 | } | 240 | } |
245 | }, | 241 | }, |
246 | report: { | 242 | report: { |
@@ -250,21 +246,26 @@ if (isProduction) { | @@ -250,21 +246,26 @@ if (isProduction) { | ||
250 | }, | 246 | }, |
251 | loggers: { | 247 | loggers: { |
252 | infoFile: { | 248 | infoFile: { |
253 | - close: true, | ||
254 | name: 'info', | 249 | name: 'info', |
255 | - level: 'error', | ||
256 | - filename: 'logs/info.log', | ||
257 | - maxFiles: 7 | 250 | + level: 'info', |
251 | + filename: '/Data/log/yoho-yohobuy-wap/info.log', | ||
252 | + maxFiles: 7, | ||
253 | + timestamp() { | ||
254 | + return new Date().toString(); | ||
255 | + } | ||
258 | }, | 256 | }, |
259 | errorFile: { | 257 | errorFile: { |
260 | - close: true, | ||
261 | name: 'error', | 258 | name: 'error', |
262 | level: 'error', | 259 | level: 'error', |
263 | - filename: 'logs/error.log', | 260 | + filename: '/Data/log/yoho-yohobuy-wap/error.log', |
264 | handleExceptions: true, | 261 | handleExceptions: true, |
265 | - maxFiles: 7 | 262 | + maxFiles: 7, |
263 | + timestamp() { | ||
264 | + return new Date().toString(); | ||
265 | + } | ||
266 | }, | 266 | }, |
267 | console: { | 267 | console: { |
268 | + close: true, | ||
268 | level: 'info', | 269 | level: 'info', |
269 | colorize: 'all', | 270 | colorize: 'all', |
270 | prettyPrint: true, | 271 | prettyPrint: true, |
@@ -287,13 +288,6 @@ if (isProduction) { | @@ -287,13 +288,6 @@ if (isProduction) { | ||
287 | extstore: 'http://extstore-test1.yohops.com', | 288 | extstore: 'http://extstore-test1.yohops.com', |
288 | yohoNowApi: process.env.YOHO_NOW_API || 'http://yohonow-test.yohops.com:9999/' | 289 | yohoNowApi: process.env.YOHO_NOW_API || 'http://yohonow-test.yohops.com:9999/' |
289 | }, | 290 | }, |
290 | - memcache: { | ||
291 | - master: ['127.0.0.1:12111'], | ||
292 | - session: ['127.0.0.1:12111'], | ||
293 | - timeout: 100, | ||
294 | - reconnect: 5000, | ||
295 | - retries: 0 | ||
296 | - }, | ||
297 | useCache: true, | 291 | useCache: true, |
298 | alipayConfig: { | 292 | alipayConfig: { |
299 | payUrl: 'https://mapi.alipay.com/gateway.do', | 293 | payUrl: 'https://mapi.alipay.com/gateway.do', |
docker.sh
0 → 100755
@@ -53,19 +53,7 @@ const limiter = (rule, policy, context) => { | @@ -53,19 +53,7 @@ const limiter = (rule, policy, context) => { | ||
53 | }; | 53 | }; |
54 | 54 | ||
55 | module.exports = (req, res, next) => { | 55 | module.exports = (req, res, next) => { |
56 | - let remoteIp = req.get('X-Forwarded-For') || req.get('X-Real-IP') || ''; | ||
57 | - | ||
58 | - if (remoteIp.indexOf(',') > 0) { | ||
59 | - let arr = remoteIp.split(','); | ||
60 | - | ||
61 | - remoteIp = arr[arr.length - 1]; | ||
62 | - } | ||
63 | - | ||
64 | - remoteIp = _.trim(remoteIp); | ||
65 | - | ||
66 | - if (_.startsWith(remoteIp, '10.66.')) { | ||
67 | - remoteIp = req.get('X-Real-IP'); | ||
68 | - } | 56 | + let remoteIp = req.yoho.clientIp || ''; |
69 | 57 | ||
70 | // 排除条件:ip白名单/路径白名单/异步请求/登录用户 | 58 | // 排除条件:ip白名单/路径白名单/异步请求/登录用户 |
71 | const excluded = _.includes(IP_WHITE_LIST, remoteIp) || | 59 | const excluded = _.includes(IP_WHITE_LIST, remoteIp) || |
@@ -14,7 +14,7 @@ const net = require('net'); | @@ -14,7 +14,7 @@ const net = require('net'); | ||
14 | * @param {*} req | 14 | * @param {*} req |
15 | */ | 15 | */ |
16 | const _getClientIp = req => { | 16 | const _getClientIp = req => { |
17 | - let remoteIp = req.get('X-Forwarded-For') || req.get('X-Real-IP') || req.ip; | 17 | + let remoteIp = req.get('X-Yoho-Real-IP') || req.get('X-Forwarded-For') || req.get('X-Real-IP') || req.ip; |
18 | 18 | ||
19 | if (remoteIp.indexOf(',') > 0) { | 19 | if (remoteIp.indexOf(',') > 0) { |
20 | let arr = remoteIp.split(','); | 20 | let arr = remoteIp.split(','); |
1 | const config = global.yoho.config; | 1 | const config = global.yoho.config; |
2 | -const memcachedSession = require('yoho-express-session'); | 2 | +const session = require('yoho-express-session'); |
3 | const _ = require('lodash'); | 3 | const _ = require('lodash'); |
4 | const uuid = require('uuid'); | 4 | const uuid = require('uuid'); |
5 | 5 | ||
6 | const cookieSession = require('client-sessions'); | 6 | const cookieSession = require('client-sessions'); |
7 | -const memcached = require('connect-memcached'); | ||
8 | -const MemcachedStore = memcached(memcachedSession); | 7 | +const connectRedis = require('connect-redis'); |
8 | +const RedisStore = connectRedis(session); | ||
9 | 9 | ||
10 | /** | 10 | /** |
11 | - * 该中间件主要把 express-session 和 client-session 集中起来处理,如果 memcached 出错了,使用 cookie session | 11 | + * 该中间件主要把 express-session 和 client-session 集中起来处理,如果 redis 出错了,使用 cookie session |
12 | * @param opts.backSession cookieSession 的键名 | 12 | * @param opts.backSession cookieSession 的键名 |
13 | * @returns {function(*=, *=, *)} | 13 | * @returns {function(*=, *=, *)} |
14 | */ | 14 | */ |
15 | function yohoSession(opts) { | 15 | function yohoSession(opts) { |
16 | return (req, res, next) => { | 16 | return (req, res, next) => { |
17 | - let notUseMemcached = _.get(req.app.locals.wap, 'session.removeMemcached', false); | 17 | + let notUseRedis = _.get(req.app.locals.wap, 'session.removeMemcached', false); |
18 | 18 | ||
19 | opts.backSession = opts.backSession || 'session2'; | 19 | opts.backSession = opts.backSession || 'session2'; |
20 | 20 | ||
21 | - if (req.session && !notUseMemcached) { | 21 | + if (req.session && !notUseRedis) { |
22 | req.sessionError = false; | 22 | req.sessionError = false; |
23 | } else { | 23 | } else { |
24 | // 重建 session | 24 | // 重建 session |
@@ -26,8 +26,8 @@ function yohoSession(opts) { | @@ -26,8 +26,8 @@ function yohoSession(opts) { | ||
26 | req.sessionError = true; | 26 | req.sessionError = true; |
27 | 27 | ||
28 | req.sessionID = req.sessionID || uuid.v4(); | 28 | req.sessionID = req.sessionID || uuid.v4(); |
29 | - req.session = new memcachedSession.Session(req, req[opts.backSession].sessionBack); | ||
30 | - req.session.cookie = new memcachedSession.Cookie({ | 29 | + req.session = new session.Session(req, req[opts.backSession].sessionBack); |
30 | + req.session.cookie = new session.Cookie({ | ||
31 | domain: 'yohobuy.com', | 31 | domain: 'yohobuy.com', |
32 | httpOnly: true | 32 | httpOnly: true |
33 | }); | 33 | }); |
@@ -51,7 +51,7 @@ function yohoSession(opts) { | @@ -51,7 +51,7 @@ function yohoSession(opts) { | ||
51 | } | 51 | } |
52 | 52 | ||
53 | module.exports = (app) => { | 53 | module.exports = (app) => { |
54 | - app.use(memcachedSession({ // eslint-disable-line | 54 | + app.use(session({ // eslint-disable-line |
55 | proxy: true, | 55 | proxy: true, |
56 | resave: false, | 56 | resave: false, |
57 | saveUninitialized: true, | 57 | saveUninitialized: true, |
@@ -65,13 +65,7 @@ module.exports = (app) => { | @@ -65,13 +65,7 @@ module.exports = (app) => { | ||
65 | domain: 'yohobuy.com', | 65 | domain: 'yohobuy.com', |
66 | httpOnly: true | 66 | httpOnly: true |
67 | }, | 67 | }, |
68 | - store: new MemcachedStore({ | ||
69 | - hosts: config.memcache.session, | ||
70 | - prefix: 'yohobuy_session:', | ||
71 | - reconnect: 5000, | ||
72 | - timeout: 1000, | ||
73 | - retries: 0 | ||
74 | - }) | 68 | + store: new RedisStore(config.redis.session) |
75 | })); | 69 | })); |
76 | 70 | ||
77 | app.use(cookieSession({ // eslint-disable-line | 71 | app.use(cookieSession({ // eslint-disable-line |
logs/README.md
deleted
100644 → 0
1 | -# 日志 |
@@ -46,8 +46,8 @@ | @@ -46,8 +46,8 @@ | ||
46 | "cheerio": "^0.22.0", | 46 | "cheerio": "^0.22.0", |
47 | "client-sessions": "^0.8.0", | 47 | "client-sessions": "^0.8.0", |
48 | "compression": "^1.7.0", | 48 | "compression": "^1.7.0", |
49 | - "connect-memcached": "^0.2.0", | ||
50 | "connect-multiparty": "^2.0.0", | 49 | "connect-multiparty": "^2.0.0", |
50 | + "connect-redis": "^3.3.3", | ||
51 | "cookie-parser": "^1.4.3", | 51 | "cookie-parser": "^1.4.3", |
52 | "cssnano": "^3.10.0", | 52 | "cssnano": "^3.10.0", |
53 | "express": "^4.15.4", | 53 | "express": "^4.15.4", |
@@ -74,7 +74,7 @@ | @@ -74,7 +74,7 @@ | ||
74 | "xml2js": "^0.4.19", | 74 | "xml2js": "^0.4.19", |
75 | "yoho-express-session": "^2.0.0", | 75 | "yoho-express-session": "^2.0.0", |
76 | "yoho-md5": "^2.0.0", | 76 | "yoho-md5": "^2.0.0", |
77 | - "yoho-node-lib": "=0.6.3", | 77 | + "yoho-node-lib": "=0.6.8", |
78 | "yoho-zookeeper": "^1.0.9" | 78 | "yoho-zookeeper": "^1.0.9" |
79 | }, | 79 | }, |
80 | "devDependencies": { | 80 | "devDependencies": { |
-
Please register or login to post a comment