Skip to content

Commit

Permalink
fix(backend): 介质文件打包增加更新时间 #1916
Browse files Browse the repository at this point in the history
  • Loading branch information
iSecloud authored and zhangzhw8 committed Nov 18, 2023
1 parent c3dd280 commit c06d373
Show file tree
Hide file tree
Showing 8 changed files with 46 additions and 21 deletions.
5 changes: 3 additions & 2 deletions dbm-services/mysql/db-tools/mysql-crond/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,11 @@ PROJ="mysql-crond"
MODULE="dbm-services/mysql/db-tools/mysql-crond"
VERSION = $(error please set VERSION flag)
GITHASH = ""
GITDATE = ""
TAR_PKG=${PROJ}.tar
PKG=${PROJ}.tar.gz
OUTPUT_DIR=build
RELEASE_BUILD_FLAG = "-X ${MODULE}/cmd.version=${VERSION} -X ${MODULE}/cmd.gitHash=${GITHASH} "
RELEASE_BUILD_FLAG = "-X ${MODULE}/cmd.version=${VERSION} -X ${MODULE}/cmd.gitHash=${GITHASH}"
DEV_BUILD_FLAG = "-X ${MODULE}/cmd.version="develop" -X ${MODULE}/cmd.gitHash="" "

.PHONY: release-bin
Expand All @@ -14,7 +15,7 @@ release-bin:
cp mysql-crond.conf.go.tpl $(OUTPUT_DIR)
cp start.sh $(OUTPUT_DIR) && chmod +x $(OUTPUT_DIR)/start.sh
# 为了保证 tar 压缩得到的包的 md5 一致,这里修改文件的时间戳,同时把 tar -zcf 拆为 tar -cf && gzip
find ${OUTPUT_DIR} -exec touch -t 202301010000 {} +
find ${OUTPUT_DIR} -exec touch -t ${GITDATE} {} +
tar -C ${OUTPUT_DIR} --numeric-owner -cvf ${OUTPUT_DIR}/${TAR_PKG} mysql-crond mysql-crond.conf.go.tpl start.sh
gzip -n -f ${OUTPUT_DIR}/${TAR_PKG}

Expand Down
5 changes: 2 additions & 3 deletions dbm-services/mysql/db-tools/mysql-monitor/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ PROJ="mysql-monitor"
MODULE="dbm-services/mysql/db-tools/mysql-monitor"
VERSION = $(error please set VERSION flag)
GITHASH = ""
GITDATE = ""
TAR_PKG = ${PROJ}.tar
PKG = ${PROJ}.tar.gz
OUTPUT_DIR = build
Expand All @@ -15,7 +16,7 @@ release-bin:
cp pt-config-diff ${OUTPUT_DIR}/pt-config-diff
cp pt-summary ${OUTPUT_DIR}/pt-summary
# 为了保证 tar 压缩得到的包的 md5 一致,这里修改文件的时间戳,同时把 tar -zcf 拆为 tar -cf && gzip
find ${OUTPUT_DIR} -exec touch -t 202301010000 {} +
find ${OUTPUT_DIR} -exec touch -t ${GITDATE} {} +
tar -C ${OUTPUT_DIR} --numeric-owner -cvf ${OUTPUT_DIR}/${TAR_PKG} ${PROJ} mysql-monitor pt-config-diff pt-summary
gzip -n -f ${OUTPUT_DIR}/${TAR_PKG}

Expand All @@ -29,5 +30,3 @@ dev-bin:
.PHONY: clean
clean:
rm -rf $(OUTPUT_DIR) && go clean -cache


