@wjwjq/release-helper 0.1.4 → 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.
Files changed (44) hide show
  1. package/dist/.release/doc//351/203/250/347/275/262/346/211/213/345/206/214.md +3 -19
  2. package/dist/.release/release.conf.yaml +2 -0
  3. package/dist/cli.js +1 -1
  4. package/dist/deploy/pkg/nginx/nginx.logrotate.tpl +14 -0
  5. package/dist/deploy/script/common.sh +36 -28
  6. package/dist/deploy/script/nginx.sh +29 -20
  7. package/dist/deploy/script/prompt.sh +6 -0
  8. package/dist/pack.js +2 -1
  9. package/dist/prepare.js +14 -4
  10. package/dist/start_prepare.js +1 -1
  11. package/package.json +2 -2
  12. package/src/.release/README.md +0 -73
  13. package/src/.release/doc//351/203/250/347/275/262/346/211/213/345/206/214.md +0 -434
  14. package/src/.release/nginx/ca/ca.crt +0 -32
  15. package/src/.release/nginx/ca/ca.key +0 -54
  16. package/src/.release/nginx/ca/client.crt +0 -100
  17. package/src/.release/nginx/ca/client.csr +0 -16
  18. package/src/.release/nginx/ca/client.p12 +0 -0
  19. package/src/.release/nginx/ca/client.pem +0 -30
  20. package/src/.release/nginx/ca/server.crt +0 -101
  21. package/src/.release/nginx/ca/server.csr +0 -17
  22. package/src/.release/nginx/ca/server.key +0 -27
  23. package/src/.release/nginx/ca/server.pem +0 -30
  24. package/src/.release/nginx/nginx.conf +0 -179
  25. package/src/.release/release.conf.yaml +0 -15
  26. package/src/cli.ts +0 -99
  27. package/src/deploy/pkg/nginx/nginx.service.tpl +0 -32
  28. package/src/deploy/pkg/nginx_binary/compile.sh +0 -39
  29. package/src/deploy/pkg/nginx_binary/nginx-arm-ssl1.1.1.tar.gz +0 -0
  30. package/src/deploy/pkg/nginx_binary/nginx-x86_64-ssl1.0.2.tar.gz +0 -0
  31. package/src/deploy/pkg/nginx_binary/nginx-x86_64-ssl1.1.1.tar.gz +0 -0
  32. package/src/deploy/pkg/nginx_binary/nginx-x86_64-ssl3.0.7.tar.gz +0 -0
  33. package/src/deploy/script/common.sh +0 -195
  34. package/src/deploy/script/install.sh +0 -7
  35. package/src/deploy/script/nginx.sh +0 -256
  36. package/src/deploy/script/prompt.sh +0 -110
  37. package/src/deploy/script/readme.md +0 -10
  38. package/src/deploy/script/upgrade.sh +0 -7
  39. package/src/logger.ts +0 -18
  40. package/src/pack.ts +0 -152
  41. package/src/prepare.ts +0 -120
  42. package/src/publish.ts +0 -308
  43. package/src/release.ts +0 -292
  44. package/src/start_prepare.ts +0 -13
@@ -182,10 +182,11 @@ chmod +x upgrade.sh
182
182
  | 安装目录 | /opt/$APP_NAME$/ |
183
183
  | 版本文件 | /opt/$APP_NAME$/version |
184
184
  | nginx配置文件 | /opt/$APP_NAME$/nginx/nginx.conf |
185
- | 日志文件位置 | /var/log/nginx/$APP_NAME$.log |
185
+ | 日志文件位置 | /var/log/$APP_NAME$/nginx.log |
186
186
  | 系统静态资源目录 | /opt/$APP_NAME$/assets/ |
187
187
  | 系统配置文件 | /opt/$APP_NAME$/assets/settings |
188
188
  | system service位置 | /usr/lib/systemd/system/$APP_NAME$.nginx.service |
189
+ | 日志翻转配置位置 | /etc/logrotate.d/$APP_NAME$.nginx |
189
190
 
190
191
  ## 4.2 启动命令
191
192
 
@@ -414,21 +415,4 @@ tar: Error is not recoverable: exiting now
414
415
 
415
416
  页面配置: **最新版配置文件,请查看最新版本$APP_NAME$.tar.gz解压路径"/$APP_NAME$/pkg/assets/settings"**
416
417
 
