Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature remote import #114

Merged
Show file tree
Hide file tree
Changes from 19 commits
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
a8e1eb1
feature: 添加非标准存储代码导入器及 git 仓库代码导入器
homholueng Apr 9, 2019
dcc0800
merge upstream V3.3.X
homholueng Apr 9, 2019
c9a811d
minor: 将 urllib2 的使用改为 requests
homholueng Apr 9, 2019
27a1df4
minor: 移除测试代码中的关键字使用
homholueng Apr 9, 2019
f9c4247
minor: 内部包与第三方包之间添加空格
homholueng Apr 9, 2019
a45eada
minor: 删除冗余编码声明; 第三方包引用间添加空行
homholueng Apr 10, 2019
ef67189
feature: 添加远程包源模型
homholueng Apr 10, 2019
fc8aa51
feature: 添加加载远程模块相关逻辑代码
homholueng Apr 10, 2019
e0473de
minor: 添加加载远程插件 APP
homholueng Apr 10, 2019
bd8c079
feature: pipeline.utils.importer 添加导入器上下文
homholueng Apr 11, 2019
430cc3c
minors: 完善 external_plugins app 的单元测试
homholueng Apr 11, 2019
e347cde
feature: GitRepoImporter 添加强制 HTTPS 开关
homholueng Apr 11, 2019
6bf3464
minor: 添加远程包源配置获取语句
homholueng Apr 11, 2019
da72256
minor: 单元测试完善,Importer Logger 配置修改,GitImporter 支持配置代理
homholueng Apr 11, 2019
9ca8c23
minor: 关键节点添加日志
homholueng Apr 11, 2019
c2a10d7
improvement: 将 importer 工具类移动到 external_plugins app 下
homholueng Apr 11, 2019
54ded97
merge upstream/feature_remote_component_load
homholueng Apr 11, 2019
7fc6589
minor: flake8 fix
homholueng Apr 11, 2019
6840f04
minor: code review fix
homholueng Apr 11, 2019
b8d0f8f
bugfix: 修复删除本地配置中的包源配置时数据库中的配置未删除的问题
homholueng Apr 12, 2019
710b016
improvement: 优化遇到不支持的远程数据类型时抛出的异常信息
homholueng Apr 12, 2019
ae54720
minor: 删除多余空行
homholueng Apr 15, 2019
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 8 additions & 1 deletion config/default.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@
'pipeline.log',
'pipeline.contrib.statistics',
'pipeline.contrib.periodic_task',
'pipeline.contrib.external_plugins',
'django_signal_valve',
'pipeline_plugins',
'pipeline_plugins.components',
Expand Down Expand Up @@ -103,7 +104,7 @@
)

# 所有环境的日志级别可以在这里配置
# LOG_LEVEL = 'INFO'
LOG_LEVEL = 'INFO'

# 静态资源文件(js,css等)在APP上线更新后, 由于浏览器有缓存,
# 可能会造成没更新的情况. 所以在引用静态资源的地方,都把这个加上
Expand Down Expand Up @@ -132,6 +133,12 @@
# load logging settings
LOGGING = get_logging_config_dict(locals())

LOGGING['loggers']['pipeline'] = {
'handlers': ['root'],
'level': LOG_LEVEL,
'propagate': True,
}

# 初始化管理员列表,列表中的人员将拥有预发布环境和正式环境的管理员权限
# 注意:请在首次提测和上线前修改,之后的修改将不会生效
INIT_SUPERUSER = []
Expand Down
14 changes: 14 additions & 0 deletions pipeline/contrib/external_plugins/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
# -*- coding: utf-8 -*-
"""
Tencent is pleased to support the open source community by making 蓝鲸智云PaaS平台社区版 (BlueKing PaaS Community
Edition) available.
Copyright (C) 2017-2019 THL A29 Limited, a Tencent company. All rights reserved.
Licensed under the MIT License (the "License"); you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://opensource.org/licenses/MIT
Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on
an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the
specific language governing permissions and limitations under the License.
"""

default_app_config = 'pipeline.contrib.external_plugins.apps.ExternalPluginsConfig'
40 changes: 40 additions & 0 deletions pipeline/contrib/external_plugins/admin.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
# -*- coding: utf-8 -*-
"""
Tencent is pleased to support the open source community by making 蓝鲸智云PaaS平台社区版 (BlueKing PaaS Community
Edition) available.
Copyright (C) 2017-2019 THL A29 Limited, a Tencent company. All rights reserved.
Licensed under the MIT License (the "License"); you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://opensource.org/licenses/MIT
Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on
an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the
specific language governing permissions and limitations under the License.
"""