5 changes: 3 additions & 2 deletions dbm-services/mysql/db-tools/mysql-rotatebinlog/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@ PROJ="mysql-rotatebinlog"
PROJ_BIN="rotatebinlog"
MODULE="dbm-services/mysql/db-tools/mysql-rotatebinlog"
VERSION = $(error please set VERSION flag)
GITHASH = ""
GITHASH=""
GITDATE=""
TAR_PKG = ${PROJ}.tar
PROJ_PKG = ${PROJ}.tar.gz
OUTPUT_DIR = build
Expand All @@ -18,7 +19,7 @@ build:
release-bin: build
cp config.example.yaml ${OUTPUT_DIR}/${PROJ}/config.yaml.example
# 为了保证 tar 压缩得到的包的 md5 一致,这里修改文件的时间戳,同时把 tar -zcf 拆为 tar -cf && gzip
find ${OUTPUT_DIR} -exec touch -t 202301010000 {} +
find ${OUTPUT_DIR} -exec touch -t ${GITDATE} {} +
tar -C ${OUTPUT_DIR} -cf ${OUTPUT_DIR}/${TAR_PKG} ${PROJ}/
gzip -n -f ${OUTPUT_DIR}/${TAR_PKG}

Expand Down
3 changes: 2 additions & 1 deletion dbm-services/mysql/db-tools/mysql-table-checksum/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ PROJ="mysql-table-checksum"
MODULE="dbm-services/mysql/db-tools/mysql-table-checksum"
VERSION = $(error please set VERSION flag)
GITHASH=""
GITDATE=""
# 注意这里的最终产物是 mysql-checksum.tar.gz,不要修改了
TAR_PKG="mysql-checksum.tar"
PKG="mysql-checksum.tar.gz"
Expand All @@ -16,7 +17,7 @@ release-bin:
cp -a pt-table-checksum ${OUTPUT_DIR}/
cp -a pt-table-sync ${OUTPUT_DIR}/
# 为了保证 tar 压缩得到的包的 md5 一致,这里修改文件的时间戳,同时把 tar -zcf 拆为 tar -cf && gzip
find ${OUTPUT_DIR} -exec touch -t 202301010000 {} +
find ${OUTPUT_DIR} -exec touch -t ${GITDATE} {} +
tar -C ${OUTPUT_DIR} --numeric-owner -cvf ${OUTPUT_DIR}/${TAR_PKG} ${PROJ} pt-table-checksum pt-table-sync
gzip -n -f ${OUTPUT_DIR}/${TAR_PKG}

Expand Down
6 changes: 5 additions & 1 deletion dbm-services/redis/db-tools/dbmon/package.sh
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

repoVersion=0.0.1
respGitHash=$(git rev-parse --short HEAD)
respGitDate=202301010000

# 解析传入的 --version=xxx 和 --git-hash=xxx 参数
while [ $# -gt 0 ]; do
Expand All @@ -12,6 +13,9 @@ while [ $# -gt 0 ]; do
--git-hash=*)
respGitHash="${1#*=}"
;;
--git-date=*)
respGitDate="${1#*=}"
;;
*) ;;
esac
shift
Expand Down Expand Up @@ -42,7 +46,7 @@ if [[ -e $tarName ]]; then
fi

# 为了保证 tar 压缩得到的包的 md5 一致,这里修改文件的时间戳,同时把 tar -zcf 拆为 tar -cf && gzip
find ${targetDir} -exec touch -t 202301010000 {} +
find ${targetDir} -exec touch -t $respGitDate {} +
tar --numeric-owner -cvf ${tarName} $targetDir
gzip -n -f ${tarName}