417
- nginx配置: **最新版配置文件,请查看最新版本$APP_NAME$.tar.gz解压路径"/$APP_NAME$/pkg/nginx/nginx.conf"**
418
-
419
- ## 5.1 v1.7.0
420
-
421
- 无变更, 无需手动修改
422
-
423
- ## 5.2 v1.8.0
424
-
425
- 新增配置项 安全事件返回条数限制
426
-
427
- ```text
428
- # 第5行
429
- systemSafeEventDate.limit=43200
430
- ````
431
-
432
- ## 5.3 v1.9.0
433
-
434
- 无变更, 无需手动修改
418
+ nginx配置: **最新版配置文件,请查看最新版本$APP_NAME$.tar.gz解压路径"/$APP_NAME$/pkg/nginx/nginx.conf"**
@@ -10,6 +10,8 @@ assetsDir: 'dist'
10
10
  # nginx和assets 所属用户和用户组
11
11
  user: root
12
12
  userGroup: root
13
+ # 安装目录
14
+ installDir: /opt
13
15
 
14
16
  # 指定安装模式 standalone(supervisor) 、 cluster(agent\systemd) 、 both
15
17
  installMode: both
package/dist/cli.js CHANGED
@@ -16,7 +16,7 @@ cli.command("init", "generate release configuration").action(async (options) =>
16
16
  try {
17
17
  logger.info("start to generate .release configuration ");
18
18
  const { prepare } = await import('./prepare.js');
19
- await prepare();
19
+ await prepare({ callBy: "init" });
20
20
  logger.info("done");
21
21
  } catch (e) {
22
22
  console.error(`release-helper error: `, e);
@@ -0,0 +1,14 @@
1
+ /var/log/__app_name__/*.log {
2
+ daily
3
+ missingok
4
+ minsize 100M
5
+ rotate 3
6
+ compress
7
+ delaycompress
8
+ notifempty
9
+ create 0644 __user__ __usergroup__
10
+ sharedscripts
11
+ postrotate
12
+ [ -f __pid_file__ ] && kill -USR1 `cat __pid_file__`
13
+ endscript
14
+ }
@@ -133,34 +133,37 @@ install_assets() {
133
133
  }
134
134
 
135
135
  start() {
136
- # 未安装
137
- if ((has_nginx_installed == 0)); then
138
- install_nginx_binary
139
-
140
- if [[ $? != 0 ]]; then
141
- echo "$(tput setaf 1)"failed to install!"$(tput sgr0)"
142
- exit 1
136
+ # 仅静态文件
137
+ if [[ "${mode}" != 3 ]]; then
138
+ # 未安装
139
+ if ((has_nginx_installed == 0)); then
140
+ install_nginx_binary
141
+
142
+ if [[ $? != 0 ]]; then
143
+ echo "$(tput setaf 1)"failed to install!"$(tput sgr0)"
144
+ exit 1
145
+ fi
143
146
  fi
144
- fi
145
147
 
146
- # 已安装 询问是否更新nginx
147
- if ((has_nginx_installed == 1)); then
148
- while true; do
149
- read -r -p "Nginx has been installed, re-install it?[Y/N]" yn
150
- case $yn in
151
- [Yy]*)
152
- install_nginx_binary
153
-
154
- if [[ $? != 0 ]]; then
155
- echo "$(tput setaf 1)"failed to install!"$(tput sgr0)"
156
- exit 1
157
- fi
158
- break
159
- ;;
160
- [Nn]*) break ;;
161
- *) echo "Please answer yes or no." ;;
162
- esac
163
- done
148
+ # 已安装 询问是否更新nginx
149
+ if ((has_nginx_installed == 1)); then
150
+ while true; do
151
+ read -r -p "Nginx has been installed, re-install it?[Y/N]" yn
152
+ case $yn in
153
+ [Yy]*)
154
+ install_nginx_binary
155
+
156
+ if [[ $? != 0 ]]; then
157
+ echo "$(tput setaf 1)"failed to install!"$(tput sgr0)"
158
+ exit 1
159
+ fi
160
+ break
161
+ ;;
162
+ [Nn]*) break ;;
163
+ *) echo "Please answer yes or no." ;;
164
+ esac
165
+ done
166
+ fi
164
167
  fi
165
168
 
166
169
  # 创建用户
@@ -179,8 +182,13 @@ start() {
179
182
 
180
183
  mkdir -p "$install_path"
181
184
 
182
- copy_nginx_conf_and_write_verison
183
- add_nginx_service
185
+ # 仅静态文件
186
+ if [[ "${mode}" != 3 ]]; then
187
+ copy_nginx_conf_and_write_verison
188
+ add_nginx_service
189
+ add_log_rotate
190
+ fi
191
+
184
192
  install_assets
185
193
 
186
194
  # 修改所属用户
@@ -14,32 +14,26 @@ nginx_conf_install_path="$prefix/opt/${app_name}/nginx/"
14
14
  nginx_conf_path="${nginx_conf_install_path}nginx.conf"
15
15
 
16
16
  # asset_path="$prefix/opt/posidon-frontend/"
17
- nginx_log_path="/var/log/nginx"
18
- nginx_log_file="${app_name}.nginx.log"
17
+ nginx_info_path="/var/log/${app_name}"
18
+ nginx_log_file="nginx.log"
19
19
  #不放在var/run 是因为重启后 var/run/下面的文件及目录会被清除
20
- nginx_pid_dir="/var/log/nginx/"
21
- nginx_pid_file_path="$nginx_pid_dir${app_name}.nginx.pid"
20
+ nginx_pid_file_path="$nginx_info_path/nginx.pid"
22
21
 
23
22
  conf_version=$(awk '{print $1}' "${pkg_path}"/version)
24
23
  echo "$conf_version"
25
24
 
26
25
  copy_nginx_conf_and_write_verison() {
27
26
  mkdir -p "$nginx_conf_install_path"
28
- # 创建pid目录
29
- mkdir -p $nginx_pid_dir
30
- chown -R $user:$usergroup $nginx_pid_dir
31
- chmod 744 -R $nginx_pid_dir
32
-
33
- # 创建日志目录
34
- mkdir -p $nginx_log_path
35
- touch $nginx_log_path/$nginx_log_file
36
- chown -R $user:$usergroup $nginx_log_path
37
- chmod 744 -R $nginx_log_path
27
+ # 创建pid目录. 创建日志目录
28
+ mkdir -p $nginx_info_path
29
+ touch $nginx_info_path/$nginx_log_file
30
+ chown -R $user:$usergroup $nginx_info_path
31
+ chmod 744 -R $nginx_info_path
38
32
 
39
33
  access_log_super="access_log /dev/stdout main"
40
34
  error_log_super="error_log /dev/stderr warn"
41
- access_log="access_log $nginx_log_path/$nginx_log_file main"
42
- error_log="error_log $nginx_log_path/$nginx_log_file"
35
+ access_log="access_log $nginx_info_path/$nginx_log_file main"
36
+ error_log="error_log $nginx_info_path/$nginx_log_file"
43
37
  pid_file="pid $nginx_pid_file_path"
44
38
 
45
39
  exec=$(get_exec_path)
@@ -145,16 +139,16 @@ get_exec_cmd() {
145
139
 
146
140
  add_nginx_service() {
147
141
  #添加到服务
148
- exec_cmd="$(get_exec_cmd) -e $nginx_log_path/$nginx_log_file"
142
+ exec_cmd="$(get_exec_cmd) -e $nginx_info_path/$nginx_log_file"
149
143
  cp "$pkg_path"/nginx/nginx.service.tpl ./nginx.service
150
144
 
151
- check_cmd="$exec -t -c $nginx_conf_path -e $nginx_log_path/$nginx_log_file"
145
+ check_cmd="$exec -t -c $nginx_conf_path -e $nginx_info_path/$nginx_log_file"
152
146
  version=$(echo "$conf_version" | grep -oP '\d+\.\d+\.\d+')
153
147
 
154
148
  sed -i "s#_user_group_#$usergroup#g" ./nginx.service
155
149
  sed -i "s#_user_#$user#g" ./nginx.service
156
150
  sed -i "s#_exec_cmd_#$exec_cmd #g" ./nginx.service
157
- sed -i "s#_log_path_#$nginx_log_path#g" ./nginx.service
151
+ sed -i "s#_log_path_#$nginx_info_path#g" ./nginx.service
158
152
  sed -i "s#_log_file_#$nginx_log_file#g" ./nginx.service
159
153
  sed -i "s#_conf_path_#$nginx_conf_path#g" ./nginx.service
160
154
  sed -i "s#_version_#$version#g" ./nginx.service
@@ -171,6 +165,21 @@ add_nginx_service() {
171
165
  rm -rf /usr/lib/systemd/system/"$app_name".nginx.service
172
166
  fi
173
167
  }
168
+
169
+ add_log_rotate(){
170
+ mkdir -p /etc/logrotate.d
171
+
172
+ rm -rf /etc/logrotate.d/${app_name}.nginx
173
+ #添加日志翻转
174
+ cp "$pkg_path"/nginx/nginx.logrotate.tpl ./nginx.logrotate
175
+
176
+ sed -i "s#__usergroup__#$usergroup#g" ./nginx.logrotate
177
+ sed -i "s#__user__#$user#g" ./nginx.logrotate
178
+ sed -i "s#__app_name__#$app_name#g" ./nginx.logrotate
179
+ sed -i "s#__pid_file__#$nginx_pid_file_path#g" ./nginx.logrotate
180
+
181
+ cp -f ./nginx.logrotate /etc/logrotate.d/${app_name}.nginx
182
+ }
174
183
  #------------------------------------ nginx服务配置文件服务 end----------------------------------
175
184
 
176
185
 
@@ -247,7 +256,7 @@ install_nginx_binary() {
247
256
  log_error "nginx installation failed!"
248
257
  fi
249
258
 
250
- cp "$nginx_binary_install_path"sbin/nginx /usr/sbin/
259
+ ln -sf "$nginx_binary_install_path"sbin/nginx /usr/sbin/nginx
251
260
 
252
261
  # 修改/etc/nginx 用户(组)
253
262
  chown -R $user:$usergroup "$nginx_binary_install_path"
@@ -12,6 +12,8 @@ if [[ "${mode}" == "standalone" ]]; then
12
12
  mode=1
13
13
  elif [[ "${mode}" == "cluster" ]]; then
14
14
  mode=2
15
+ elif [[ "${mode}" == "static" ]]; then
16
+ mode=3
15
17
  else
16
18
  mode=''
17
19
  fi
@@ -28,6 +30,10 @@ while [ $# -gt 0 ]; do
28
30
  mode=2
29
31
  shift
30
32
  ;;
33
+ -SS | -static)
34
+ mode=3
35
+ shift
36
+ ;;
31
37
  -h | --help)
32
38
  echo "supported parameters: "
33
39
  echo "-S, -standalone install for supervisord startup mode, conflict with -C"
package/dist/pack.js CHANGED
@@ -40,7 +40,8 @@ async function pack(version) {
40
40
  fs.writeFileSync(path.resolve(assetsDir, "version"), version, { encoding: "utf-8" });
41
41
  fs.writeFileSync(path.resolve(nginxDir, "version"), version, { encoding: "utf-8" });
42
42
  logger.info(pc.green(`version: ${version} added`));
43
- const assetInstallPath = `/opt/${projectName}/`;
43
+ const installDir = releaseConf.installDir.endsWith("/") ? releaseConf.installDir.replace(/\/$/, "") : releaseConf.installDir;
44
+ const assetInstallPath = `${installDir}/${projectName}/`;
44
45
  logger.info(pc.green(`start to replace variants in common.sh`));
45
46
  replaceFileContent({
46
47
  filePath: path.resolve(projectDir, "script", "common.sh"),
package/dist/prepare.js CHANGED
@@ -7,7 +7,7 @@ import { fileURLToPath } from 'node:url';
7
7
  import { logger } from './logger.js';
8
8
  import 'picocolors';
9
9
 
10
- const installMode = ["standalone", "cluster", "both"];
10
+ const installMode = ["standalone", "cluster", "static", "all"];
11
11
  const __work_dir = process.env.INIT_CWD || process.cwd();
12
12
  const __releaseDir = path.resolve(__work_dir, ".release");
13
13
  const __filename = fileURLToPath(import.meta.url);
@@ -22,6 +22,11 @@ function parseConf(file) {
22
22
  return {};
23
23
  }
24
24
  }
25
+ function isValidLinuxPath(path2) {
26
+ const absolutePathPattern = /^\//;
27
+ const relativePathPattern = /^(\.\/|\.\.\/)/;
28
+ return absolutePathPattern.test(path2) || relativePathPattern.test(path2);
29
+ }
25
30
  const releaseConf = Object.assign({
26
31
  host: "",
27
32
  token: "",
@@ -31,10 +36,11 @@ const releaseConf = Object.assign({
31
36
  assetsDir: "dist",
32
37
  user: "root",
33
38
  userGroup: "root",
34
- installMode: "both"
39
+ installMode: "both",
40
+ installDir: "/opt"
35
41
  }, parseConf(__releaseConfPath));
36
42
  const $ = execa({ encoding: "utf8" });
37
- async function prepare() {
43
+ async function prepare({ callBy } = { callBy: "postinstall" }) {
38
44
  const copyFiles = () => {
39
45
  fs.cpSync(path.resolve(__dirname, ".release"), __releaseDir, { recursive: true });
40
46
  };
@@ -43,7 +49,7 @@ async function prepare() {
43
49
  copyFiles();
44
50
  logger.tip(`\u8BF7\u6CE8\u610F\u4FEE\u6539.release/${releaseConfFileName} \u914D\u7F6E\u4FE1\u606F`);
45
51
  } else {
46
- if (!process.env.INIT_CWD) {
52
+ if (callBy === "init") {
47
53
  const shouldRegenerate = await inquirer.confirm(
48
54
  {
49
55
  message: ".release\u914D\u7F6E\u5DF2\u5B58\u5728\uFF0C\u662F\u5426\u91CD\u65B0\u751F\u6210\uFF1F"
@@ -78,6 +84,10 @@ async function checkEnvInfo() {
78
84
  logger.error(`The field: [${field}]'s value should be one of ${installMode.join(" | ")}`);
