Skip to content

Commit

Permalink
feat: docker镜像新增git相关记录的label标记
Browse files Browse the repository at this point in the history
  • Loading branch information
142vip.cn committed Nov 7, 2023
1 parent 0c42bec commit dccfbcf
Show file tree
Hide file tree
Showing 4 changed files with 57 additions and 31 deletions.
19 changes: 0 additions & 19 deletions .travis.yml

This file was deleted.

18 changes: 16 additions & 2 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -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="[email protected]"
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/
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
"name": "微信公众号:储凡",
"email": "[email protected]",
"url": "https://github.com/142vip",
"homePage": "https://www.142vip.cn"
"homePage": "https://408.142vip.cn"
},
"packageManager": "[email protected]",
"engines": {
Expand All @@ -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",
Expand Down
47 changes: 39 additions & 8 deletions scripts/bundle
Original file line number Diff line number Diff line change
Expand Up @@ -12,37 +12,68 @@
*/

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 = ''

if (preBuild) {
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} .
`,
// 推送镜像
Expand Down

0 comments on commit dccfbcf

Please sign in to comment.