Expand Down
11 changes: 5 additions & 6 deletions dbm-ui/backend/dbm_init/medium/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -137,13 +137,13 @@ RUN set -ex && \
cd /blueking-dbm/dbm-services/mysql/db-tools/dbactuator && \
make VERSION=$(/lock.sh mysql actuator version) GITHASH=$(/lock.sh mysql actuator commitId) -j4 && \
cd /blueking-dbm/dbm-services/mysql/db-tools/mysql-table-checksum && \
make release-bin VERSION=$(/lock.sh mysql mysql-checksum version) GITHASH=$(/lock.sh mysql mysql-checksum commitId) -j4 && \
make release-bin VERSION=$(/lock.sh mysql mysql-checksum version) GITHASH=$(/lock.sh mysql mysql-checksum commitId) GITDATE=$(/lock.sh mysql mysql-checksum commitDate) -j4 && \
cd /blueking-dbm/dbm-services/mysql/db-tools/mysql-crond && \
make release-bin VERSION=$(/lock.sh mysql mysql-crond version) GITHASH=$(/lock.sh mysql mysql-crond commitId) -j4 && \
make release-bin VERSION=$(/lock.sh mysql mysql-crond version) GITHASH=$(/lock.sh mysql mysql-crond commitId) GITDATE=$(/lock.sh mysql mysql-crond commitDate) -j4 && \
cd /blueking-dbm/dbm-services/mysql/db-tools/mysql-rotatebinlog && \
make release-bin VERSION=$(/lock.sh mysql rotate-binlog version) GITHASH=$(/lock.sh mysql rotate-binlog commitId) -j4 && \
make release-bin VERSION=$(/lock.sh mysql rotate-binlog version) GITHASH=$(/lock.sh mysql rotate-binlog commitId) GITDATE=$(/lock.sh mysql rotate-binlog commitDate) -j4 && \
cd /blueking-dbm/dbm-services/mysql/db-tools/mysql-monitor && \
make release-bin VERSION=$(/lock.sh mysql mysql-monitor version) GITHASH=$(/lock.sh mysql mysql-monitor commitId) -j4
make release-bin VERSION=$(/lock.sh mysql mysql-monitor version) GITHASH=$(/lock.sh mysql mysql-monitor commitId) GITDATE=$(/lock.sh mysql mysql-monitor commitDate) -j4

## 编译 dbbackup-go community,下载依赖
RUN set -ex && \
Expand All @@ -160,8 +160,7 @@ RUN set -ex && \
cd /blueking-dbm/dbm-services/redis/db-tools/dbactuator && \
make VERSION=$(/lock.sh redis actuator version) GITHASH=$(/lock.sh redis actuator commitId) -j4 && \
cd /blueking-dbm/dbm-services/redis/db-tools/dbmon && \
bash package.sh

bash package.sh --version=$(/lock.sh redis actuator version) --git-hash=$(/lock.sh redis actuator commitId) --git-date=$(/lock.sh redis actuator commitDate)

FROM medium-builder as bigdata-medium-builder

Expand Down
19 changes: 13 additions & 6 deletions dbm-ui/backend/dbm_init/medium/handlers.py
Original file line number Diff line number Diff line change
Expand Up @@ -216,15 +216,22 @@ def add_version(version):
for medium in mediums:
for medium_type, medium_info in medium.items():
# 判断commit是否相等,不想等则进行版本号增加
dir_commit = subprocess.run(
[f"git -C {medium_info['buildPath'].rsplit('/', 2)[0]} log -n 1 --pretty=format:%H ."],
stdout=subprocess.PIPE,
stderr=subprocess.PIPE,
shell=True,
).stdout.decode("utf-8")
dir_commit, commit_date = (
subprocess.run(
[f"git -C {medium_info['buildPath'].rsplit('/', 2)[0]} log -n 1 --pretty=format:%H,%ci ."],
stdout=subprocess.PIPE,
stderr=subprocess.PIPE,
shell=True,
)
.stdout.decode("utf-8")
.split(",")
)
if dir_commit != medium_info["commitId"]:
medium_info["version"] = add_version(medium_info["version"])
medium_info["commitId"] = dir_commit
medium_info["commitDate"] = datetime.strptime(commit_date, "%Y-%m-%d %H:%M:%S %z").strftime(
"%Y%m%d%H%M"
)