79
85
  process.exit(1);
80
86
  }
87
+ if (field === "installDir" && !isValidLinuxPath(value)) {
88
+ logger.error(`The field: [${field}]'s value is not a legal path`);
89
+ process.exit(1);
90
+ }
81
91
  }
82
92
  }
83
93
 
@@ -11,7 +11,7 @@ import 'node:url';
11
11
  (async function startPrepare() {
12
12
  try {
13
13
  logger.info("start to generate .release configuration ");
14
- await prepare();
14
+ await prepare({ callBy: "postinstall" });
15
15
  logger.info("done");
16
16
  } catch (error) {
17
17
  console.error(`release-helper error: `, error);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@wjwjq/release-helper",
3
- "version": "0.1.4",
3
+ "version": "0.1.6",
4
4
  "description": "generate deployment package for frontend, include nginx...",
5
5
  "main": "dist/index.js",
6
6
  "module": "dist/index.js",
@@ -63,7 +63,7 @@
63
63
  "node": "^18.20.0 || >=20.0.0"
64
64
  },
65
65
  "scripts": {
66
- "localpack": "pnpm link --global",
66
+ "localpack": "pnpm build && pnpm link --global",
67
67
  "postinstall": "node dist/start_prepare.js",
68
68
  "build": "rm -rf dist && rollup -c",
69
69
  "prepublish": "pnpm build"
@@ -1,73 +0,0 @@
1
- # release-helper
2
-
3
- 打包 和发布辅助工具, 集成nginx二进制文件,支持supervisor和systemctl启动安装模式
4
-
5
- 服务器端安装和更新,请看发布后文档
6
-
7
- ## 使用
8
-
9
- ### 推荐
10
-
11
- 在package.json中添加如下命令, 后续通过pnpm pak/pub/publish使用
12
-
13
- ```bash
14
- "pak": "release-helper pack",
15
- "pub": "release-helper publish",
16
- "release": "release-helper release",
17
- ```
18
-
19
- ### 单独使用命令
20
-
21
- 请在项目根目录,使用命令
22
-
23
- #### 初始化
24
-
25
- 常规来讲,通过pnpm安装时,会自动在项目根目录位置,生成.release目录,若未生成,请手动生成
26
-
27
- ```bash
28
- release-helper init
29
- ```
30
-
31
- #### 打包
32
-
33
- 仅打包成xx.tar.gz 需指定release.conf.yaml中assetsDir字段
34
-
35
- ```bash
36
- release-helper pack
37
- ```
38
-
39
- #### 发版
40
-
41
- 发布git release相关版本; 需指定release.conf.yaml中host等相关字段
42
-
43
- ```bash
44
- release-helper release
45
- ```
46
-
47
- ## .release 目录说明
48
-
49
- ### doc 目录
50
-
51
- 用于release时附带的文档,文档中可以使用指定变量占位,后续执行release-helper release时会自动遍历,并替换所有变量
52
-
53
- 可使用变量及说明:
54
-
55
- | **占位符** | **含义** |
56
- | ------------- | ---------------------------------------------------- |
57
- | \$APP\_NAME\$ | 应用名称(自动读取package.json中name字段值) |
58
- | \$VERSION\$ | 用户指定的版本号 |
59
- | \$PKG_NAME\$ | tar.gz包名称(值为\$APP_NAME\$\_\$VERSION\$.tar.gz) |
60
-
61
- ### nginx 目录
62
-
63
- 用于存放服务器端nginx的启动配置文件等,部分占位说明及占位符请勿删除,会在服务器端安装或更新时,由脚本自动替换
64
-
65
- 文件说明:
66
- | **文件或目录** | **说明** |
67
- | -------------- | --------------------------------------------------------- |
68
- | ca | nginx https使用到的证书,变更时需对应修改nginx.conf中的值 |
69
- | nginx.conf | nginx启动时 需要的配置文件 |
70
-
71
- ### release.conf.yaml
72
-
73
- 打包发布相关配置项