mirror of
https://github.com/142vip/408CSFamily.git
synced 2026-02-03 18:43:20 +08:00
feat: docker镜像新增git相关记录的label标记
This commit is contained in:
19
.travis.yml
19
.travis.yml
@@ -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
|
||||
18
Dockerfile
18
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/
|
||||
|
||||
@@ -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",
|
||||
|
||||
@@ -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}`
|
||||
|
||||
/**
|
||||
* 获取构建镜像的脚本
|
||||
* @param containerBuild
|
||||
* @param preBuild
|
||||
* @param needProxy
|
||||
* @returns {string[]}
|
||||
* 获取最近一次Git提交信息
|
||||
* - 短哈希值
|
||||
* - 提交信息
|
||||
*/
|
||||
function getBuildImageScript({containerBuild, preBuild, needProxy = false}) {
|
||||
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 是否配置代理路径
|
||||
*/
|
||||
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} .
|
||||
`,
|
||||
// 推送镜像
|
||||
|
||||
Reference in New Issue
Block a user