Skip to content
This repository was archived by the owner on Apr 20, 2022. It is now read-only.

Commit 4dcefaf

Browse files
authored
Merge pull request #129 from Bidaya0/enhancement/versioncrontrl
Enhancement/versioncrontrl
2 parents 71274a2 + 3379d4d commit 4dcefaf

File tree

6 files changed

+57
-0
lines changed

6 files changed

+57
-0
lines changed

.github/workflows/deploy_test.yml

+10
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,16 @@ jobs:
9595

9696
- name: Set up Docker Buildx
9797
uses: docker/setup-buildx-action@v1
98+
99+
- id: version
100+
run: |
101+
MAIN_STREAM_VERSION=`echo ${{ github.run_number }}.0.0 | awk '{split($0,a,".");printf "%d.%d.x",a[1],a[2];}'`
102+
echo "::set-output name=main_stream_version::$MAIN_STREAM_VERSION"
103+
104+
- name: Generate version file
105+
run: |
106+
echo "REPLACE INTO project_version_control (version, component_name, component_version_hash) VALUES('${{ github.run_number }}.0.0', '${{ github.event.repository.name }}', '${GITHUB_SHA}');" >> ./docker/version.sql
107+
echo "REPLACE INTO project_version_control (version, component_name) VALUES('${{ steps.version.outputs.main_stream_version }}', 'DongTai');" >> ./docker/version.sql
98108
99109
- name: Login to DockerHub
100110
uses: docker/login-action@v1

.github/workflows/release_engine.yml

+6
Original file line numberDiff line numberDiff line change
@@ -50,13 +50,19 @@ jobs:
5050
TAG_NAME=${{ github.event.release.tag_name }}
5151
ID=`echo ${TAG_NAME##v}`
5252
echo "::set-output name=VERSION::$ID"
53+
- id: version
54+
MAIN_STREAM_VERSION=`echo ${{ steps.release.outputs.version }} | awk '{split($0,a,".");printf "%d.%d.x",a[1],a[2];}'`
55+
echo "::set-output name=main_stream_version::$MAIN_STREAM_VERSION"
5356

5457
- name: Generate version file
5558
run: |
5659
bash .github/workflows/version_update.sh "${{ steps.release.outputs.VERSION }}"
5760
cd ${{ github.workspace }} && \
5861
echo "${{ github.event.repository.name }},version,${{ steps.release.outputs.VERSION }}" >> version.txt && \
5962
echo "${{ github.event.repository.name }},commit_hash,${GITHUB_SHA}" >> version.txt \
63+
export MAIN_STREAM_VERSION=`echo ${{ steps.release.outputs.version }} | awk '{split($0,a,".");printf "%d.%d.x",a[1],a[2];}`
64+
echo "REPLACE INTO project_version_control (version, component_name, component_version_hash) VALUES('${{ steps.release.outputs.version }}', '${{ github.event.repository.name }}', '${GITHUB_SHA}');" >> ./docker/version.sql
65+
echo "REPLACE INTO project_version_control (version, component_name) VALUES('${{ steps.version.outputs.main_stream_version }}', 'DongTai');" >> ./docker/version.sql
6066
6167
- name: Upload version file to oss
6268
id: upload_version_file_to_oss

docker/entrypoint.sh

+1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
python /opt/dongtai/engine/docker/version_update.py || true
12
echo '启动uwsgi服务'
23
nohup /usr/local/bin/uwsgi --ini /opt/dongtai/engine/conf/uwsgi.ini &
34
sleep 2

docker/version.sql

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
CREATE TABLE IF NOT EXISTS `project_version_control` ( `id` int(11) NOT NULL AUTO_INCREMENT COMMENT '自增主键', `version` varchar(63) DEFAULT NULL COMMENT '版本号', `component_name` varchar(255) DEFAULT NULL COMMENT 'sql名', `component_version_hash` varchar(255) DEFAULT NULL COMMENT 'sql哈希值', `additional` text COMMENT '额外注释', `update_time` timestamp NULL DEFAULT CURRENT_TIMESTAMP, PRIMARY KEY (`id`), UNIQUE KEY `project_version_control_UN` (`component_name`) ) ENGINE = InnoDB CHARSET = utf8mb4;

docker/version.sql.example

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
CREATE TABLE `project_version_control` ( `id` int(11) NOT NULL AUTO_INCREMENT COMMENT '自增主键', `version` varchar(63) DEFAULT NULL COMMENT '版本号', `component_name` varchar(255) DEFAULT NULL COMMENT 'sql名', `component_version_hash` varchar(255) DEFAULT NULL COMMENT 'sql哈希值', `additional` text COMMENT '额外注释', `update_time` timestamp NULL DEFAULT CURRENT_TIMESTAMP, PRIMARY KEY (`id`), UNIQUE KEY `project_version_control_UN` (`component_name`) ) ENGINE = InnoDB AUTO_INCREMENT = 19 CHARSET = utf8mb4;
2+
REPLACE INTO project_version_control (version, component_name, component_version_hash) VALUES('1.3.0', 'DongTai-webapi', '12313223121331232132');
3+
REPLACE INTO project_version_control (version, component_name, component_version_hash) VALUES('1.3.0', 'DongTai', '12313223121331232132');

docker/version_update.py

+36
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
######################################################################
2+
# @author : bidaya0 (bidaya0@$HOSTNAME)
3+
# @file : version_update
4+
# @created : 星期四 1月 20, 2022 15:42:27 CST
5+
#
6+
# @description :
7+
######################################################################
8+
9+
10+
from configparser import ConfigParser
11+
import os
12+
import MySQLdb
13+
import sys
14+
BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
15+
16+
config = ConfigParser()
17+
status = config.read(os.path.join(BASE_DIR, 'conf/config.ini'))
18+
if len(status) == 0:
19+
print("config file not exist. stop running")
20+
sys.exit(0)
21+
DBCONFIG = {
22+
'user': config.get("mysql", 'user'),
23+
'db': config.get("mysql", 'name'),
24+
'passwd': config.get("mysql", 'password'),
25+
'host': config.get("mysql", 'host'),
26+
'port': int(config.get("mysql", 'port')),
27+
}
28+
db = MySQLdb.connect(**DBCONFIG, use_unicode=True, charset="utf8mb4")
29+
cursor = db.cursor()
30+
for line in open(os.path.join(BASE_DIR, 'docker/version.sql'),
31+
encoding='utf-8'):
32+
if not line.strip():
33+
continue
34+
cursor.execute(line)
35+
cursor.close()
36+
db.commit()

0 commit comments

Comments
 (0)