Skip to content

Commit 0f24ff0

Browse files
committed
refactor: use k8s secret to set env instead of mounting config/
__dirname is not correct in files of k8s volumeMounts
1 parent 7a5a597 commit 0f24ff0

File tree

3 files changed

+17
-13
lines changed

3 files changed

+17
-13
lines changed

Diff for: .dockerignore

-1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,2 @@
1-
config
21
node_modules
32
npm-debug.log

Diff for: config/config.default.js

+7-5
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
'use strict';
22

3+
const env = process.env;
4+
35
module.exports = appInfo => {
46
const config = exports = {};
57

@@ -9,14 +11,14 @@ module.exports = appInfo => {
911
// add your config here
1012
config.middleware = [];
1113

12-
const POSTGRES_DB_HOST = process.env.POSTGRES_DB_HOST || '';
14+
const POSTGRES_DB_HOST = env.POSTGRES_DB_HOST || '';
1315
config.sequelize = {
1416
dialect: 'postgres',
1517
database: 'smart-signature-pro',
1618
host: POSTGRES_DB_HOST.split(':')[0] || 'localhost',
1719
port: POSTGRES_DB_HOST.split(':')[1] || '5432',
18-
username: process.env.POSTGRES_DB_USER || 'postgres',
19-
password: process.env.POSTGRES_DB_PASSWORD || 'postgres',
20+
username: env.POSTGRES_DB_USER || 'postgres',
21+
password: env.POSTGRES_DB_PASSWORD || 'postgres',
2022
};
2123

2224
config.security = {
@@ -27,11 +29,11 @@ module.exports = appInfo => {
2729

2830
config.smsVerify = {
2931
ttl: 10, // 验证码有效期(分钟)
30-
mock: '1234', // 如果设置了mock,就不会真正去发短信
32+
mock: env.SMS_MOCK, // 如果设置了mock,就不会真正去发短信
3133
provider: {
3234
type: 'yunpian',
3335
api: 'https://sms.yunpian.com/v2/sms/single_send.json',
34-
key: '<REPLACE_WITH_YOUR_KEY>',
36+
key: env.YUNPIAN_KEY || '<REPLACE_WITH_YOUR_KEY>',
3537
template: '【云片网】您的验证码是',
3638
},
3739
};

Diff for: k8s/deployment.yaml

+10-7
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,6 @@ spec:
1616
- name: APP_NAME
1717
image: IMAGE_TAG
1818
imagePullPolicy: Always
19-
volumeMounts:
20-
- name: config-volume
21-
readOnly: true
22-
mountPath: /usr/src/app/config
2319
# The following environment variables will contain the database host,
2420
# user and password to connect to the PostgreSQL instance.
2521
env:
@@ -37,6 +33,16 @@ spec:
3733
name: cloudsql-db-credentials
3834
key: password
3935
# [END cloudsql_secrets]
36+
- name: YUNPIAN_KEY
37+
valueFrom:
38+
secretKeyRef:
39+
name: APP_NAME-env
40+
key: YUNPIAN_KEY
41+
- name: SMS_MOCK
42+
valueFrom:
43+
secretKeyRef:
44+
name: APP_NAME-env
45+
key: SMS_MOCK
4046
# Change <SQL_INSTANCE_CONNECTION_NAME> here to include your GCP
4147
# project, the region of your Cloud SQL instance and the name
4248
# of your Cloud SQL instance. The format is
@@ -57,7 +63,4 @@ spec:
5763
- name: cloudsql-instance-credentials
5864
secret:
5965
secretName: cloudsql-instance-credentials
60-
- name: config-volume
61-
secret:
62-
secretName: APP_NAME-config
6366
# [END volumes]

0 commit comments

Comments
 (0)