from django.contrib import admin

from pipeline.contrib.external_plugins.models import (
GitRepoSource,
S3Source,
FileSystemSource
)


# Register your models here.

@admin.register(GitRepoSource)
class GitRepoSourceAdmin(admin.ModelAdmin):
list_display = ['name', 'from_config', 'repo_raw_address', 'branch']
search_fields = ['name', 'branch', 'repo_raw_address']


@admin.register(S3Source)
class S3SourceAdmin(admin.ModelAdmin):
list_display = ['name', 'from_config', 'service_address', 'bucket']
search_fields = ['name', 'bucket', 'service_address']


@admin.register(FileSystemSource)
class FileSystemSourceAdmin(admin.ModelAdmin):
list_display = ['name', 'from_config', 'path']
search_fields = ['name', 'path']
49 changes: 49 additions & 0 deletions pipeline/contrib/external_plugins/apps.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
# -*- coding: utf-8 -*-
"""
Tencent is pleased to support the open source community by making 蓝鲸智云PaaS平台社区版 (BlueKing PaaS Community
Edition) available.
Copyright (C) 2017-2019 THL A29 Limited, a Tencent company. All rights reserved.
Licensed under the MIT License (the "License"); you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://opensource.org/licenses/MIT
Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on
an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the
specific language governing permissions and limitations under the License.
"""

import sys
import logging
import traceback

from django.apps import AppConfig
from django.conf import settings
from django.db.utils import ProgrammingError

logger = logging.getLogger('root')


class ExternalPluginsConfig(AppConfig):
name = 'pipeline.contrib.external_plugins'

def ready(self):
from pipeline.contrib.external_plugins import loader # noqa
from pipeline.contrib.external_plugins.models import ExternalPackageSource # noqa

triggers = getattr(settings, 'EXTERNAL_COMPONENTS_LOAD_TRIGGER', {'runserver', 'celery', 'worker'})
command = sys.argv[1]

if command in triggers:
try:
logger.info('Start to update package source from config file...')
ExternalPackageSource.update_package_source_from_config(getattr(settings,
'COMPONENTS_PACKAGE_SOURCES',
{}))
except ProgrammingError:
logger.warning('update package source failed, maybe first migration? exception: %s' %
traceback.format_exc())
# first migrate
return

logger.info('Start to load external modules...')

loader.load_external_modules()
16 changes: 16 additions & 0 deletions pipeline/contrib/external_plugins/exceptions.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
# -*- coding: utf-8 -*-
"""
Tencent is pleased to support the open source community by making 蓝鲸智云PaaS平台社区版 (BlueKing PaaS Community
Edition) available.
Copyright (C) 2017-2019 THL A29 Limited, a Tencent company. All rights reserved.
Licensed under the MIT License (the "License"); you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://opensource.org/licenses/MIT
Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on
an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the
specific language governing permissions and limitations under the License.
"""


class InvalidOperationException(Exception):
pass
43 changes: 43 additions & 0 deletions pipeline/contrib/external_plugins/loader.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
# -*- coding: utf-8 -*-
"""
Tencent is pleased to support the open source community by making 蓝鲸智云PaaS平台社区版 (BlueKing PaaS Community
Edition) available.
Copyright (C) 2017-2019 THL A29 Limited, a Tencent company. All rights reserved.
Licensed under the MIT License (the "License"); you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://opensource.org/licenses/MIT
Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on
an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the
specific language governing permissions and limitations under the License.
"""

import logging
import importlib
import traceback

from pipeline.contrib.external_plugins.models import source_cls_factory
from pipeline.contrib.external_plugins.utils.importer import importer_context

logger = logging.getLogger('root')


def load_external_modules():
for source_type, source_model_cls in source_cls_factory.items():
# get all external source
sources = source_model_cls.objects.all()

# get importer for source
for source in sources:
_import_modules_in_source(source)


def _import_modules_in_source(source):
importer = source.importer()

