@wjwjq/release-helper 0.2.95 → 0.2.97

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.
@@ -1,51 +1,55 @@
1
1
  #!/bin/bash
2
2
 
3
3
  # 安装包所在路径
4
- pkg_path="${project_path}/pkg"
4
+ readonly PKG_DIR="${PROJECT_PATH}/pkg"
5
5
 
6
6
  #------------------------------------ nginx服务配置文件服务 start----------------------------------
7
7
  # 配置文件所在路径
8
- new_nginx_conf_path="${pkg_path}/nginx"
8
+ readonly NEW_NGINX_CONF_PATH="${PKG_DIR}/nginx"
9
9
 
10
10
  # 指定安装目录
11
- nginx_conf_install_path="$prefix/opt/${app_name}/nginx/"
11
+ readonly NGINX_CONF_INSTALL_PATH="$prefix/opt/${APP_NAME}/nginx/"
12
12
 
13
13
  # nginx服务配置文件路径
14
- nginx_conf_path="${nginx_conf_install_path}nginx.conf"
14
+ readonly NGINX_CONF_PATH="${NGINX_CONF_INSTALL_PATH}nginx.conf"
15
15
 
16
16
  # asset_path="$prefix/opt/posidon-frontend/"
17
- nginx_info_path="/var/log/${app_name}"
18
- nginx_log_file="nginx.log"
17
+ readonly NGINX_INFO_PATH="/var/log/${APP_NAME}"
18
+ readonly NGINX_LOG_FILE="nginx.log"
19
19
  #不放在var/run 是因为重启后 var/run/下面的文件及目录会被清除
20
- nginx_pid_file_path="$nginx_info_path/nginx.pid"
20
+ readonly NGINX_PID_FILE_PATH="$NGINX_INFO_PATH/nginx.pid"
21
21
 
22
- conf_version=$(awk '{print $1}' "${pkg_path}"/version)
22
+ readonly MIME_TYPE_PATH=" ${MIME_TYPE}/"
23
+
24
+
25
+ conf_version=$(awk '{print $1}' "${PKG_DIR}"/version)
23
26
  echo "$conf_version"
24
27
 
