Skip to content

Commit

Permalink
feat:k8s部署
Browse files Browse the repository at this point in the history
  • Loading branch information
Marvin committed May 4, 2021
1 parent fff9cd9 commit aefd78c
Show file tree
Hide file tree
Showing 11 changed files with 110 additions and 51 deletions.
11 changes: 6 additions & 5 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
FROM node:12.16.1-alpine
MAINTAINER Marvin
ENV HOST 0.0.0.0
ENV MYSQL 148.70.150.131
ENV MYSQL 127.0.0.1
ENV MYSQL_PASSWORD 123Ad123Ad
ENV MYSQL_USER root
ENV MYSQL_DATABASE_NAME b_simple_user_center
Expand All @@ -12,15 +12,16 @@ ENV MONGODB_USER ''
ENV MONGODB_DATABASE_NAME ''
ENV MONGODB_PORT ''
ENV MONGODB_AUTH_SOURCE ''
ENV REDIS 148.70.150.131:6379
ENV REDIS 127.0.0.1:6379
ENV REDIS_NAME user_token
ENV REDIS_HOST 148.70.150.131
ENV REDIS_HOST 127.0.0.1
ENV REDIS_POST 6379
ENV KAfKA 148.70.150.131:19092
ENV REDIS_PASSWORD 123Asd123Asd
ENV KAfKA 127.0.0.1:19090
ENV RABBITMQ ''
RUN mkdir -p /app
COPY . /app
WORKDIR /app
EXPOSE 8881
RUN ls
CMD ["node", "/app/index.js", "MONGODB=$MONGODB MONGODB_AUTH_SOURCE=$MONGODB_AUTH_SOURCE MONGODB_PORT=$MONGODB_PORT MONGODB_DATABASE_NAME=$MONGODB_DATABASE_NAME MONGODB_USER=$MONGODB_USER MONGODB_PASSWORD=$MONGODB_PASSWORD KAfKA=$KAfKA REDIS_NAME=$REDIS_NAME REDIS_HOST=$REDIS_HOST REDIS_POST=$REDIS_POST MYSQL=$MYSQL MYSQL_USER=$MYSQL_USER MYSQL_PASSWORD=$MYSQL_PASSWORD MYSQL_PORT=$MYSQL_PORT MYSQL_DATABASE_NAME=$MYSQL_DATABASE_NAME REDIS=$REDIS"]
CMD ["node", "/app/index.js", "MONGODB=$MONGODB REDIS_PASSWORD=$REDIS_PASSWORD MONGODB_AUTH_SOURCE=$MONGODB_AUTH_SOURCE MONGODB_PORT=$MONGODB_PORT MONGODB_DATABASE_NAME=$MONGODB_DATABASE_NAME MONGODB_USER=$MONGODB_USER MONGODB_PASSWORD=$MONGODB_PASSWORD KAfKA=$KAfKA REDIS_NAME=$REDIS_NAME REDIS_HOST=$REDIS_HOST REDIS_POST=$REDIS_POST MYSQL=$MYSQL MYSQL_USER=$MYSQL_USER MYSQL_PASSWORD=$MYSQL_PASSWORD MYSQL_PORT=$MYSQL_PORT MYSQL_DATABASE_NAME=$MYSQL_DATABASE_NAME REDIS=$REDIS"]
41 changes: 41 additions & 0 deletions k8s/deployment.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
apiVersion: apps/v1
kind: Deployment
metadata:
labels:
app: simple-user-center-server
name: simple-user-center-server
spec:
replicas: 1
selector:
matchLabels:
app: simple-user-center-server
template:
metadata:
labels:
app: simple-user-center-server
spec:
containers:
- env:
- name: MYSQL
value: "127.0.0.1"
- name: MYSQL_PASSWORD
value: "123456"
- name: MYSQL_PORT
value: '7000'
- name: MYSQL_USER
value: root
- name: MYSQL_DATABASE_NAME
value: b_simple_user_center
- name: REDIS
value: '127.0.0.1:6379'
- name: REDIS_NAME
value: 'user_token'
- name: REDIS_POST
value: '6380'
- name: KAfKA
value: '127.0.0.1:19090'
image: canyuegongzi/simple-user-center-server:2.0
imagePullPolicy: IfNotPresent
name: simple-user-center-server
ports:
- containerPort: 8881
15 changes: 15 additions & 0 deletions k8s/service.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
apiVersion: v1
kind: Service
metadata:
labels:
app: simple-user-center-server
name: simple-user-center-server-service
spec:
type: LoadBalancer
ports:
- name: simple-user-center-server-port
port: 8881
protocol: TCP
targetPort: 8881
selector:
app: simple-user-center-server
21 changes: 8 additions & 13 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 1 addition & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@
"socket.io-redis": "^5.2.0",
"typeorm": "^0.2.16",
"ws": "^7.3.0",
"yaml": "^2.0.0-4"
"yamljs": "^0.3.0"
},
"devDependencies": {
"@nestjs/cli": "^7.0.0",
Expand All @@ -75,7 +75,6 @@
"@types/socket.io": "2.1.2",
"@types/supertest": "^2.0.7",
"@types/ws": "6.0.1",
"@types/yaml": "^1.9.7",
"jest": "^23.6.0",
"nodemon": "^1.18.9",
"prettier": "^1.15.3",
Expand Down
9 changes: 6 additions & 3 deletions src/MainModule.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,9 @@ console.log(commonConfigService.envConfig);
imports: [
RedisModule.register({
name: commonConfigService.get(CommonConfigKey.REDIS_NAME),
url: commonConfigService.get(CommonConfigKey.REDIS_HOST) + ':' + commonConfigService.get(CommonConfigKey.REDIS_POST),
host: commonConfigService.get(CommonConfigKey.REDIS_HOST),
port: commonConfigService.get(CommonConfigKey.REDIS_POST),
password: commonConfigService.get(CommonConfigKey.REDIS_PASSWORD),
}),
TypeOrmModule.forRoot(
{
Expand All @@ -41,13 +43,14 @@ console.log(commonConfigService.envConfig);
synchronize: true,
},
),
CacheModule.register({
/* CacheModule.register({
store: redisStore,
host: commonConfigService.get(CommonConfigKey.REDIS_HOST),
port: commonConfigService.get(CommonConfigKey.REDIS_POST),
password: commonConfigService.get(CommonConfigKey.REDIS_PASSWORD),
ttl: 30,
max: 150,
}),
}),*/
UserModule, RoleModule, OrganizationModule, AuthorityModule, SystemModule, KafkaTaskModule, ApiResourceModule,
],
controllers: [ AppController ],
Expand Down
2 changes: 2 additions & 0 deletions src/config/CommonConfigInterface.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ export interface CommonConfigInterface {
REDIS_NAME: string;
// redis ip 地址
REDIS_HOST: string;
REDIS_PASSWORD: string;
// redis 端口
REDIS_POST: string;
// kafka 地址
Expand All @@ -53,6 +54,7 @@ export const CommonConfigKey: CommonConfigInterface = {
REDIS_NAME: 'REDIS_NAME',
REDIS_HOST: 'REDIS_HOST',
REDIS_POST: 'REDIS_POST',
REDIS_PASSWORD: 'REDIS_PASSWORD',
KAfKA: 'KAfKA',
RABBITMQ: 'RABBITMQ',
};
13 changes: 8 additions & 5 deletions src/config/CommonConfigService.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
import {CommonConfigInterface} from './CommonConfigInterface';
import { parse, stringify } from 'yaml';
// import { parse, stringify } from 'yaml';
// tslint:disable-next-line:no-var-requires
const YAML = require('yamljs');
import * as fs from 'fs';
import {join} from 'path';
const isDevelopment: boolean = process.env.NODE_ENV === 'development';
const envConfigFile = isDevelopment ?
fs.readFileSync(join(__dirname, '.', 'dev.yaml'), 'utf-8')
: fs.readFileSync(join(__dirname, '.', 'pro.yaml'), 'utf-8');
const envConfig = parse(envConfigFile);
const devConfig = fs.readFileSync(join(__dirname, '.', 'dev.yaml'), 'utf-8');
const proConfig = fs.readFileSync(join(__dirname, '.', 'pro.yaml'), 'utf-8');
const envConfigFile = isDevelopment ? devConfig : proConfig;
const envConfig = YAML.parse(envConfigFile);
const { mysqlConfig, mongodbConfig, kafkaConfig, rabbitMQConfig, redisConfig, emailConfig, serverConfig } = envConfig;

export class CommonConfigService {
Expand Down Expand Up @@ -44,6 +46,7 @@ export class CommonConfigService {
REDIS: autoConfig.REDIS || redisConfig.url,
REDIS_NAME: autoConfig.REDIS_NAME || redisConfig.name,
REDIS_POST: autoConfig.REDIS_POST || redisConfig.port,
REDIS_PASSWORD: autoConfig.REDIS_PASSWORD || redisConfig.password,
REDIS_HOST: autoConfig.REDIS_HOST || redisConfig.host,
KAfKA: autoConfig.KAfKA || kafkaConfig.url,
} as CommonConfigInterface;
Expand Down
2 changes: 1 addition & 1 deletion src/config/constant.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
export const HELLO_TOPIC = 'hello.topic';
export const HELLO_FIXED_TOPIC = 'hello.fixed.topic';
export const TASK_PUSH_INFO = 'task.push.info'
export const TASK_PUSH_INFO = 'task.push.info';
6 changes: 3 additions & 3 deletions src/config/dev.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -22,14 +22,14 @@ redisConfig:
host: '127.0.0.1'
port: 6379
kafkaConfig:
url: '148.70.150.131:19092'
url: '127.0.0.1:19090'
clientId: 'test-app-client'
groupId: 'test-app-group'
rabbitMQConfig:
url: ''
url: 'amqp://root:123Ad123Ad@127.0.0.1:5179'
name: 'MESSAGE_SERVICE'
queue: 'message_queue'
emailConfig:
authPass: ''
authPass: 'tsdrnaaktxsebfbd'
fromUser: '"Marvin" <1970305447@qq.com>'
user: '1970305447@qq.com'
38 changes: 19 additions & 19 deletions src/config/pro.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,32 +4,32 @@ serverConfig:
tokenSetTimeOut: 7200
globalPrefix: 'simple-user-center/v1.0'
mysqlConfig:
host: ''
userName: ''
password: ''
dataBaseName: 'prd_simple_user_center'
host: '127.0.0.1'
userName: 'root'
password: '123456'
dataBaseName: 'b_simple_user_center'
port: 3306
mongodbConfig:
host: ''
userName: ''
port:
host: '127.0.0.1'
userName: 'root'
port: 7000
dataBaseName: ''
password: ''
authSource: ''
password: '123456'
authSource: 'admin'
redisConfig:
name: 'user_token'
url: ''
host: ''
port:
url: '127.0.0.1:6379'
host: '127.0.0.1'
port: 6379
kafkaConfig:
url: ''
url: '127.0.0.1:19090'
clientId: 'test-app-client'
groupId: 'test-app-group'
rabbitMQConfig:
url: ''
name: ''
queue: ''
url: 'amqp://root:123Ad123Ad@127.0.0.1:5179'
name: 'MESSAGE_SERVICE'
queue: 'message_queue'
emailConfig:
authPass: ''
fromUser: ''
user: ''
authPass: 'tsdrnaaktxsebfbd'
fromUser: '"Marvin" <1970305447@qq.com>'
user: '1970305447@qq.com'

0 comments on commit aefd78c

Please sign in to comment.