1. 新建deno.json

    GitLab CICD Day 17 - Image递增版本号 - 1_docker


  1. Gitlab-runner上安装jq

[root@qa onpremise]# yum -y install jq
Loaded plugins: fastestmirror, langpacks, product-id, search-disabled-repos, subscription-manager

This system is not registered with an entitlement server. You can use subscription-manager to register.

Loading mirror speeds from cached hostfile
epel/x86_64/metalink | 4.0 kB 00:00:00
* base: mirrors.tuna.tsinghua.edu.cn
* epel:
* extras: mirrors.tuna.tsinghua.edu.cn
* updates: mirrors.tuna.tsinghua.edu.cn
WANdisco-git


[root@qa onpremise]# cat deno.json |jq -r .version
1.0.0

  1. 配置gitlab.yaml

stages:
- build

##变量都配置在gitlab全局变量中
before_script:
- export Image_Version=$(cat deno.json | jq -r .version) # 获取文件中的版本,注意空格
- echo $Image_Version

build_docker_image:
stage: build
tags:
- shell
script:
- docker login -u $harbor_user -p $harbor_pwd $harbor_server # 登录到harbor.
- echo $image_mycat:$Image_Version
- docker build -t $image_mycat:$Image_Version . # 打包镜像
- docker push $image_mycat:$Image_Version # 推送镜像到harbor

  1. 手动修改deno.json

{
"version": "1.0.1", # 手动修改为1.0.1
"tasks": {
"start": "deno run -A --unstable --watch=static/,routes/ dev.ts"
},
"importMap": "./import_map.json",
"compilerOptions": {
"jsx": "react-jsx",
"jsxImportSource": "preact"
}
}

  1. 自动推送成功

    GitLab CICD Day 17 - Image递增版本号 - 1_docker_02