25
- copy_nginx_conf_and_write_verison() {
26
- mkdir -p "$nginx_conf_install_path"
28
+ copy_nginx_conf_and_write_version() {
29
+ mkdir -p "$NGINX_CONF_INSTALL_PATH"
27
30
  # 创建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
31
+ mkdir -p $NGINX_INFO_PATH
32
+ touch $NGINX_INFO_PATH/$NGINX_LOG_FILE
33
+ chown -R $user:$usergroup $NGINX_INFO_PATH
34
+ chmod 744 -R $NGINX_INFO_PATH
32
35
 
33
36
  access_log_super="access_log /dev/stdout main"
34
37
  error_log_super="error_log /dev/stderr warn"
35
- access_log="access_log $nginx_info_path/$nginx_log_file main"
36
- error_log="error_log $nginx_info_path/$nginx_log_file"
37
- pid_file="pid $nginx_pid_file_path"
38
+ access_log="access_log $NGINX_INFO_PATH/$NGINX_LOG_FILE main"
39
+ error_log="error_log $NGINX_INFO_PATH/$NGINX_LOG_FILE"
40
+ pid_file="pid $NGINX_PID_FILE_PATH"
41
+ mime_type="include $INSTALL_PATH/mime.types;"
38
42
 
39
43
  exec=$(get_exec_path)
40
44
 
41
- # if [ -f "$nginx_conf_path" ]; then
42
- # old_version=$(sed -n '1p' "$nginx_conf_path" | sed 's/# version: //' | sed "s/\s\+//g")
45
+ # if [ -f "$NGINX_CONF_PATH" ]; then
46
+ # old_version=$(sed -n '1p' "$NGINX_CONF_PATH" | sed 's/# version: //' | sed "s/\s\+//g")
43
47
 
44
48
  # if [[ -n "${old_version}" ]]; then
45
49
  # now=$(date "+%Y-%m-%d_%H:%M:%S")
46
50
 
47
51
  # # echo "nginx_"$old_version"_"$now".conf"
48
- # mv "$nginx_conf_path" "${nginx_conf_install_path}"/"$app_name".nginx_"$old_version"_"$now".conf
52
+ # mv "$NGINX_CONF_PATH" "${NGINX_CONF_INSTALL_PATH}"/"$APP_NAME".nginx_"$old_version"_"$now".conf
49
53
  # fi
50
54
  # fi
51
55
 
@@ -53,7 +57,7 @@ copy_nginx_conf_and_write_verison() {
53
57
  nginx_version=$($exec -v 2>&1)
54
58
 
55
59
  tmp_file='./nginx/nginx.conf'
56
- cp -rf "$new_nginx_conf_path" ./
60
+ cp -rf "$NEW_NGINX_CONF_PATH" ./
57
61
 
58
62
  sed -i "1i\# ${nginx_version}" $tmp_file
59
63
  sed -i "1i\# version: ${conf_version}" $tmp_file
@@ -89,7 +93,7 @@ copy_nginx_conf_and_write_verison() {
89
93
  # fi
90
94
  fi
91
95
 
92
- n=$(grep -wn "#PID_FILE_PALCEHOLDER" $tmp_file | awk -F: '{print $1}' | sed -n 1p)
96
+ n=$(grep -wn "#PID_FILE_PLACEHOLDER" $tmp_file | awk -F: '{print $1}' | sed -n 1p)
93
97
  if [[ -n "${n}" ]]; then
94
98
  sed -i "${n}c ${pid_file};" $tmp_file
95
99
  # 非supervisorctl
@@ -107,23 +111,23 @@ copy_nginx_conf_and_write_verison() {
107
111
  fi
108
112
 
109
113
  # 拷贝整个nginx目录
110
- mv -fb ./nginx/* "$nginx_conf_install_path"
114
+ mv -fb ./nginx/* "$NGINX_CONF_INSTALL_PATH"
111
115
 
112
116
  mkdir -p /data/command/
113
117
  log "nginx start command: $(get_exec_cmd)"
114
- echo "$exec -c $nginx_conf_path" >/data/command/nginx
118
+ echo "$exec -c $NGINX_CONF_PATH" >/data/command/nginx
115
119
 
116
120
  if [[ $? == 0 ]]; then
117
- log_success "$conf_version $nginx_conf_path replaced successfully!"
121
+ log_success "$conf_version $NGINX_CONF_PATH replaced successfully!"
118
122
  else
119
- log_error "$conf_version $nginx_conf_path replaced failed!"
123
+ log_error "$conf_version $NGINX_CONF_PATH replaced failed!"
120
124
  fi
121
125
  }
122
126
 
123
127
  get_exec_path() {
124
128
  cmd=''
125
129
  if [[ -n "${prefix}" ]]; then
126
- cmd="${nginx_conf_install_path}/sbin/nginx"
130
+ cmd="${NGINX_CONF_INSTALL_PATH}/sbin/nginx"
127
131
  else
128
132
  cmd="/usr/sbin/nginx"
129
133
  fi
@@ -134,63 +138,60 @@ get_exec_path() {
134
138
  get_exec_cmd() {
135
139
  exec=$(get_exec_path)
136
140
 
137
- echo "$exec -c $nginx_conf_path"
141
+ echo "$exec -c $NGINX_CONF_PATH"
138
142
  }
139
143
 
140
144
  add_nginx_service() {
141
145
  #添加到服务
142
- exec_cmd="$(get_exec_cmd) -e $nginx_info_path/$nginx_log_file"
143
- cp "$pkg_path"/nginx/nginx.service.tpl ./nginx.service
146
+ exec_cmd="$(get_exec_cmd) -e $NGINX_INFO_PATH/$NGINX_LOG_FILE"
147
+ cp "$PKG_DIR"/nginx/nginx.service.tpl ./nginx.service
144
148
 
145
- check_cmd="$exec -t -c $nginx_conf_path -e $nginx_info_path/$nginx_log_file"
149
+ check_cmd="$exec -t -c $NGINX_CONF_PATH -e $NGINX_INFO_PATH/$NGINX_LOG_FILE"
146
150
  version=$(echo "$conf_version" | grep -oP '\d+\.\d+\.\d+')
147
151
 
148
152
  sed -i "s#_user_group_#$usergroup#g" ./nginx.service
149
153
  sed -i "s#_user_#$user#g" ./nginx.service
150
154
  sed -i "s#_exec_cmd_#$exec_cmd #g" ./nginx.service
151
- sed -i "s#_log_path_#$nginx_info_path#g" ./nginx.service
152
- sed -i "s#_log_file_#$nginx_log_file#g" ./nginx.service
153
- sed -i "s#_conf_path_#$nginx_conf_path#g" ./nginx.service
155
+ sed -i "s#_log_path_#$NGINX_INFO_PATH#g" ./nginx.service
156
+ sed -i "s#_log_file_#$NGINX_LOG_FILE#g" ./nginx.service
157
+ sed -i "s#_conf_path_#$NGINX_CONF_PATH#g" ./nginx.service
154
158
  sed -i "s#_version_#$version#g" ./nginx.service
155
- sed -i "s#_pid_file_#$nginx_pid_file_path#g" ./nginx.service
159
+ sed -i "s#_pid_file_#$NGINX_PID_FILE_PATH#g" ./nginx.service
156
160
  #sed -i "s#_start_check_#$check_cmd#g" ./nginx.service
157
161
 
158
162
  if ((mode == 2)); then
159
163
  # systemctl enable nginx
160
- cp ./nginx.service /usr/lib/systemd/system/"$app_name".nginx.service
164
+ cp ./nginx.service /usr/lib/systemd/system/"$APP_NAME".nginx.service
161
165
  systemctl daemon-reload
162
166
 
163
- log_success "add ${app_name}.nginx.service to /usr/lib/systemd/system/"
167
+ log_success "add ${APP_NAME}.nginx.service to /usr/lib/systemd/system/"
164
168
  else
165
- rm -rf /usr/lib/systemd/system/"$app_name".nginx.service
169
+ rm -rf /usr/lib/systemd/system/"$APP_NAME".nginx.service
166
170
  fi
167
171
  }
168
172
 
169
173
  add_log_rotate(){
170
174
  mkdir -p /etc/logrotate.d
171
175
 
172
- rm -rf /etc/logrotate.d/${app_name}.nginx
176
+ rm -rf /etc/logrotate.d/${APP_NAME}.nginx
173
177
  #添加日志翻转
174
- cp "$pkg_path"/nginx/nginx.logrotate.tpl ./nginx.logrotate
178
+ cp "$PKG_DIR"/nginx/nginx.logrotate.tpl ./nginx.logrotate
175
179
 
176
180
  sed -i "s#__usergroup__#$usergroup#g" ./nginx.logrotate
177
181
  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
182
+ sed -i "s#__APP_NAME__#$APP_NAME#g" ./nginx.logrotate
183
+ sed -i "s#__pid_file__#$NGINX_PID_FILE_PATH#g" ./nginx.logrotate
180
184
 
181
- cp -f ./nginx.logrotate /etc/logrotate.d/${app_name}.nginx
185
+ cp -f ./nginx.logrotate /etc/logrotate.d/${APP_NAME}.nginx
182
186
  }
183
187
  #------------------------------------ nginx服务配置文件服务 end----------------------------------
184
188
 
185
189
 
186
190
  #------------------------------------ nginx 可执行程序相关 start----------------------------------
187
- # 指定安装目录
188
- nginx_binary_install_path="/etc/nginx/"
189
-
190
- mkdir -p "$nginx_binary_install_path"
191
-
192
191
  # 安装包所在路径
193
- nginx_binary_pkg_path="${pkg_path}/nginx_binary"
192
+ readonly NGINX_BINARY_PKG_PATH="${PKG_DIR}/nginx_binary"
193
+
194
+ readonly NGINX_BINARY_INSTALL_PATH="/etc/nginx/"
194
195
 
195
196
  open_port_80() {
196
197
  # 查看防火墙是否开启
@@ -207,74 +208,57 @@ open_port_80() {
207
208
  # 重启防火墙(关键步骤二)
208
209
  firewall-cmd --reload
209
210
  }
210
-
211
- function check_dependency(){
212
- if [[ -z $(rpm -qa | grep ^gcc | grep -v grep) ]];
213
- then
214
- cd ${nginx_binary_pkg_path}/gcc && rpm -Uvh *.rpm --nodeps --force
215
- fi
216
- if [[ -z $(rpm -qa | grep ^gcc-c++ | grep -v grep) ]];
217
- then
218
- cd ${nginx_binary_pkg_path}/g++ && rpm -Uvh *.rpm --nodeps --force
219
- fi
220
- if [[ -z $(rpm -qa | grep ^zlib-devel | grep -v grep) ]];
221
- then
222
- cd ${nginx_binary_pkg_path}/zlib && rpm -Uvh *.rpm --nodeps --force
223
- fi
224
- if [[ -z $(rpm -qa | grep ^openssl-devel | grep -v grep) ]];
225
- then
226
- cd ${nginx_binary_pkg_path}/openssl && rpm -Uvh *.rpm --nodeps --force
227
- fi
228
- if [[ -z $(rpm -qa | grep ^pcre-devel | grep -v grep) ]];
229
- then
230
- cd ${nginx_binary_pkg_path}/pcre && rpm -Uvh *.rpm --nodeps --force
231
- fi
232
-
233
- cd $project_path/script
234
- }
235
-
236
-
237
211
 
238
212
  install_nginx_from_binary(){
239
213
  log "start to install nginx binary"
240
214
 
241
215
  arch=$(uname -m)
242
- ssl_version=$(openssl version | grep -oP '\d+\.\d+' | sed -n '1p' 2>&1)
216
+ system_name=$(uname -r | awk -F'.' '{print $(NF-1)}')
217
+ ssl_full_version=$(openssl version | awk '{print $2}')
218
+ ssl_fuzzy_version=$(openssl version | grep -oP '\d+\.\d+' | sed -n '1p' 2>&1)
219
+ system_name_with_arch=$system_name"."$arch
243
220
 
244
- if [[ -z "${arch}" ]]; then
245
- arch="x86_64"
246
- fi
221
+ # 若存在完整的系统名称.架构.ssl版本的包则优先使用该包安装
222
+ pkg="$NGINX_BINARY_PKG_PATH"/binary/nginx-"$system_name_with_arch"-ssl"$ssl_full_version".tar.gz
247
223
 
248
- if [[ $arch == arm* ]] || [[ $arch = aarch64 ]]; then
249
- arch="arm"
250
- fi
224
+ if [ -f "$pkg" ]; then
225
+ log "current arch: $system_name_with_arch, current ssl_version: $ssl_full_version"
226
+ else
227
+ if [[ -z "${arch}" ]]; then
228
+ arch="x86_64"
229
+ fi
251
230
 
252
- if [[ "${ssl_version}" == "1.0" ]]; then
253
- ssl_version="1.0.2"
254
- fi
231
+ if [[ $arch == arm* ]] || [[ $arch = aarch64 ]]; then
232
+ arch="arm"
233
+ fi
255
234
 
256
- if [[ "${ssl_version}" == "1.1" ]]; then
257
- ssl_version="1.1.1"
258
- fi
235
+ if [[ "${ssl_fuzzy_version}" == "1.0" ]]; then
236
+ ssl_fuzzy_version="1.0.2"
237
+ fi
259
238
 
260
- if [[ "${ssl_version}" == "3.0" ]]; then
261
- ssl_version="3.0.7"
262
- fi
239
+ if [[ "${ssl_fuzzy_version}" == "1.1" ]]; then
240
+ ssl_fuzzy_version="1.1.1"
241
+ fi
263
242
 
264
- if [[ -z "${ssl_version}" ]]; then
265
- ssl_version="1.0.2"
266
- fi
243
+ if [[ "${ssl_fuzzy_version}" == "3.0" ]]; then
244
+ ssl_fuzzy_version="3.0.7"
245
+ fi
267
246
 
268
- pkg="$nginx_binary_pkg_path"/binary/nginx-"$arch"-ssl"$ssl_version".tar.gz
247
+ if [[ -z "${ssl_fuzzy_version}" ]]; then
248
+ ssl_fuzzy_version="1.0.2"
249
+ fi
269
250
 
270
- if [ ! -f "$pkg" ]; then
271
- log_error "Fatal error: nginx-$arch-ssl$ssl_version.tar.gz not matched! contact developer!"
272
- exit 1
273
- fi
251
+ pkg="$NGINX_BINARY_PKG_PATH"/binary/nginx-"$arch"-ssl"$ssl_fuzzy_version".tar.gz
252
+
253
+ if [ ! -f "$pkg" ]; then
254
+ log_error "Fatal error: nginx-$arch-ssl$ssl_fuzzy_version.tar.gz not matched! contact developer!"
255
+ exit 1
256
+ fi
274
257
 
275
- log "current arch: $arch, current ssl_version: $ssl_version"
258
+ log "current arch: $arch, current ssl_version: $ssl_fuzzy_version"
259
+ fi
276
260
 
277
- tar -zxvhf "$pkg" -C "$nginx_binary_install_path" --strip-components 1
261
+ tar -zxvhf "$pkg" -C "$NGINX_BINARY_INSTALL_PATH" --strip-components 1
278
262
 
279
263
  # 检测是否安装成功
280
264
  if [[ $? == 0 ]]; then
@@ -288,7 +272,7 @@ install_nginx_from_binary(){
288
272
 
289
273
  install_nginx_from_source(){
290
274
  log "start to complie and install nginx"
291
- pkg="$nginx_binary_pkg_path"/source/
275
+ pkg="$NGINX_BINARY_PKG_PATH"/source/
292
276
  tar_name=$(ls ${pkg}|grep nginx-.*.tar.gz)
293
277
  tar_dir=${tar_name%.tar.gz*}
294
278
  tar -zxvf "${pkg}"/"${tar_name}"
@@ -300,7 +284,7 @@ install_nginx_from_source(){
300
284
  --with-http_gzip_static_module \
301
285
  --with-http_stub_status_module \
302
286
  --with-stream \
303
- --prefix=${nginx_binary_install_path}
287
+ --prefix=${NGINX_BINARY_INSTALL_PATH}
304
288
 
305
289
  make && make install
306
290
  # 检测是否安装成功
@@ -310,13 +294,13 @@ install_nginx_from_source(){
310
294
  log_error "nginx installation failed!"
311
295
  fi
312
296
 
313
- cp $nginx_binary_install_path/conf/mime.types $nginx_binary_install_path
297
+ cp $NGINX_BINARY_INSTALL_PATH/conf/mime.types $NGINX_BINARY_INSTALL_PATH
314
298
  cd ..
315
299
  }
316
300
 
317
301
  # 安装nginx可执行程序
318
302
  install_nginx_binary() {
319
- log "install nginx to path: ${nginx_binary_install_path}"
303
+ log "install nginx to path: ${NGINX_BINARY_INSTALL_PATH}"
320
304
 
321
305
  if [[ "${nginx_install_mode}" == "source" ]]; then
322
306
  install_nginx_from_source
@@ -326,6 +310,6 @@ install_nginx_binary() {
326
310
 
327
311
  mkdir -p /usr/local/bin
328
312
  mkdir -p /var/log/nginx
329
- ln -sf "$nginx_binary_install_path"sbin/nginx /usr/sbin/nginx
313
+ ln -sf "$NGINX_BINARY_INSTALL_PATH"sbin/nginx /usr/sbin/nginx
330
314
  }
331
315
  #------------------------------------ nginx 可执行程序相关 end ----------------------------------
package/dist/pack.js CHANGED
@@ -35,6 +35,7 @@ async function pack(version) {
35
35
  const projectDir = resolve(__releaseDir, projectName);
36
36
  const assetsDir = resolve(projectDir, "pkg/assets");
37
37
  const nginxDir = resolve(projectDir, "pkg/nginx");
38
+ const scriptDir = resolve(projectDir, "script");
38
39
  fs.cpSync(resolve(__dirname, "deploy"), projectDir, { recursive: true });
39
40
  fs.cpSync(resolve(__work_dir, releaseConf.assetsDir), assetsDir, { recursive: true });
40
41
  fs.writeFileSync(resolve(projectDir, "pkg", "version"), version, { encoding: "utf-8" });
@@ -80,6 +81,9 @@ async function pack(version) {
80
81
  replaced: [["__root__", `${assetInstallPath}assets/`]]
81
82
  // writeToNewFilePath: resolve(nginxDir, `${projectName}.conf`)
82
83
  });
84
+ if (fs.existsSync(resolve(__releaseDir, "script", "after.sh"))) {
85
+ fs.copyFileSync(resolve(__releaseDir, "script", "after.sh"), resolve(scriptDir, "after.sh"));
86
+ }
83
87
  logger.info(pc.green(`start to generate ${zipFileName}`));
84
88
  const zipFilePath = resolve(__releaseDir, zipFileName);
85
89
  await genTarPkg(__releaseDir, projectName, zipFilePath);
package/dist/prepare.js CHANGED
@@ -39,6 +39,8 @@ const releaseConf = Object.assign({
39
39
  userGroup: "root",
40
40
  installMode: "all",
41
41
  installDir: "/opt",
42
+ nginxBinaryDir: "/etc/nginx",
43
+ nginxConfDir: "/etc/nginx",
42
44
  nginxInstallMode: "binary",
43
45
  dockerInstallDir: "",
44
46
  dockerBackupDir: ""
@@ -79,10 +81,7 @@ async function checkEnvInfo() {
79
81
  process.exit(1);
80
82
  }
81
83
  for (let [field, value] of Object.entries(releaseConf)) {
82
- if (!value) {
83
- logger.error(`The field: [${field}] is required in .release/release.conf.yaml!`);
84
- process.exit(1);
85
- }
84
+ validateField(field);
86
85
  if (field === "installMode" && !installMode.includes(value)) {
87
86
  logger.error(`The field: [${field}]'s value should be one of ${installMode.join(" | ")}`);
88
87
  process.exit(1);
@@ -97,5 +96,16 @@ async function checkEnvInfo() {
97
96
  }
98
97
  }
99
98
  }
99
+ function validateFields(fields) {
100
+ for (let field of fields) {
101
+ validateField(field);
102
+ }
103
+ }
104
+ function validateField(field) {
105
+ if (!releaseConf[field]) {
106
+ logger.error(`The field: [${field}] is required in .release/release.conf.yaml!`);
107
+ process.exit(1);
108
+ }
109
+ }
100
110
 
101
- export { __dirname, __releaseConfPath, __releaseDir, __work_dir, checkEnvInfo, prepare, releaseConf, releaseConfFileName };
111
+ export { __dirname, __releaseConfPath, __releaseDir, __work_dir, checkEnvInfo, prepare, releaseConf, releaseConfFileName, validateField, validateFields };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@wjwjq/release-helper",
3
- "version": "0.2.95",
3
+ "version": "0.2.97",
4
4
  "description": "generate deployment package for frontend, include nginx...",
5
5
  "main": "dist/index.js",
6
6
  "module": "dist/index.js",