Skip to content

Commit

Permalink
Merge pull request #143 from loganhz/master
Browse files Browse the repository at this point in the history
release app
  • Loading branch information
loganhz authored Sep 19, 2023
2 parents 6db292e + d971848 commit a1b494d
Show file tree
Hide file tree
Showing 42 changed files with 123 additions and 74 deletions.
76 changes: 43 additions & 33 deletions publish.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,17 +7,20 @@
import oss2
import shutil


def path_is_parent(parent_path, child_path):
parent_path = os.path.abspath(parent_path)
child_path = os.path.abspath(child_path)
return os.path.commonpath([parent_path]) == os.path.commonpath([parent_path, child_path])


def is_ignored(target_path, ignores):
for ignore in ignores:
if os.path.relpath(target_path, ignore) == '.' or path_is_parent(ignore, target_path):
return True
return False


def zip_file(workspace, eve_app):
os.chdir('%s/%s/src' % (workspace, eve_app))
if os.path.isfile('README.md'):
Expand All @@ -27,7 +30,8 @@ def zip_file(workspace, eve_app):
elif os.path.isfile('Readme.md'):
shutil.copy('Readme.md', 'code')
os.chdir('%s/%s/src/code' % (workspace, eve_app))
ignore_list = ['./.git', './.github', './.idea', './.DS_Store', './.vscode']
ignore_list = ['./.git', './.github',
'./.idea', './.DS_Store', './.vscode']
with zipfile.ZipFile('code.zip', mode="w") as f:
for dirpath, dirnames, filenames in os.walk('./'):
if dirpath != './' and is_ignored(dirpath, ignore_list):
Expand All @@ -39,6 +43,7 @@ def zip_file(workspace, eve_app):

return 'code.zip'


def zip_golang_binary(workspace, eve_app):
os.chdir('%s/%s/src' % (workspace, eve_app))
if os.path.isfile('README.md'):
Expand All @@ -48,7 +53,8 @@ def zip_golang_binary(workspace, eve_app):
elif os.path.isfile('Readme.md'):
shutil.copy('Readme.md', 'code/target')
os.chdir('%s/%s/src/code/target' % (workspace, eve_app))
ignore_list = ['./.git', './.github', './.idea', './.DS_Store', './.vscode']
ignore_list = ['./.git', './.github',
'./.idea', './.DS_Store', './.vscode']
with zipfile.ZipFile('code.zip', mode="w") as f:
for dirpath, dirnames, filenames in os.walk('./'):
if dirpath != './' and is_ignored(dirpath, ignore_list):
Expand All @@ -60,14 +66,18 @@ def zip_golang_binary(workspace, eve_app):

return 'code.zip'


def upload_oss(code_name, zip_file):
auth = oss2.Auth(os.environ.get('AccessKeyId'), os.environ.get('AccessKeySecret'))
bucket = oss2.Bucket(auth, os.environ.get('ArtifactEndpoint'), os.environ.get('ArtifactBucket'))
auth = oss2.Auth(os.environ.get('AccessKeyId'),
os.environ.get('AccessKeySecret'))
bucket = oss2.Bucket(auth, os.environ.get(
'ArtifactEndpoint'), os.environ.get('ArtifactBucket'))

with open(zip_file, 'rb') as fileobj:
object_name = '%s/code.zip' % (code_name)
bucket.put_object(object_name, fileobj)


workspace = os.getcwd()
with open('update.list') as f:
publish_list = [eve_app.strip() for eve_app in f.readlines()]
Expand All @@ -80,7 +90,7 @@ def upload_oss(code_name, zip_file):
try:
while times <= 3:
print("----------------------: ", eve_app)
# publish app to registry
# publish app to registry
publish_script = 'https://serverless-registry.oss-cn-hangzhou.aliyuncs.com/publish-file/python3/hub-publish.py'
command = 'cd %s && wget %s && python hub-publish.py' % (
eve_app, publish_script)
Expand All @@ -102,32 +112,32 @@ def upload_oss(code_name, zip_file):
failed_registry.append(eve_app)

