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

Commit

Permalink
Merge pull request #129 from Bidaya0/enhancement/versioncrontrl
Browse files Browse the repository at this point in the history
Enhancement/versioncrontrl
  • Loading branch information
exexute authored Feb 23, 2022
2 parents 71274a2 + 3379d4d commit 4dcefaf
Show file tree
Hide file tree
Showing 6 changed files with 57 additions and 0 deletions.
10 changes: 10 additions & 0 deletions .github/workflows/deploy_test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,16 @@ jobs:

- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v1

- id: version
run: |
MAIN_STREAM_VERSION=`echo ${{ github.run_number }}.0.0 | awk '{split($0,a,".");printf "%d.%d.x",a[1],a[2];}'`
echo "::set-output name=main_stream_version::$MAIN_STREAM_VERSION"
- name: Generate version file
run: |
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
echo "REPLACE INTO project_version_control (version, component_name) VALUES('${{ steps.version.outputs.main_stream_version }}', 'DongTai');" >> ./docker/version.sql
- name: Login to DockerHub
uses: docker/login-action@v1
Expand Down
6 changes: 6 additions & 0 deletions .github/workflows/release_engine.yml
Original file line number Diff line number Diff line change
Expand Up @@ -50,13 +50,19 @@ jobs:
TAG_NAME=${{ github.event.release.tag_name }}
ID=`echo ${TAG_NAME##v}`
echo "::set-output name=VERSION::$ID"
- id: version
MAIN_STREAM_VERSION=`echo ${{ steps.release.outputs.version }} | awk '{split($0,a,".");printf "%d.%d.x",a[1],a[2];}'`
echo "::set-output name=main_stream_version::$MAIN_STREAM_VERSION"

- name: Generate version file
run: |
bash .github/workflows/version_update.sh "${{ steps.release.outputs.VERSION }}"
cd ${{ github.workspace }} && \
echo "${{ github.event.repository.name }},version,${{ steps.release.outputs.VERSION }}" >> version.txt && \
echo "${{ github.event.repository.name }},commit_hash,${GITHUB_SHA}" >> version.txt \
export MAIN_STREAM_VERSION=`echo ${{ steps.release.outputs.version }} | awk '{split($0,a,".");printf "%d.%d.x",a[1],a[2];}`
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
echo "REPLACE INTO project_version_control (version, component_name) VALUES('${{ steps.version.outputs.main_stream_version }}', 'DongTai');" >> ./docker/version.sql
- name: Upload version file to oss
id: upload_version_file_to_oss
Expand Down
1 change: 1 addition & 0 deletions docker/entrypoint.sh
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
python /opt/dongtai/engine/docker/version_update.py || true
echo '启动uwsgi服务'
nohup /usr/local/bin/uwsgi --ini /opt/dongtai/engine/conf/uwsgi.ini &
sleep 2
Expand Down
1 change: 1 addition & 0 deletions docker/version.sql
Original file line number Diff line number Diff line change
@@ -0,0 +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;
3 changes: 3 additions & 0 deletions docker/version.sql.example
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
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;
REPLACE INTO project_version_control (version, component_name, component_version_hash) VALUES('1.3.0', 'DongTai-webapi', '12313223121331232132');
REPLACE INTO project_version_control (version, component_name, component_version_hash) VALUES('1.3.0', 'DongTai', '12313223121331232132');
36 changes: 36 additions & 0 deletions docker/version_update.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
######################################################################
# @author : bidaya0 (bidaya0@$HOSTNAME)
# @file : version_update
# @created : 星期四 1月 20, 2022 15:42:27 CST
#
# @description :
######################################################################


from configparser import ConfigParser
import os
import MySQLdb
import sys
BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))

config = ConfigParser()
status = config.read(os.path.join(BASE_DIR, 'conf/config.ini'))
if len(status) == 0:
print("config file not exist. stop running")
sys.exit(0)
DBCONFIG = {
'user': config.get("mysql", 'user'),
'db': config.get("mysql", 'name'),
'passwd': config.get("mysql", 'password'),
'host': config.get("mysql", 'host'),
'port': int(config.get("mysql", 'port')),
}
db = MySQLdb.connect(**DBCONFIG, use_unicode=True, charset="utf8mb4")
cursor = db.cursor()
for line in open(os.path.join(BASE_DIR, 'docker/version.sql'),
encoding='utf-8'):
if not line.strip():
continue
cursor.execute(line)
cursor.close()
db.commit()

0 comments on commit 4dcefaf

Please sign in to comment.