From 3f7784318d4dda2a0c68d274f8a889a090a9ec4d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=96=9C=E6=AC=A2=E8=8A=9D=E5=A3=AB=E7=9A=84=E5=A6=B9?= =?UTF-8?q?=E5=A6=B9?= Date: Wed, 22 Jun 2022 09:28:12 +0800 Subject: [PATCH] =?UTF-8?q?refactor(script):=E8=84=9A=E6=9C=AC=E9=85=8D?= =?UTF-8?q?=E7=BD=AE=E6=96=87=E4=BB=B6=E4=BF=AE=E6=94=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 提供页面部署脚本 - Dockerfile修改,优化构建步骤 - nginx配置文件修改,自定义端口 - --- Dockerfile | 5 +++-- nginx.conf | 42 ++++++++++++++++++++++++++++++++++++++++ scripts/build_image.sh | 12 +++++++----- scripts/page_deploy.sh | 44 ++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 96 insertions(+), 7 deletions(-) create mode 100644 nginx.conf create mode 100644 scripts/page_deploy.sh diff --git a/Dockerfile b/Dockerfile index 390fe74..42d5004 100644 --- a/Dockerfile +++ b/Dockerfile @@ -16,5 +16,6 @@ FROM registry.cn-hangzhou.aliyuncs.com/142vip/nginx:latest # 将dist文件中的内容复制到 /usr/share/nginx/html/ 这个目录下面 注意:--from参数 COPY --from=build_base /apps/docs/.vuepress/dist/ /usr/share/nginx/html/ -## 暴露端口 -EXPOSE 80 \ No newline at end of file +COPY nginx.conf /etc/nginx/ +EXPOSE 7000 +CMD ["nginx", "-g", "daemon off;"] \ No newline at end of file diff --git a/nginx.conf b/nginx.conf new file mode 100644 index 0000000..d4a5b94 --- /dev/null +++ b/nginx.conf @@ -0,0 +1,42 @@ +# 参考:https://www.likecs.com/ask-1256888.html +user root; +worker_processes auto; +error_log /var/log/nginx/error.log warn; +events { + worker_connections 1024; +} +http { + include /etc/nginx/mime.types; + default_type application/octet-stream; + sendfile off; + access_log off; + keepalive_timeout 3000; + server { + listen 7000; + server_name localhost; + #charset koi8-r; + access_log /var/log/nginx/access.log main; + error_log /var/log/nginx/error.log error; + ## 静态资源代理 + location / { + gzip on; #开启或关闭gzip on off + gzip_disable "msie6"; #不使用gzip IE6 + gzip_min_length 100k; #gzip压缩最小文件大小,超出进行压缩(自行调节) + gzip_buffers 4 16k; #buffer 不用修改 + gzip_comp_level 8; #压缩级别:1-10,数字越大压缩的越好,时间也越长 + gzip_types text/plain application/x-javascript text/css application/xml text/javascript application/x-httpd-php image/jpeg image/gif image/png; # 压缩文件类型 + # root 根目录,默认nginx镜像的html文件夹,可以指定其他 + root /usr/share/nginx/html; + index index.html index.htm; + # 如果vue-router使用的是history模式,需要设置这个 + try_files $uri $uri/ /index.html; + } + ## 错误页面 + error_page 404 /404.html; + error_page 500 502 503 504 /50x.html; + location = /50x.html { + root /usr/share/nginx/html; + } + } +} + diff --git a/scripts/build_image.sh b/scripts/build_image.sh index 0a9fe90..5a8cfaa 100644 --- a/scripts/build_image.sh +++ b/scripts/build_image.sh @@ -15,6 +15,8 @@ readonly warnLogger="\033[1;33m" readonly currentTime=$(date "+%Y-%m-%d %H:%M:%S") ## 项目名称 readonly projectName="408CSFamily" +## 仓库地址 +readonly repoAddress="registry.cn-hangzhou.aliyuncs.com/142vip/doc_book:" ## 版本号 version=${1} @@ -28,7 +30,7 @@ prepare_check(){ run(){ echo -e "${successLogger}---------------- shell doc_book start ---------------- " - docker build -t registry.cn-hangzhou.aliyuncs.com/142vip/doc_book:"${projectName}_${version}" . + docker build -t "${repoAddress}${projectName}_${version}" . echo -e "${successLogger}---------------- shell doc_book end ---------------- " push_docker_image } @@ -38,14 +40,14 @@ run(){ push_docker_image(){ - if [[ "$(docker images -q registry.cn-hangzhou.aliyuncs.com/142vip/doc_book:"${projectName}_${version}" 2> /dev/null)" != "" ]]; + if [[ "$(docker images -q "${repoAddress}${projectName}_${version}" 2> /dev/null)" != "" ]]; then ## 推送 - docker push registry.cn-hangzhou.aliyuncs.com/142vip/doc_book:"${projectName}_${version}" + docker push "${repoAddress}${projectName}_${version}" echo -e "${successLogger}---------------- 上传镜像成功,删除本地镜像 ---------------- " - docker rmi registry.cn-hangzhou.aliyuncs.com/142vip/doc_book:"${projectName}_${version}" + docker rmi "${repoAddress}${projectName}_${version}" else - echo -e "${errorLogger}${currentTime}:镜像:registry.cn-hangzhou.aliyuncs.com/142vip/doc_book:${projectName}_${version}不存在" + echo -e "${errorLogger}${currentTime}:镜像:${repoAddress}${projectName}_${version}不存在" fi exit 0 } diff --git a/scripts/page_deploy.sh b/scripts/page_deploy.sh new file mode 100644 index 0000000..5dd95b3 --- /dev/null +++ b/scripts/page_deploy.sh @@ -0,0 +1,44 @@ +#!/usr/bin/env sh + +### + # @Description: 静态资源网站部署脚本 + # @Version: Beta1.0 + # @Author: 【B站&公众号】Rong姐姐好可爱 + # @Date: 2021-02-19 22:34:57 + # @LastEditors: 【B站&公众号】Rong姐姐好可爱 + # @LastEditTime: 2022-04-18 23:35:15 +### + +commitInfo=${1} + +set -e + +# 进入上级目录,并编译 +npm run build + +## 切换到dist文件目录 +cd docs/.vuepress/dist + +git init +git add -A + +## 如果没有输入commit信息,则采用默认 +if [ "${commitInfo}" -eq "" ]; then + commitInfo="408CSFamily page init" +fi + +git commit -m "refactor:${commitInfo}" + + +## 配置个人信息 +git config user.name "喜欢吃芝士葡萄的妹妹" +git config user.email "fairy0115@2925.com" + +# if you are deploying to https://.github.io +# git push -f git@github.com:/.github.io.git master + +# if you are deploying to https://.github.io/ +git push -f https://github.com/mmdapl/JavaScriptCollection.git master:pages/github + + +cd - \ No newline at end of file