# publish code.zip to oss
os.chdir(workspace)
try:
makefile = Path('%s/src/Makefile' % (eve_app))
if makefile.is_file():
print("----------------------Makefile: ", makefile)
command = 'cd %s/src && make release' % (eve_app)
print(command)
child = subprocess.Popen(
command, stdout=subprocess.PIPE, stderr=subprocess.PIPE, shell=True, )
stdout, stderr = child.communicate()
print("stdout:", stdout.decode("utf-8"))
if child.returncode != 0:
print("stderr:", stderr.decode("utf-8"))
raise ChildProcessError(stderr)
jarPath = '%s/%s/src/code/target/code.jar' % (workspace, eve_app)
golangBinaryPath = '%s/%s/src/code/target/main' % (workspace, eve_app)
if os.path.isfile(jarPath):
code_zip = jarPath
elif os.path.isfile(golangBinaryPath):
code_zip = zip_golang_binary(workspace, eve_app)
else:
code_zip = zip_file(workspace, eve_app)
upload_oss(eve_app, code_zip)
except Exception as e:
print('Failed to publish oss, app %s, err: %s' % (eve_app, e))
failed_oss.append(eve_app)
# os.chdir(workspace)
# try:
# makefile = Path('%s/src/Makefile' % (eve_app))
# if makefile.is_file():
# print("----------------------Makefile: ", makefile)
# command = 'cd %s/src && make release' % (eve_app)
# print(command)
# child = subprocess.Popen(
# command, stdout=subprocess.PIPE, stderr=subprocess.PIPE, shell=True, )
# stdout, stderr = child.communicate()
# print("stdout:", stdout.decode("utf-8"))
# if child.returncode != 0:
# print("stderr:", stderr.decode("utf-8"))
# raise ChildProcessError(stderr)
# jarPath = '%s/%s/src/code/target/code.jar' % (workspace, eve_app)
# golangBinaryPath = '%s/%s/src/code/target/main' % (workspace, eve_app)
# if os.path.isfile(jarPath):
# code_zip = jarPath
# elif os.path.isfile(golangBinaryPath):
# code_zip = zip_golang_binary(workspace, eve_app)
# else:
# code_zip = zip_file(workspace, eve_app)
# upload_oss(eve_app, code_zip)
# except Exception as e:
# print('Failed to publish oss, app %s, err: %s' % (eve_app, e))
# failed_oss.append(eve_app)