with importer_context(importer):
for module in source.modules:
try:
importlib.import_module(module)
except Exception as e:
logger.error('An error occurred when loading {%s}: %s' % (module, traceback.format_exc()))
raise e
71 changes: 71 additions & 0 deletions pipeline/contrib/external_plugins/migrations/0001_initial.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
# -*- coding: utf-8 -*-
"""
Tencent is pleased to support the open source community by making 蓝鲸智云PaaS平台社区版 (BlueKing PaaS Community
Edition) available.
Copyright (C) 2017-2019 THL A29 Limited, a Tencent company. All rights reserved.
Licensed under the MIT License (the "License"); you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://opensource.org/licenses/MIT
Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on
an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the
specific language governing permissions and limitations under the License.
"""

from __future__ import unicode_literals

from django.db import migrations, models
import pipeline.contrib.external_plugins.models.fields
homholueng marked this conversation as resolved.
Show resolved Hide resolved


class Migration(migrations.Migration):

initial = True

dependencies = [
]

operations = [
migrations.CreateModel(
name='FileSystemSource',
fields=[
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('name', models.CharField(max_length=128, unique=True, verbose_name='\u5305\u6e90\u540d')),
('from_config', models.BooleanField(default=False, verbose_name='\u662f\u5426\u662f\u4ece\u914d\u7f6e\u6587\u4ef6\u4e2d\u8bfb\u53d6\u7684')),
('packages', pipeline.contrib.external_plugins.models.fields.JSONTextField(verbose_name='\u6a21\u5757\u914d\u7f6e')),
('path', models.TextField(verbose_name='\u6587\u4ef6\u7cfb\u7edf\u8def\u5f84')),
],
options={
'abstract': False,
},
),
migrations.CreateModel(
name='GitRepoSource',
fields=[
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('name', models.CharField(max_length=128, unique=True, verbose_name='\u5305\u6e90\u540d')),
('from_config', models.BooleanField(default=False, verbose_name='\u662f\u5426\u662f\u4ece\u914d\u7f6e\u6587\u4ef6\u4e2d\u8bfb\u53d6\u7684')),
('packages', pipeline.contrib.external_plugins.models.fields.JSONTextField(verbose_name='\u6a21\u5757\u914d\u7f6e')),
('repo_raw_address', models.TextField(verbose_name='\u6587\u4ef6\u6258\u7ba1\u4ed3\u5e93\u94fe\u63a5')),
('branch', models.CharField(max_length=128, verbose_name='\u5206\u652f\u540d')),
],
options={
'abstract': False,
},
),
migrations.CreateModel(
name='S3Source',
fields=[
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('name', models.CharField(max_length=128, unique=True, verbose_name='\u5305\u6e90\u540d')),
('from_config', models.BooleanField(default=False, verbose_name='\u662f\u5426\u662f\u4ece\u914d\u7f6e\u6587\u4ef6\u4e2d\u8bfb\u53d6\u7684')),
('packages', pipeline.contrib.external_plugins.models.fields.JSONTextField(verbose_name='\u6a21\u5757\u914d\u7f6e')),
('service_address', models.TextField(verbose_name='\u5bf9\u8c61\u5b58\u50a8\u670d\u52a1\u5730\u5740')),
('bucket', models.TextField(verbose_name='bucket \u540d')),
('access_key', models.TextField(verbose_name='access key')),
('secret_key', models.TextField(verbose_name='secret key')),
],
options={
'abstract': False,
},
),
]
12 changes: 12 additions & 0 deletions pipeline/contrib/external_plugins/migrations/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
# -*- coding: utf-8 -*-
"""
Tencent is pleased to support the open source community by making 蓝鲸智云PaaS平台社区版 (BlueKing PaaS Community
Edition) available.
Copyright (C) 2017-2019 THL A29 Limited, a Tencent company. All rights reserved.
Licensed under the MIT License (the "License"); you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://opensource.org/licenses/MIT
Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on
an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the
specific language governing permissions and limitations under the License.
"""
15 changes: 15 additions & 0 deletions pipeline/contrib/external_plugins/models/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
# -*- coding: utf-8 -*-
"""
Tencent is pleased to support the open source community by making 蓝鲸智云PaaS平台社区版 (BlueKing PaaS Community
Edition) available.
Copyright (C) 2017-2019 THL A29 Limited, a Tencent company. All rights reserved.
Licensed under the MIT License (the "License"); you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://opensource.org/licenses/MIT
Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on
an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the
specific language governing permissions and limitations under the License.
"""

from pipeline.contrib.external_plugins.models.base import source_cls_factory # noqa
from pipeline.contrib.external_plugins.models.source import * # noqa
Loading