# 更新lock文件
with open(medium_lock_path, "w") as lock_file:
Expand Down
13 changes: 13 additions & 0 deletions dbm-ui/backend/dbm_init/medium/medium.lock
Original file line number Diff line number Diff line change
Expand Up @@ -2,71 +2,84 @@ es:
- actuator:
buildPath: /blueking-dbm/dbm-services/bigdata/db-tools/dbactuator/build/dbactuator
commitId: 183acccc032756be2ada909b423aaaf14ca5f83e
commitDate: 200001010101
name: dbactuator
version: 1.0.2
hdfs:
- actuator:
buildPath: /blueking-dbm/dbm-services/bigdata/db-tools/dbactuator/build/dbactuator
commitId: 183acccc032756be2ada909b423aaaf14ca5f83e
commitDate: 200001010101
name: dbactuator
version: 1.0.2
influxdb:
- actuator:
buildPath: /blueking-dbm/dbm-services/bigdata/db-tools/dbactuator/build/dbactuator
commitId: 183acccc032756be2ada909b423aaaf14ca5f83e
commitDate: 200001010101
name: dbactuator
version: 1.0.2
kafka:
- actuator:
buildPath: /blueking-dbm/dbm-services/bigdata/db-tools/dbactuator/build/dbactuator
commitId: 183acccc032756be2ada909b423aaaf14ca5f83e
commitDate: 200001010101
name: dbactuator
version: 1.0.2
mysql:
- actuator:
buildPath: /blueking-dbm/dbm-services/mysql/db-tools/dbactuator/build/dbactuator
commitId: 166a1ed8856a062de2ced5bdd3bc7d8c315457ca
commitDate: 200001010101
name: dbactuator
version: 1.0.3
- dbbackup:
buildPath: /blueking-dbm/dbm-services/mysql/db-tools/mysql-dbbackup/build/dbbackup-go-community.tar.gz
commitId: 166a1ed8856a062de2ced5bdd3bc7d8c315457ca
commitDate: 200001010101
name: dbbackup-go-community.tar.gz
version: 1.0.2
- mysql-checksum:
buildPath: /blueking-dbm/dbm-services/mysql/db-tools/mysql-table-checksum/build/mysql-checksum.tar.gz
commitId: 1a7b99bf32dc9d2445e3fe8637cb21faebf1f08c
commitDate: 200001010101
name: mysql-checksum.tar.gz
version: 1.0.3
- mysql-crond:
buildPath: /blueking-dbm/dbm-services/mysql/db-tools/mysql-crond/build/mysql-crond.tar.gz
commitId: 378047fc5156920d6d174a7e053d3c75a2e63023
commitDate: 200001010101
name: mysql-crond.tar.gz
version: 1.0.3
- rotate-binlog:
buildPath: /blueking-dbm/dbm-services/mysql/db-tools/mysql-rotatebinlog/build/mysql-rotatebinlog.tar.gz
commitId: 166a1ed8856a062de2ced5bdd3bc7d8c315457ca
commitDate: 200001010101
name: mysql-rotatebinlog.tar.gz
version: 1.0.3
- mysql-monitor:
buildPath: /blueking-dbm/dbm-services/mysql/db-tools/mysql-monitor/build/mysql-monitor.tar.gz
commitId: 378047fc5156920d6d174a7e053d3c75a2e63023
commitDate: 200001010101
name: mysql-monitor.tar.gz
version: 1.0.3
pulsar:
- actuator:
buildPath: /blueking-dbm/dbm-services/bigdata/db-tools/dbactuator/build/dbactuator
commitId: 183acccc032756be2ada909b423aaaf14ca5f83e
commitDate: 200001010101
name: dbactuator
version: 1.0.2
redis:
- actuator:
buildPath: /blueking-dbm/dbm-services/redis/db-tools/dbactuator/build/dbactuator_redis
commitId: 255e57334099b76332819d56a093b7553b68998b
commitDate: 200001010101
name: dbactuator_redis
version: 1.0.3
- dbmon:
buildPath: /blueking-dbm/dbm-services/redis/db-tools/dbmon/build/bk-dbmon-*.tar.gz
commitId: 255e57334099b76332819d56a093b7553b68998b
commitDate: 200001010101
name: dbmon
version: 1.0.3

0 comments on commit c06d373

Please sign in to comment.