print('Failed registry list: ', failed_registry)
print('Failed oss list: ', failed_oss)
print('Failed oss list: ', failed_oss)
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Type: Application
Name: cdn-trigger-fc-event-golang
Version: dev
Version: 0.0.1
Provider:
- 阿里云
Description: 快速部署一个 具备 CDN 触发器 Event 类型的函数到阿里云函数计算。
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ Type: Application
Name: kafka-producer-fc-event-golang
Provider:
- 阿里云
Version: dev
Version: 0.0.1
Description: 快速部署一个可以生产消息至 Kafka 的函数到阿里云函数计算
HomePage: https://github.com/devsapp/start-fc
Tags:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ Type: Application
Name: kafka-trigger-fc-event-golang
Provider:
- 阿里云
Version: dev
Version: 0.0.1
Description: 快速部署一个具备 Kafka触发器 Event 类型的函数到阿里云函数计算
HomePage: https://github.com/devsapp/start-fc
Tags:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ Type: Application
Name: start-golang-mongodb-http
Provider:
- 阿里云
Version: dev
Version: 0.0.1
Description: 函数计算访问MongoDB
HomePage: https://github.com/devsapp/start-golang-mongodb-http
Tags: #标签详情
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ Type: Application
Name: start-golang-mongodb
Provider:
- 阿里云
Version: dev
Version: 0.0.1
Description: 函数计算访问MongoDB
HomePage: https://github.com/devsapp/start-golang-mongodb
Tags: #标签详情
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Type: Application
Name: ots-trigger-fc-event-golang
Version: dev
Version: 0.0.1
Provider:
- 阿里云
Description: 快速部署一个 具备 OTS 触发器 Event 类型的函数到阿里云函数计算。
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ Type: Application
Name: start-golang-tablestore-http
Provider:
- 阿里云
Version: dev
Version: 0.0.1
Description: 函数计算访问表格存储示例
HomePage: https://github.com/devsapp/start-golang-tablestore-http
Tags: #标签详情
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ Type: Application
Name: start-golang-tablestore
Provider:
- 阿里云
Version: dev
Version: 0.0.1
Description: 函数计算访问表格存储示例
HomePage: https://github.com/devsapp/start-golang-tablestore
Tags: #标签详情
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ Type: Application
Name: timer-trigger-fc-event-golang
Provider:
- 阿里云
Version: dev
Version: 0.0.1
Description: 快速部署一个具备 定时器触发器 Event 类型的函数到阿里云函数计算
HomePage: https://github.com/devsapp/start-fc
Tags:
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Type: Application
Name: cdn-trigger-fc-event-java11
Version: dev
Version: 0.0.1
Provider:
- 阿里云
Description: 快速部署一个 具备 CDN 触发器 Event 类型的函数到阿里云函数计算。
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ Type: Application
Name: kafka-producer-fc-event-java11
Provider:
- 阿里云
Version: dev
Version: 0.0.1
Description: 快速部署一个可以生产消息至 Kafka 的函数到阿里云函数计算
HomePage: https://github.com/devsapp/start-fc
Tags:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ Type: Application
Name: kafka-trigger-fc-event-java11
Provider:
- 阿里云
Version: dev
Version: 0.0.1
Description: 快速部署一个具备 Kafka触发器 Event 类型的函数到阿里云函数计算
HomePage: https://github.com/devsapp/start-fc
Tags:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ Type: Application
Name: start-java11-mongodb-http
Provider:
- 阿里云
Version: dev
Version: 0.0.1
Description: 函数计算访问MongoDB
HomePage: https://github.com/devsapp/start-java11-mongodb-http
Tags: #标签详情
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ Type: Application
Name: start-java11-mongodb
Provider:
- 阿里云
Version: dev
Version: 0.0.1
Description: 函数计算访问MongoDB
HomePage: https://github.com/devsapp/start-java11-mongodb
Tags: #标签详情
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Type: Application
Name: ots-trigger-fc-event-java11
Version: dev
Version: 0.0.1
Provider:
- 阿里云
Description: 快速部署一个 具备 OTS 触发器 Event 类型的函数到阿里云函数计算。
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ Type: Application
Name: start-java11-tablestore-http
Provider:
- 阿里云
Version: dev
Version: 0.0.1
Description: 函数计算访问表格存储示例
HomePage: https://github.com/devsapp/start-java11-tablestore-http
Tags: #标签详情
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ Type: Application
Name: start-java11-tablestore
Provider:
- 阿里云
Version: dev
Version: 0.0.1
Description: 函数计算访问表格存储示例
HomePage: https://github.com/devsapp/start-java11-tablestore
Tags: #标签详情
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ Type: Application
Name: timer-trigger-fc-event-java11
Provider:
- 阿里云
Version: dev
Version: 0.0.1
Description: 快速部署一个具备 定时器触发器 Event 类型的函数到阿里云函数计算
HomePage: https://github.com/devsapp/start-fc
Tags:
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Type: Application
Name: cdn-trigger-fc-event-nodejs14
Version: dev
Version: 0.0.1
Provider:
- 阿里云
Description: 快速部署一个 具备 CDN 触发器 Event 类型的函数到阿里云函数计算。
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ Type: Application
Name: kafka-producer-fc-event-nodejs14
Provider:
- 阿里云
Version: dev
Version: 0.0.1
Description: 快速部署一个可以生产消息至 Kafka 的函数到阿里云函数计算
HomePage: https://github.com/devsapp/start-fc
Tags:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ Type: Application
Name: kafka-trigger-fc-event-nodejs14
Provider:
- 阿里云
Version: dev
Version: 0.0.1
Description: 快速部署一个具备 Kafka触发器 Event 类型的函数到阿里云函数计算
HomePage: https://github.com/devsapp/start-fc
Tags:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ Type: Application
Name: start-nodejs14-mongodb-http
Provider:
- 阿里云
Version: dev
Version: 0.0.1
Description: 函数计算访问MongoDB
HomePage: https://github.com/devsapp/start-nodejs14-mongodb-http
Tags: #标签详情
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ Type: Application
Name: start-nodejs14-mongodb
Provider:
- 阿里云
Version: dev
Version: 0.0.1
Description: 函数计算访问MongoDB
HomePage: https://github.com/devsapp/start-nodejs14-mongodb
Tags: #标签详情
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Type: Application
Name: ots-trigger-fc-event-nodejs
Version: dev
Version: 0.0.1
Provider:
- 阿里云
Description: 快速部署一个 具备 OTS 触发器 Event 类型的函数到阿里云函数计算。
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ Type: Application
Name: start-nodejs14-tablestore-http
Provider:
- 阿里云
Version: dev
Version: 0.0.1
Description: 函数计算访问表格存储示例
HomePage: https://github.com/devsapp/start-nodejs14-tablestore-http
Tags: #标签详情
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ Type: Application
Name: timer-trigger-fc-event-nodejs14
Provider:
- 阿里云
Version: dev
Version: 0.0.1
Description: 快速部署一个具备 定时器触发器 Event 类型的函数到阿里云函数计算
HomePage: https://github.com/devsapp/start-fc
Tags:
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Type: Application
Name: cdn-trigger-fc-event-php
Version: dev
Version: 0.0.1
Provider:
- 阿里云
Description: 快速部署一个 具备 CDN 触发器 Event 类型的函数到阿里云函数计算。
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ Type: Application
Name: start-php-mongodb-http
Provider:
- 阿里云
Version: dev
Version: 0.0.1
Description: 函数计算访问MongoDB
HomePage: https://github.com/devsapp/start-php-mongodb-http
Tags: #标签详情
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ Type: Application
Name: start-php-mongodb
Provider:
- 阿里云
Version: dev
Version: 0.0.1
Description: 函数计算访问MongoDB
HomePage: https://github.com/devsapp/start-php-mongodb
Tags: #标签详情
Expand Down
Loading

0 comments on commit a1b494d

Please sign in to comment.