From dccfbcfea64e2abd13cfb36ff5ea74fef2273c9f Mon Sep 17 00:00:00 2001 From: "142vip.cn" Date: Tue, 7 Nov 2023 18:44:12 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20docker=E9=95=9C=E5=83=8F=E6=96=B0?= =?UTF-8?q?=E5=A2=9Egit=E7=9B=B8=E5=85=B3=E8=AE=B0=E5=BD=95=E7=9A=84label?= =?UTF-8?q?=E6=A0=87=E8=AE=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .travis.yml | 19 ------------------- Dockerfile | 18 ++++++++++++++++-- package.json | 4 ++-- scripts/bundle | 47 +++++++++++++++++++++++++++++++++++++++-------- 4 files changed, 57 insertions(+), 31 deletions(-) delete mode 100644 .travis.yml diff --git a/.travis.yml b/.travis.yml deleted file mode 100644 index 70c44566..00000000 --- a/.travis.yml +++ /dev/null @@ -1,19 +0,0 @@ -# 参考链接: https://docs.travis-ci.com/user/languages/javascript-with-nodejs/ -language: node_js -node_js: - - 16 -# 环境变量 -#env: -# - EMBER_VERSION=default -# - EMBER_VERSION=release -# - EMBER_VERSION=beta -# - EMBER_VERSION=canary - -# 安装依赖前,先安装pnpm -before_install: - - "npm install -g npm@7" -install: - - pnpm i -script: - - pnpm lintfix - - pnpm build \ No newline at end of file diff --git a/Dockerfile b/Dockerfile index 78933675..44eaa7a7 100644 --- a/Dockerfile +++ b/Dockerfile @@ -21,10 +21,24 @@ RUN if [ "$CONTAINER_BUILD" = "true" ]; then \ FROM registry.cn-hangzhou.aliyuncs.com/142vip/nginx:1.23.0-alpine +ARG APP_NAME ARG APP_VERSION -LABEL version=$APP_VERSION description="408CSFamily合集" -LABEL author="【Github&公众号】:Rong姐姐好可爱" email="fairy_408@2925.com" +ARG AUTHOR +ARG EMAIL +ARG DESCRIPTION +ARG GIT_HASH +ARG GIT_MESSAGE +ARG HOME_PAGE +# 作者信息 +LABEL "author.name"="$AUTHOR" "author.email"="$EMAIL" + +# 项目信息 +LABEL "repo.name"=$APP_NAME "repo.version"=$APP_VERSION \ + "repo.homePage"="$HOME_PAGE" "repo.description"="$DESCRIPTION" + +# Git信息 +LABEL "git.hash"="$GIT_HASH" "git.message"="$GIT_MESSAGE" # 将dist文件中的内容复制到 /usr/share/nginx/html/ 这个目录下面 注意:--from参数 COPY --from=build_base /apps/docs/.vuepress/dist/ /usr/share/nginx/html/ COPY nginx.conf /etc/nginx/ diff --git a/package.json b/package.json index 7c040217..6baf5c6a 100644 --- a/package.json +++ b/package.json @@ -6,7 +6,7 @@ "name": "微信公众号:储凡", "email": "fairy_408@2925.com", "url": "https://github.com/142vip", - "homePage": "https://www.142vip.cn" + "homePage": "https://408.142vip.cn" }, "packageManager": "pnpm@8.9.2", "engines": { @@ -18,7 +18,7 @@ "postinstall": "pnpm build:mark-map", "prepare": "husky install", "dev": "vuepress dev docs", - "build": "./scripts/bundle build", + "build": "vuepress build docs", "build:proxy": "./scripts/bundle build_proxy", "build:mark-map": "./scripts/mark-map", "deploy:vercel": "vercel --prod", diff --git a/scripts/bundle b/scripts/bundle index e43929a7..bfb949b8 100755 --- a/scripts/bundle +++ b/scripts/bundle @@ -12,23 +12,45 @@ */ const {execShell} = require('./.exec') +const {execSync} = require('child_process'); const {Select} = require('enquirer') -const packageVersion = require('../package.json').version -const projectName = '408CSFamily' // 仓库地址 const repoAddress = 'registry.cn-hangzhou.aliyuncs.com/142vip/doc_book' + +const packageInfo = require('../package.json') +const packageVersion = packageInfo.version +const projectName = packageInfo.name + // 镜像地址 const imageName = `${repoAddress}:${projectName}-${packageVersion}` +/** + * 获取最近一次Git提交信息 + * - 短哈希值 + * - 提交信息 + */ +async function getGitInfo() { + // 执行 git log 命令获取最新一次提交的哈希值和消息 + const gitLog = execSync('git log --no-merges -1 --pretty=format:"%h %s"').toString(); + + // 分割输出字符串以获取哈希值和消息 + const [commitHash, ...commitMessage] = gitLog.trim().split(' '); + + // 输出最近一次提交的信息 + return { + gitHash: commitHash, + gitMessage: commitMessage.join('') + } +} + /** * 获取构建镜像的脚本 - * @param containerBuild - * @param preBuild - * @param needProxy - * @returns {string[]} + * @param containerBuild 是否容器内构建 + * @param preBuild 是否预编译 + * @param needProxy 是否配置代理路径 */ -function getBuildImageScript({containerBuild, preBuild, needProxy = false}) { +async function getBuildImageScript({containerBuild, preBuild, needProxy = false}) { // 基础构建脚本 let baseBuildScript = '' @@ -36,13 +58,22 @@ function getBuildImageScript({containerBuild, preBuild, needProxy = false}) { baseBuildScript = needProxy ? './scripts/bundle build_proxy' : './scripts/bundle build' } + const {gitHash, gitMessage} = await getGitInfo() + return [ // 构建镜像 ` ${baseBuildScript} docker build \ - --build-arg APP_VERSION=${packageVersion} \ --build-arg CONTAINER_BUILD=${containerBuild} \ + --build-arg APP_VERSION=${packageVersion} \ + --build-arg APP_NAME=${projectName} \ + --build-arg HOME_PAGE=${packageInfo.authorInfo.homePage} \ + --build-arg AUTHOR=${packageInfo.authorInfo.name} \ + --build-arg EMAIL=${packageInfo.authorInfo.email} \ + --build-arg DESCRIPTION=${packageInfo.description} \ + --build-arg GIT_HASH=${gitHash} \ + --build-arg GIT_MESSAGE="${gitMessage}" \ -t ${imageName} . `, // 推送镜像