Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
18 changes: 17 additions & 1 deletion web-framework/python/flask/publish.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,15 @@ Type: Project
Name: start-flask-cap
Provider:
- 阿里云
Version: 0.0.5
Version: 0.1.1
Description: 本案例展示了如何将 Flask,一款非常受欢迎的 Web 框架,快捷创建并部署到云原生应用开发平台 CAP。Flask 以其轻量级、简洁性和易用性著称,特别适用于小型、简单的 Web 应用或 API 开发。
HomePage: https://github.com/devsapp/start-web-framework/tree/dipper/web-framework/python/flask
Organization: 阿里云函数计算(FC)
Effective: Public
Tags:
- Web框架
- Flask
- Develop
Category: Web框架
Service:
函数计算:
Expand All @@ -25,6 +26,7 @@ Parameters:
required: # 必填项
- region
- functionName
- roleArn
properties:
region:
title: 地域
Expand Down Expand Up @@ -58,3 +60,17 @@ Parameters:
default: flask-${default-suffix}
pattern: "^[a-zA-Z_][a-zA-Z0-9-_]{0,127}$"
description: 函数名称,只能包含字母、数字、下划线和中划线。不能以数字、中划线开头。长度在 1-128 之间
roleArn:
title: 服务角色ARN
type: string
default: "AliyunFCDefaultRole"
pattern: "^acs:ram::[0-9]*:role/.*$"
description: "函数计算访问其他云服务时使用的服务角色,需要填写具体的角色ARN,格式为acs:ram::$account-id>:role/$role-name。例如:acs:ram::14310000000:role/aliyunfcdefaultrole。
\n如果您没有特殊要求,可以使用函数计算提供的默认的服务角色,即AliyunFCDefaultRole。如果您首次使用函数计算,可以访问 https://fcnext.console.aliyun.com 进行授权。
\n详细文档参考 https://help.aliyun.com/document_detail/181589.html?spm=5176.fcnext.help.dexternal.7bea78c8sVHoRf#section-o93-dbr-z6o"
x-role:
name: AliyunFCDefaultRole
service: fc
authorities:
- AliyunOSSFullAccess
- AliyunFCDefaultRolePolicy
10 changes: 10 additions & 0 deletions web-framework/python/flask/src/.fcignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
.idea/
.venv/
.vscode/
.DS_Store
.env
s.yaml
readme.md
build.sh
.fcignore
.gitignore
267 changes: 267 additions & 0 deletions web-framework/python/flask/src/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,267 @@
# Created by https://www.toptal.com/developers/gitignore/api/python,intellij+all
# Edit at https://www.toptal.com/developers/gitignore?templates=python,intellij+all

### Intellij+all ###
# Covers JetBrains IDEs: IntelliJ, RubyMine, PhpStorm, AppCode, PyCharm, CLion, Android Studio, WebStorm and Rider
# Reference: https://intellij-support.jetbrains.com/hc/en-us/articles/206544839

# User-specific stuff
.idea/**/workspace.xml
.idea/**/tasks.xml
.idea/**/usage.statistics.xml
.idea/**/dictionaries
.idea/**/shelf

# AWS User-specific
.idea/**/aws.xml

# Generated files
.idea/**/contentModel.xml

# Sensitive or high-churn files
.idea/**/dataSources/
.idea/**/dataSources.ids
.idea/**/dataSources.local.xml
.idea/**/sqlDataSources.xml
.idea/**/dynamic.xml
.idea/**/uiDesigner.xml
.idea/**/dbnavigator.xml

# Gradle
.idea/**/gradle.xml
.idea/**/libraries

# Gradle and Maven with auto-import
# When using Gradle or Maven with auto-import, you should exclude module files,
# since they will be recreated, and may cause churn. Uncomment if using
# auto-import.
# .idea/artifacts
# .idea/compiler.xml
# .idea/jarRepositories.xml
# .idea/modules.xml
# .idea/*.iml
# .idea/modules
# *.iml
# *.ipr

# CMake
cmake-build-*/

# Mongo Explorer plugin
.idea/**/mongoSettings.xml

# File-based project format
*.iws

# IntelliJ
out/

# mpeltonen/sbt-idea plugin
.idea_modules/

# JIRA plugin
atlassian-ide-plugin.xml

# Cursive Clojure plugin
.idea/replstate.xml

# SonarLint plugin
.idea/sonarlint/

# Crashlytics plugin (for Android Studio and IntelliJ)
com_crashlytics_export_strings.xml
crashlytics.properties
crashlytics-build.properties
fabric.properties

# Editor-based Rest Client
.idea/httpRequests

# Android studio 3.1+ serialized cache file
.idea/caches/build_file_checksums.ser

### Intellij+all Patch ###
# Ignore everything but code style settings and run configurations
# that are supposed to be shared within teams.

