Skip to content

Commit

Permalink
Merge pull request #2 from devsapp/add-new
Browse files Browse the repository at this point in the history
add lindorm and postgresql
  • Loading branch information
rsonghuster authored Aug 31, 2021
2 parents e634a86 + f91b27f commit 8c686f3
Show file tree
Hide file tree
Showing 19 changed files with 235 additions and 4 deletions.
20 changes: 20 additions & 0 deletions .github/workflows/python-publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -60,4 +60,24 @@ jobs:
wget https://serverless-registry.oss-cn-hangzhou.aliyuncs.com/publish-file/python3/hub-publish.py
ls
python hub-publish.py
cd ..
- name: fc-postgresql-python
env:
publish_token: ${{ secrets.alibaba_registry_publish_token }}
run: |
cd postgresql
wget https://serverless-registry.oss-cn-hangzhou.aliyuncs.com/publish-file/python3/hub-publish.py
ls
python hub-publish.py
cd ..
- name: fc-lindorm-python
env:
publish_token: ${{ secrets.alibaba_registry_publish_token }}
run: |
cd lindorm
wget https://serverless-registry.oss-cn-hangzhou.aliyuncs.com/publish-file/python3/hub-publish.py
ls
python hub-publish.py
cd ..
20 changes: 20 additions & 0 deletions lindorm/publish.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
Type: Application
Name: start-fc-lindorm-python
Version: 0.0.3
Provider:
- 阿里云
Description: 快速部署一个 Python 访问 lindorm 的函数到阿里云函数计算。
HomePage: https://github.com/devsapp/start-fc-db-python
Tags:
- 函数计算
- 你好世界
- 新手入门
Category: 新手入门
Service:
函数计算:
Authorities:
- 创建函数
- 删除函数
- 创建服务
- 删除服务
Runtime: Python
12 changes: 12 additions & 0 deletions lindorm/readme.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
# 阿里云函数计算 Python 访问 Lindorm 云数据库

只需几步就可以快速在阿里云函数计算服务上体验 Python 访问 redis 数据库

- 初始化项目:`s init start-fc-lindorm-python -d start-fc-lindorm-python`
- 进入项目:`cd start-fc-lindorm-python`
- 将 s.yaml 中的环境变量修改成您自己的值, 并将数据库操作代码改成您需要的
- 构建项目:`s build --use-docker`
- 部署项目:`s deploy`
- 触发项目:`s invoke`

即可实现`Python 访问 Lindorm`案例的初始化、部署整个流程。
30 changes: 30 additions & 0 deletions lindorm/src/code/index.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
# -*- coding: utf-8 -*-
import logging
import os
from cassandra.cluster import Cluster
from cassandra.auth import PlainTextAuthProvider

logger = logging.getLogger()


def handler(event, context):
logger.info("start to test Lindorm ")
addr_str = os.environ['DATABASE_ADDR']
cluster = Cluster(
# 配置连接地址。
contact_points=addr_str.split(","),
# 配置用户名和密码。
auth_provider=PlainTextAuthProvider(os.environ['USER'], os.environ['PASSWORD']))
session = cluster.connect()
session.execute(
"CREATE KEYSPACE IF NOT EXISTS testKeyspace WITH replication = {'class':'SimpleStrategy', 'replication_factor':1};")
session.execute(
"CREATE TABLE IF NOT EXISTS testKeyspace.testTable (id int PRIMARY KEY, name text,age int,address text);")
session.execute(
"INSERT INTO testKeyspace.testTable (id, name, age, address) VALUES ( 1, 'testname', 11, 'hangzhou');")
rows = session.execute("SELECT * FROM testKeyspace.testTable ;")
for row in rows:
logger.info("# row: {}".format(row))

session.shutdown()
cluster.shutdown()
1 change: 1 addition & 0 deletions lindorm/src/code/requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
cassandra-driver
12 changes: 12 additions & 0 deletions lindorm/src/readme.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
# 阿里云函数计算 Python 访问 Lindorm 云数据库

只需几步就可以快速在阿里云函数计算服务上体验 Python 访问 redis 数据库

- 初始化项目:`s init start-fc-lindorm-python -d start-fc-lindorm-python`
- 进入项目:`cd start-fc-lindorm-python`
- 将 s.yaml 中的环境变量修改成您自己的值, 并将数据库操作代码改成您需要的
- 构建项目:`s build --use-docker`
- 部署项目:`s deploy`
- 触发项目:`s invoke`

即可实现`Python 访问 Lindorm`案例的初始化、部署整个流程。
26 changes: 26 additions & 0 deletions lindorm/src/s.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
edition: 1.0.0 # 命令行YAML规范版本,遵循语义化版本(Semantic Versioning)规范
name: fcDeployApp # 项目名称
access: "{{ access }}" # 秘钥别名

