@wjwjq/release-helper 0.1.5 → 0.1.6
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/.release/release.conf.yaml +2 -0
- package/dist/cli.js +1 -1
- package/dist/deploy/script/common.sh +36 -29
- package/dist/deploy/script/prompt.sh +6 -0
- package/dist/pack.js +2 -1
- package/dist/prepare.js +14 -4
- package/dist/start_prepare.js +1 -1
- package/package.json +1 -1
- package/src/.release/README.md +0 -73
- package/src/.release/doc//351/203/250/347/275/262/346/211/213/345/206/214.md +0 -418
- package/src/.release/nginx/ca/ca.crt +0 -32
- package/src/.release/nginx/ca/ca.key +0 -54
- package/src/.release/nginx/ca/client.crt +0 -100
- package/src/.release/nginx/ca/client.csr +0 -16
- package/src/.release/nginx/ca/client.p12 +0 -0
- package/src/.release/nginx/ca/client.pem +0 -30
- package/src/.release/nginx/ca/server.crt +0 -101
- package/src/.release/nginx/ca/server.csr +0 -17
- package/src/.release/nginx/ca/server.key +0 -27
- package/src/.release/nginx/ca/server.pem +0 -30
- package/src/.release/nginx/nginx.conf +0 -179
- package/src/.release/release.conf.yaml +0 -15
- package/src/cli.ts +0 -99
- package/src/deploy/pkg/nginx/nginx.logrotate.tpl +0 -14
- package/src/deploy/pkg/nginx/nginx.service.tpl +0 -32
- package/src/deploy/pkg/nginx_binary/compile.sh +0 -39
- package/src/deploy/pkg/nginx_binary/nginx-arm-ssl1.1.1.tar.gz +0 -0
- package/src/deploy/pkg/nginx_binary/nginx-x86_64-ssl1.0.2.tar.gz +0 -0
- package/src/deploy/pkg/nginx_binary/nginx-x86_64-ssl1.1.1.tar.gz +0 -0
- package/src/deploy/pkg/nginx_binary/nginx-x86_64-ssl3.0.7.tar.gz +0 -0
- package/src/deploy/script/common.sh +0 -196
- package/src/deploy/script/install.sh +0 -7
- package/src/deploy/script/nginx.sh +0 -265
- package/src/deploy/script/prompt.sh +0 -110
- package/src/deploy/script/readme.md +0 -10
- package/src/deploy/script/upgrade.sh +0 -7
- package/src/logger.ts +0 -18
- package/src/pack.ts +0 -152
- package/src/prepare.ts +0 -120
- package/src/publish.ts +0 -308
- package/src/release.ts +0 -292
- package/src/start_prepare.ts +0 -13
|
@@ -1,110 +0,0 @@
|
|
|
1
|
-
#!/bin/bash
|
|
2
|
-
log "-----------receive parameter: $@------------"
|
|
3
|
-
|
|
4
|
-
# if [ $# == 0 ]; then
|
|
5
|
-
# log_error "Fatal error: parameter -standalone or -cluster is required!"
|
|
6
|
-
# exit 1
|
|
7
|
-
# fi
|
|
8
|
-
|
|
9
|
-
mode="__INSTALL_MODE__"
|
|
10
|
-
|
|
11
|
-
if [[ "${mode}" == "standalone" ]]; then
|
|
12
|
-
mode=1
|
|
13
|
-
elif [[ "${mode}" == "cluster" ]]; then
|
|
14
|
-
mode=2
|
|
15
|
-
else
|
|
16
|
-
mode=''
|
|
17
|
-
fi
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
if [[ -z "${mode}" ]]; then
|
|
21
|
-
while [ $# -gt 0 ]; do
|
|
22
|
-
case "$1" in
|
|
23
|
-
-S | -standalone)
|
|
24
|
-
mode=1
|
|
25
|
-
shift
|
|
26
|
-
;;
|
|
27
|
-
-C | -cluster)
|
|
28
|
-
mode=2
|
|
29
|
-
shift
|
|
30
|
-
;;
|
|
31
|
-
-h | --help)
|
|
32
|
-
echo "supported parameters: "
|
|
33
|
-
echo "-S, -standalone install for supervisord startup mode, conflict with -C"
|
|
34
|
-
echo "-C, -cluster install for systemd startup mode, conflict with -S"
|
|
35
|
-
echo "-P, -prefix specify the install path"
|
|
36
|
-
exit 0
|
|
37
|
-
;;
|
|
38
|
-
-P | -prefix)
|
|
39
|
-
case "$2" in
|
|
40
|
-
"")
|
|
41
|
-
if [ $# -eq 1 ]; then
|
|
42
|
-
break
|
|
43
|
-
else
|
|
44
|
-
shift 2
|
|
45
|
-
fi
|
|
46
|
-
;;
|
|
47
|
-
-*) shift ;;
|
|
48
|
-
*)
|
|
49
|
-
prefix=$2
|
|
50
|
-
if [ $# -eq 2 ]; then
|
|
51
|
-
break
|
|
52
|
-
else
|
|
53
|
-
shift 2
|
|
54
|
-
fi
|
|
55
|
-
;;
|
|
56
|
-
esac
|
|
57
|
-
;;
|
|
58
|
-
--)
|
|
59
|
-
shift
|
|
60
|
-
break
|
|
61
|
-
;;
|
|
62
|
-
"")
|
|
63
|
-
echo 'no args'
|
|
64
|
-
break
|
|
65
|
-
;;
|
|
66
|
-
*)
|
|
67
|
-
log_error "invalid parameter: {$1}"
|
|
68
|
-
exit 1
|
|
69
|
-
;;
|
|
70
|
-
esac
|
|
71
|
-
done
|
|
72
|
-
fi
|
|
73
|
-
|
|
74
|
-
if [[ -z "${mode}" ]]; then
|
|
75
|
-
log_error "Fatal error: parameter -standalone or -cluster is required!"
|
|
76
|
-
exit 1
|
|
77
|
-
# echo "Please choose an redis installation mode!"
|
|
78
|
-
# PS3='Please input the number: '
|
|
79
|
-
# options=("Standalone 1" "Cluster 2" "Quit")
|
|
80
|
-
# select opt in "${options[@]}"; do
|
|
81
|
-
# case $opt in
|
|
82
|
-
# "Standalone 1")
|
|
83
|
-
# mode=1
|
|
84
|
-
# break
|
|
85
|
-
# ;;
|
|
86
|
-
# "Cluster 2")
|
|
87
|
-
# mode=2
|
|
88
|
-
# break
|
|
89
|
-
# ;;
|
|
90
|
-
# "Quit")
|
|
91
|
-
# break
|
|
92
|
-
# ;;
|
|
93
|
-
# *) echo "invalid option $REPLY" ;;
|
|
94
|
-
# esac
|
|
95
|
-
# done
|
|
96
|
-
fi
|
|
97
|
-
|
|
98
|
-
if ((mode == 1)); then
|
|
99
|
-
log "-------------------------------------------------"
|
|
100
|
-
log "-------start to install Standalone mode-------"
|
|
101
|
-
log "-------------------------------------------------"
|
|
102
|
-
fi
|
|
103
|
-
|
|
104
|
-
if ((mode == 2)); then
|
|
105
|
-
log "-------------------------------------------------"
|
|
106
|
-
log "-------start to install Cluster mode-------"
|
|
107
|
-
log "-------------------------------------------------"
|
|
108
|
-
fi
|
|
109
|
-
|
|
110
|
-
# echo "install/upgrade prefix: $prefix"
|
package/src/logger.ts
DELETED
|
@@ -1,18 +0,0 @@
|
|
|
1
|
-
import pc from 'picocolors';
|
|
2
|
-
|
|
3
|
-
export const logger = {
|
|
4
|
-
info: (msg: string) => {
|
|
5
|
-
console.info(`---------------------- ${msg} ----------------------`)
|
|
6
|
-
},
|
|
7
|
-
error: (msg: string) => {
|
|
8
|
-
console.log(`---------------------- ${pc.red(msg)} ----------------------`)
|
|
9
|
-
},
|
|
10
|
-
success: (msg: string) => {
|
|
11
|
-
console.info("--------------------------------------------------------------");
|
|
12
|
-
console.info(`---------🚀 ${pc.green(msg)} ----------------`);
|
|
13
|
-
console.info("--------------------------------------------------------------");
|
|
14
|
-
},
|
|
15
|
-
tip: (msg: string) => {
|
|
16
|
-
console.log(`---------------------- ${pc.yellow(msg)} ----------------------`)
|
|
17
|
-
}
|
|
18
|
-
}
|
package/src/pack.ts
DELETED
|
@@ -1,152 +0,0 @@
|
|
|
1
|
-
import fs from "fs"
|
|
2
|
-
import path from "path"
|
|
3
|
-
|
|
4
|
-
import * as inquirer from "@inquirer/prompts"
|
|
5
|
-
import pc from "picocolors"
|
|
6
|
-
import * as tar from 'tar'
|
|
7
|
-
|
|
8
|
-
import { __work_dir, __releaseDir, __dirname, releaseConf, checkEnvInfo } from './prepare'
|
|
9
|
-
import { logger } from "./logger"
|
|
10
|
-
|
|
11
|
-
export async function pack(version?: string) {
|
|
12
|
-
try {
|
|
13
|
-
await checkEnvInfo();
|
|
14
|
-
|
|
15
|
-
if (version === undefined) {
|
|
16
|
-
version = await inquirer.input(
|
|
17
|
-
{
|
|
18
|
-
message: '请输入版本号:',
|
|
19
|
-
},
|
|
20
|
-
)
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
if (version == '') {
|
|
24
|
-
logger.error('版本号不能为空!')
|
|
25
|
-
return
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
const packageJson = JSON.parse(fs.readFileSync(path.resolve(__work_dir, 'package.json'), { 'encoding': 'utf-8' }))
|
|
29
|
-
const projectName = packageJson.name as string;
|
|
30
|
-
|
|
31
|
-
if (!projectName) {
|
|
32
|
-
logger.error('未在package.json找到name定义!')
|
|
33
|
-
return
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
const zipFileName = `${projectName}_${version}.tar.gz`
|
|
37
|
-
|
|
38
|
-
logger.tip(`start to pack`)
|
|
39
|
-
|
|
40
|
-
const projectDir = path.resolve(__releaseDir, projectName); //eg .release/posidon-frontend
|
|
41
|
-
const assetsDir = path.resolve(projectDir, 'pkg/assets');
|
|
42
|
-
const nginxDir = path.resolve(projectDir, 'pkg/nginx')
|
|
43
|
-
|
|
44
|
-
// 复制整个安装脚本和nginx二进制包
|
|
45
|
-
fs.cpSync(path.resolve(__dirname, 'deploy'), projectDir, { recursive: true })
|
|
46
|
-
// 复制打包后的静态资源
|
|
47
|
-
fs.cpSync(path.resolve(__work_dir, releaseConf.assetsDir), assetsDir, { recursive: true })
|
|
48
|
-
|
|
49
|
-
// 添加版本信息
|
|
50
|
-
fs.writeFileSync(path.resolve(projectDir, 'pkg', 'version'), version, { encoding: 'utf-8' })
|
|
51
|
-
fs.writeFileSync(path.resolve(assetsDir, 'version'), version, { encoding: 'utf-8' })
|
|
52
|
-
fs.writeFileSync(path.resolve(nginxDir, 'version'), version, { encoding: 'utf-8' })
|
|
53
|
-
|
|
54
|
-
logger.info(pc.green(`version: ${version} added`))
|
|
55
|
-
|
|
56
|
-
const assetInstallPath = `/opt/${projectName}/`
|
|
57
|
-
logger.info(pc.green(`start to replace variants in common.sh`))
|
|
58
|
-
|
|
59
|
-
// 替换安装脚本 与nginx匹配的名称
|
|
60
|
-
replaceFileContent({
|
|
61
|
-
filePath: path.resolve(projectDir, 'script', 'common.sh'),
|
|
62
|
-
replaced: [
|
|
63
|
-
['__APP_NAME__', `"${projectName}"`],
|
|
64
|
-
['__INSTALL_PATH__', assetInstallPath],
|
|
65
|
-
['__USER__', releaseConf.user],
|
|
66
|
-
['__USER_GROUP__', releaseConf.userGroup],
|
|
67
|
-
]
|
|
68
|
-
})
|
|
69
|
-
|
|
70
|
-
// 替换安装模式
|
|
71
|
-
replaceFileContent({
|
|
72
|
-
filePath: path.resolve(projectDir, 'script', 'prompt.sh'),
|
|
73
|
-
replaced: [
|
|
74
|
-
['__INSTALL_MODE__', releaseConf.installMode],
|
|
75
|
-
]
|
|
76
|
-
})
|
|
77
|
-
|
|
78
|
-
logger.info(pc.green(`start to replace version: ${version} in index.html`))
|
|
79
|
-
|
|
80
|
-
replaceFileContent({
|
|
81
|
-
filePath: path.resolve(assetsDir, 'index.html'),
|
|
82
|
-
replaced: [['__version__', version]]
|
|
83
|
-
})
|
|
84
|
-
|
|
85
|
-
// 生成nginx.conf文件
|
|
86
|
-
logger.info(pc.green(`start to generate nginx.conf`))
|
|
87
|
-
|
|
88
|
-
//复制用户指定的nginx配置信息
|
|
89
|
-
fs.cpSync(path.resolve(__releaseDir, 'nginx'), nginxDir, { recursive: true, force: true })
|
|
90
|
-
|
|
91
|
-
replaceFileContent({
|
|
92
|
-
filePath: path.resolve(nginxDir, 'nginx.conf'),
|
|
93
|
-
replaced: [['__root__', `${assetInstallPath}assets/`]],
|
|
94
|
-
// writeToNewFilePath: path.resolve(nginxDir, `${projectName}.conf`)
|
|
95
|
-
})
|
|
96
|
-
|
|
97
|
-
logger.info(pc.green(`start to generate ${zipFileName}`))
|
|
98
|
-
|
|
99
|
-
const zipFilePath = path.resolve(__releaseDir, zipFileName)
|
|
100
|
-
await genTarPkg(__releaseDir, projectName, zipFilePath);
|
|
101
|
-
|
|
102
|
-
logger.success(`done to pack ${pc.green(`${zipFileName} at: ${__releaseDir}`)}`);
|
|
103
|
-
|
|
104
|
-
if (fs.existsSync(projectDir)) {
|
|
105
|
-
fs.rmSync(projectDir, { recursive: true, force: true })
|
|
106
|
-
}
|
|
107
|
-
|
|
108
|
-
return {
|
|
109
|
-
version,
|
|
110
|
-
pkgName: zipFileName,
|
|
111
|
-
appName: projectName,
|
|
112
|
-
pkgFilePath: zipFilePath
|
|
113
|
-
}
|
|
114
|
-
} catch (error) {
|
|
115
|
-
console.error('Error:', error);
|
|
116
|
-
return Promise.reject(error);
|
|
117
|
-
}
|
|
118
|
-
}
|
|
119
|
-
|
|
120
|
-
function genTarPkg(releaseDir: string, projectName: string, zipFileName: string) {
|
|
121
|
-
return new Promise((resolve, reject) => {
|
|
122
|
-
const zipStream = fs.createWriteStream(zipFileName);
|
|
123
|
-
zipStream.on('close', () => {
|
|
124
|
-
resolve(true);
|
|
125
|
-
})
|
|
126
|
-
|
|
127
|
-
try {
|
|
128
|
-
tar.create(
|
|
129
|
-
{
|
|
130
|
-
z: true,
|
|
131
|
-
cwd: releaseDir,
|
|
132
|
-
},
|
|
133
|
-
[projectName],
|
|
134
|
-
).pipe(zipStream)
|
|
135
|
-
} catch (error) {
|
|
136
|
-
reject(error);
|
|
137
|
-
}
|
|
138
|
-
})
|
|
139
|
-
}
|
|
140
|
-
|
|
141
|
-
function replaceFileContent(params: {filePath: string; writeToNewFilePath?: string; replaced: [string, string][] }) {
|
|
142
|
-
const { filePath, writeToNewFilePath, replaced = [] } = params
|
|
143
|
-
if (fs.existsSync(filePath)) {
|
|
144
|
-
let content = fs.readFileSync(filePath, { encoding: 'utf-8' })
|
|
145
|
-
|
|
146
|
-
replaced.forEach(([regExp, replaceContent]) => {
|
|
147
|
-
content = content.toString().replace(regExp, replaceContent);
|
|
148
|
-
});
|
|
149
|
-
|
|
150
|
-
fs.writeFileSync(writeToNewFilePath ? writeToNewFilePath : filePath, content, { encoding: 'utf-8' })
|
|
151
|
-
}
|
|
152
|
-
}
|
package/src/prepare.ts
DELETED
|
@@ -1,120 +0,0 @@
|
|
|
1
|
-
import path, { dirname } from "path";
|
|
2
|
-
import fs from "fs"
|
|
3
|
-
import YAML from 'yaml';
|
|
4
|
-
import * as inquirer from "@inquirer/prompts"
|
|
5
|
-
|
|
6
|
-
import { execa } from 'execa';
|
|
7
|
-
import { fileURLToPath } from "node:url";
|
|
8
|
-
|
|
9
|
-
import { logger } from './logger';
|
|
10
|
-
|
|
11
|
-
const installMode = ['standalone', 'cluster', 'both'] as const;
|
|
12
|
-
|
|
13
|
-
export type ReleaseConf = {
|
|
14
|
-
/** gitlab 仓库地址 */
|
|
15
|
-
host: string
|
|
16
|
-
/** gitlab rest api token */
|
|
17
|
-
token: string
|
|
18
|
-
/** 打包脚本 默认npm run build */
|
|
19
|
-
buildCmd?: string
|
|
20
|
-
/** 打包后资源 相对工作区所在路径 默认dist/*/
|
|
21
|
-
assetsDir?: string
|
|
22
|
-
/** nginx和assets 所属用户和用户组 默认: root*/
|
|
23
|
-
user: string
|
|
24
|
-
userGroup: string
|
|
25
|
-
/* 指定安装模式 standalone(supervisor) 、 cluster(agent\systemd) 、 both */
|
|
26
|
-
installMode: (typeof installMode)[number]
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
// 获取项目根目录
|
|
30
|
-
export const __work_dir = process.env.INIT_CWD || process.cwd();
|
|
31
|
-
export const __releaseDir = path.resolve(__work_dir, '.release')
|
|
32
|
-
|
|
33
|
-
const __filename = fileURLToPath(import.meta.url);
|
|
34
|
-
export const __dirname = dirname(__filename);
|
|
35
|
-
|
|
36
|
-
export const releaseConfFileName = "release.conf.yaml"
|
|
37
|
-
export const __releaseConfPath = path.resolve(__releaseDir, releaseConfFileName);
|
|
38
|
-
|
|
39
|
-
function parseConf(file: string) {
|
|
40
|
-
try {
|
|
41
|
-
const conf = fs.readFileSync(file, "utf-8");
|
|
42
|
-
return YAML.parse(conf) as ReleaseConf
|
|
43
|
-
} catch (error) {
|
|
44
|
-
return {} as ReleaseConf;
|
|
45
|
-
}
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
export const releaseConf: Required<ReleaseConf> = Object.assign({
|
|
49
|
-
host: '',
|
|
50
|
-
token: '',
|
|
51
|
-
/** 打包脚本 默认npm run build */
|
|
52
|
-
buildCmd: 'npm run build',
|
|
53
|
-
/** 打包后资源 相对工作区所在路径 默认dist/*/
|
|
54
|
-
assetsDir: 'dist',
|
|
55
|
-
user: 'root',
|
|
56
|
-
userGroup: 'root',
|
|
57
|
-
installMode: 'both'
|
|
58
|
-
}, parseConf(__releaseConfPath));
|
|
59
|
-
|
|
60
|
-
export const $ = execa({ encoding: 'utf8' });
|
|
61
|
-
|
|
62
|
-
export async function prepare() {
|
|
63
|
-
const copyFiles = () => {
|
|
64
|
-
// 将.release file copy 到__work_dir 目录下
|
|
65
|
-
fs.cpSync(path.resolve(__dirname, '.release'), __releaseDir, { recursive: true })
|
|
66
|
-
}
|
|
67
|
-
|
|
68
|
-
if (!fs.existsSync(__releaseDir)) {
|
|
69
|
-
|
|
70
|
-
fs.mkdirSync(__releaseDir)
|
|
71
|
-
copyFiles();
|
|
72
|
-
logger.tip(`请注意修改.release/${releaseConfFileName} 配置信息`)
|
|
73
|
-
}else {
|
|
74
|
-
if(!process.env.INIT_CWD){ // Npm环境下 无法交互 会阻塞install
|
|
75
|
-
const shouldRegenerate = await inquirer.confirm(
|
|
76
|
-
{
|
|
77
|
-
message: '.release配置已存在,是否重新生成?',
|
|
78
|
-
},
|
|
79
|
-
)
|
|
80
|
-
|
|
81
|
-
if(shouldRegenerate){
|
|
82
|
-
copyFiles()
|
|
83
|
-
}
|
|
84
|
-
}
|
|
85
|
-
}
|
|
86
|
-
}
|
|
87
|
-
|
|
88
|
-
export async function checkEnvInfo() {
|
|
89
|
-
// 检查是否在 git 仓库中
|
|
90
|
-
const { stdout: isGitRepo } = await $(`git rev-parse --is-inside-work-tree`)
|
|
91
|
-
if (isGitRepo !== 'true') {
|
|
92
|
-
logger.error('当前项目不是git仓库')
|
|
93
|
-
process.exit(1);
|
|
94
|
-
}
|
|
95
|
-
|
|
96
|
-
// 检查.release下 nginx.conf, release.conf.yaml 等文件是否存在
|
|
97
|
-
|
|
98
|
-
if (!fs.existsSync(path.resolve(__releaseDir, 'nginx/nginx.conf'))) {
|
|
99
|
-
logger.error('.release目录下不存在nginx/nginx.conf 文件, 请使用 release-helper init 初始化生成')
|
|
100
|
-
process.exit(1);
|
|
101
|
-
}
|
|
102
|
-
|
|
103
|
-
if (!fs.existsSync(__releaseConfPath)) {
|
|
104
|
-
logger.error(`.release目录下不存在${releaseConfFileName}文件,请使用 release-helper init 初始化生成`)
|
|
105
|
-
process.exit(1);
|
|
106
|
-
}
|
|
107
|
-
|
|
108
|
-
for(let [field, value] of Object.entries(releaseConf)){
|
|
109
|
-
if (!value) {
|
|
110
|
-
logger.error(`The field: [${field}] is required in .release/release.conf.yaml!`);
|
|
111
|
-
process.exit(1);
|
|
112
|
-
}
|
|
113
|
-
|
|
114
|
-
if(field === 'installMode' && !installMode.includes(value as (typeof installMode)[number])){
|
|
115
|
-
logger.error(`The field: [${field}]'s value should be one of ${installMode.join(' | ')}`);
|
|
116
|
-
process.exit(1);
|
|
117
|
-
}
|
|
118
|
-
}
|
|
119
|
-
}
|
|
120
|
-
|