.idea/*

!.idea/codeStyles
!.idea/runConfigurations

### Python ###
# Byte-compiled / optimized / DLL files
__pycache__/
*.py[cod]
*$py.class

# C extensions
*.so

# Distribution / packaging
.Python
build/
develop-eggs/
dist/
downloads/
eggs/
.eggs/
lib/
lib64/
parts/
sdist/
var/
wheels/
share/python-wheels/
*.egg-info/
.installed.cfg
*.egg
MANIFEST

# PyInstaller
# Usually these files are written by a python script from a template
# before PyInstaller builds the exe, so as to inject date/other infos into it.
*.manifest
*.spec

# Installer logs
pip-log.txt
pip-delete-this-directory.txt

# Unit test / coverage reports
htmlcov/
.tox/
.nox/
.coverage
.coverage.*
.cache
nosetests.xml
coverage.xml
*.cover
*.py,cover
.hypothesis/
.pytest_cache/
cover/

# Translations
*.mo
*.pot

# Django stuff:
*.log
local_settings.py
db.sqlite3
db.sqlite3-journal

# Flask stuff:
instance/
.webassets-cache

# Scrapy stuff:
.scrapy

# Sphinx documentation
docs/_build/

# PyBuilder
.pybuilder/
target/

# Jupyter Notebook
.ipynb_checkpoints

# IPython
profile_default/
ipython_config.py

# pyenv
# For a library or package, you might want to ignore these files since the code is
# intended to run in multiple environments; otherwise, check them in:
# .python-version

# pipenv
# According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control.
# However, in case of collaboration, if having platform-specific dependencies or dependencies
# having no cross-platform support, pipenv may install dependencies that don't work, or not
# install all needed dependencies.
#Pipfile.lock

# poetry
# Similar to Pipfile.lock, it is generally recommended to include poetry.lock in version control.
# This is especially recommended for binary packages to ensure reproducibility, and is more
# commonly ignored for libraries.
# https://python-poetry.org/docs/basic-usage/#commit-your-poetrylock-file-to-version-control
#poetry.lock

# pdm
# Similar to Pipfile.lock, it is generally recommended to include pdm.lock in version control.
#pdm.lock
# pdm stores project-wide configurations in .pdm.toml, but it is recommended to not include it
# in version control.
# https://pdm.fming.dev/#use-with-ide
.pdm.toml

# PEP 582; used by e.g. github.com/David-OConnor/pyflow and github.com/pdm-project/pdm
__pypackages__/

# Celery stuff
celerybeat-schedule
celerybeat.pid

# SageMath parsed files
*.sage.py

# Environments
.env
.venv
env/
venv/
ENV/
env.bak/
venv.bak/

# Spyder project settings
.spyderproject
.spyproject

# Rope project settings
.ropeproject

# mkdocs documentation
/site

# mypy
.mypy_cache/
.dmypy.json
dmypy.json

# Pyre type checker
.pyre/

# pytype static type analyzer
.pytype/

# Cython debug symbols
cython_debug/

# PyCharm
# JetBrains specific template is maintained in a separate JetBrains.gitignore that can
# be found at https://github.com/github/gitignore/blob/main/Global/JetBrains.gitignore
# and can be added to the global gitignore or merged into this file. For a more nuclear
# option (not recommended) you can uncomment the following to ignore the entire idea folder.
#.idea/

### Python Patch ###
# Poetry local configuration file - https://python-poetry.org/docs/configuration/#local-configuration
poetry.toml

# ruff
.ruff_cache/

# LSP config files
pyrightconfig.json

# End of https://www.toptal.com/developers/gitignore/api/python,intellij+all

python
.idea
8 changes: 8 additions & 0 deletions web-framework/python/flask/src/alicloud/oss.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import oss2

from config import config

stsAuth = oss2.StsAuth(config.ACCESS_KEY_ID, config.ACCESS_KEY_SECRET, config.SECURITY_TOKEN)
# https://help.aliyun.com/zh/oss/user-guide/regions-and-endpoints
endpoint = "oss-%s-internal.aliyuncs.com" % config.CURRENT_REGION
oss_client = oss2.Service(stsAuth, endpoint)
4 changes: 2 additions & 2 deletions web-framework/python/flask/src/build.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,6 @@ start_flask:
- python3.10
steps:
- run: mkdir -p python
path: ./code
path: ./
- run: pip install -r requirements.txt -t ./python
path: ./code
path: ./
30 changes: 0 additions & 30 deletions web-framework/python/flask/src/code/index.py

This file was deleted.

2 changes: 0 additions & 2 deletions web-framework/python/flask/src/code/requirements.txt

This file was deleted.

13 changes: 13 additions & 0 deletions web-framework/python/flask/src/config.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import os


class Config:
SECRET_KEY = os.environ.get('SECRET_KEY') or 'my-passwd'
ACCESS_KEY_ID = os.environ.get("ALIBABA_CLOUD_ACCESS_KEY_ID") or 'default-access-key-id'
ACCESS_KEY_SECRET = os.environ.get("ALIBABA_CLOUD_ACCESS_KEY_SECRET") or 'default-access-key-secret'
SECURITY_TOKEN = os.environ.get("ALIBABA_CLOUD_SECURITY_TOKEN") or 'default-security-token'
CURRENT_REGION = os.environ.get("FC_REGION") or 'cn-hangzhou'
DEBUG = True


config = Config
5 changes: 5 additions & 0 deletions web-framework/python/flask/src/index.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
from init import create_app
app = create_app()

if __name__ == "__main__":
app.run(host="0.0.0.0", port=9000)
Loading