services:
fc-db-lindorm-python: # 服务名称
component: devsapp/fc # 组件名称
props: # 组件的属性值
region: cn-hangzhou
service:
name: fc-db-demo
description: 'demo for fc visit db'
internetAccess: true
function:
name: lindorm
description: visit lindorm
runtime: python3
codeUri: ./code
handler: index.handler
memorySize: 256
timeout: 30
environmentVariables:
DATABASE_ADDR: <your database>
USER: <your user>
PASSWORD: <your password>
# 函数计算FC组件文档参考地址:https://github.com/devsapp/fc
1 change: 1 addition & 0 deletions lindorm/version.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
- 新版本支持
2 changes: 1 addition & 1 deletion mongodb/publish.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Type: Application
Name: start-fc-mongodb-python
Version: 0.0.2
Version: 0.0.3
Provider:
- 阿里云
Description: 快速部署一个 Python 访问 mongodb 的函数到阿里云函数计算。
Expand Down
2 changes: 1 addition & 1 deletion mysql/publish.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Type: Application
Name: start-fc-mysql-python
Version: 0.0.2
Version: 0.0.3
Provider:
- 阿里云
Description: 快速部署一个 Python 访问 mysql 的函数到阿里云函数计算。
Expand Down
20 changes: 20 additions & 0 deletions postgresql/publish.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
Type: Application
Name: start-fc-postgresql-python
Version: 0.0.3
Provider:
- 阿里云
Description: 快速部署一个 Python 访问 postgresql 的函数到阿里云函数计算。
HomePage: https://github.com/devsapp/start-fc-db-python
Tags:
- 函数计算
- 你好世界
- 新手入门
Category: 新手入门
Service:
函数计算:
Authorities:
- 创建函数
- 删除函数
- 创建服务
- 删除服务
Runtime: Python
12 changes: 12 additions & 0 deletions postgresql/readme.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
# 阿里云函数计算 Python 访问 postgresql 数据库

只需几步就可以快速在阿里云函数计算服务上体验 Python 访问 redis 数据库

- 初始化项目:`s init start-fc-postgresql-python -d start-fc-postgresql-python`
- 进入项目:`cd start-fc-postgresql-python`
- 将 s.yaml 中的环境变量修改成您自己的值, 并将数据库操作代码改成您需要的
- 构建项目:`s build --use-docker`
- 部署项目:`s deploy`
- 触发项目:`s invoke`

即可实现`Python 访问 postgresql`案例的初始化、部署整个流程。
35 changes: 35 additions & 0 deletions postgresql/src/code/index.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
# -*- coding: utf-8 -*-
import logging
import psycopg2
import os
import sys
logger = logging.getLogger()


def getConnection():
try:
conn = psycopg2.connect(
database=os.environ['DATABASE'],
user=os.environ['USER'],
password=os.environ['PASSWORD'],
host=os.environ['HOST'],
port=os.environ['PORT'],
)
return conn
except Exception as e:
logger.error(e)
logger.error(
"ERROR: Unexpected error: Could not connect to PostgreSQL instance.")
raise Exception(str(e))


def handler(event, context):
conn = getConnection()
try:
cur = conn.cursor()
cur.execute("INSERT INTO COMPANY (ID,NAME,AGE,ADDRESS,SALARY) \
VALUES (1, 'Paul', 32, 'California', 20000.00 )")
conn.commit()
return 'successfully'
finally:
conn.close()
1 change: 1 addition & 0 deletions postgresql/src/code/requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
psycopg2
12 changes: 12 additions & 0 deletions postgresql/src/readme.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
# 阿里云函数计算 Python 访问 postgresql 数据库

只需几步就可以快速在阿里云函数计算服务上体验 Python 访问 redis 数据库

- 初始化项目:`s init start-fc-postgresql-python -d start-fc-postgresql-python`
- 进入项目:`cd start-fc-postgresql-python`
- 将 s.yaml 中的环境变量修改成您自己的值, 并将数据库操作代码改成您需要的
- 构建项目:`s build --use-docker`
- 部署项目:`s deploy`
- 触发项目:`s invoke`

即可实现`Python 访问 postgresql`案例的初始化、部署整个流程。
28 changes: 28 additions & 0 deletions postgresql/src/s.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
edition: 1.0.0 # 命令行YAML规范版本,遵循语义化版本(Semantic Versioning)规范
name: fcDeployApp # 项目名称
access: "{{ access }}" # 秘钥别名

services:
fc-db-postgresql-python: # 服务名称
component: devsapp/fc # 组件名称
props: # 组件的属性值
region: cn-hangzhou
service:
name: fc-db-demo
description: 'demo for fc visit db'
internetAccess: true
function:
name: postgresql
description: visit postgresql
runtime: python3
codeUri: ./code
handler: index.handler
memorySize: 256
timeout: 30
environmentVariables:
DATABASE: <your database>
HOST: <your host>
PORT: <your port>
USER: <your user>
PASSWORD: <your password>
# 函数计算FC组件文档参考地址:https://github.com/devsapp/fc
1 change: 1 addition & 0 deletions postgresql/version.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
- 新版本支持
2 changes: 1 addition & 1 deletion redis/publish.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Type: Application
Name: start-fc-redis-python
Version: 0.0.2
Version: 0.0.3
Provider:
- 阿里云
Description: 快速部署一个 Python 访问 redis 的函数到阿里云函数计算。
Expand Down
2 changes: 1 addition & 1 deletion sql_server/publish.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Type: Application
Name: start-fc-sql-server-python
Version: 0.0.2
Version: 0.0.3
Provider:
- 阿里云
Description: 快速部署一个 Python 访问 sql-server 的函数到阿里云函数计算。
Expand Down

0 comments on commit 8c686f3

Please sign in to comment.