Skip to content

Commit

Permalink
add golang, nodejs14, and python3.9 custom container demo that suppor…
Browse files Browse the repository at this point in the history
…t websocket
  • Loading branch information
定戎 committed Mar 3, 2022
1 parent 4080730 commit 2134f9b
Show file tree
Hide file tree
Showing 30 changed files with 1,547 additions and 4 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
async function preInit(inputObj) {
console.log(`\n ____ _ _ ___ _ _ _ _____ ____
/ _ \\/ \\ / \\\\ \\/// \\ /\\/ \\ /| / // _\\
| / \\|| | | | \\ / | | ||| |\\ || | __\\| /
| |-||| |_/\\| | / / | \\_/|| | \\|| | | | \\__
\\_/ \\|\\____/\\_//_/ \\____/\\_/ \\| \\_/ \\____/`)
}

async function postInit(inputObj) {
console.log(`\n Welcome to the Aliyun FC start application
This application requires to open these services:
FC : https://fc.console.aliyun.com/
ACR: https://cr.console.aliyun.com/
* 额外说明:s.yaml中声明了actions:
部署前执行:s build --use-docker --dockerfile ./code/Dockerfile
如果不需要每次都构建项目,或者部署前不需要构建,或者已经手动构建了,可以注释掉这部分内容
> PS:部署的时候还需要修改s.yaml中image字段为自己的acr配置的地址
* 项目初始化完成,您可以直接进入项目目录下,并使用 s deploy 进行项目部署
\n`)
}

module.exports = {
postInit,
preInit
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
Type: Application
Name: start-fc-custom-container-websocket-golang
Provider:
- 阿里云
Version: 0.0.1
Description: 快速部署一个基于custom container runtime 的 Golang Wensocket 类型的 Hello World 到阿里云函数计算
HomePage: https://github.com/devsapp/start-fc
Tags:
- 函数计算
- 你好世界
- 新手入门
Category: 新手入门
Service:
函数计算:
Authorities:
- 创建函数
- 删除函数
- 创建服务
- 删除服务
Runtime: custom container
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# 阿里云函数计算 Custom Container Golang WebSocket 函数案例

只需几步就可以快速在阿里云函数计算服务上体验 Golang:

- 初始化项目:`s init start-fc-custom-container-websocket-golang -d start-cc-golang`
- 进入项目:`cd start-cc-golang`
- 修改 s.yaml 中 Image 为自己的 ACR 镜像地址
- 部署项目:`s deploy -y`
- 调用函数:`# 在浏览器或者 Postman 中进行调用`

即可实现`Custom Container Golang`案例的初始化、部署整个流程。

> 本应用仓库地址:https://github.com/devsapp/start-fc
------------------------------------
> # More
> 欢迎您使用阿里云函数计算 FC 组件进行项目开发
> 组件仓库地址/帮助文档:https://github.com/devsapp/fc
> Yaml参考文档:https://github.com/devsapp/fc/blob/main/docs/zh/yaml.md
> 快速入门:
> - 快速创建应用:https://github.com/devsapp/fc/blob/main/docs/zh/quick_start_application.md
> - 快速使用命令:https://github.com/devsapp/fc/blob/main/docs/zh/quick_start_function.md
------------------------------------
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
# Alibaba Cloud Function Computing Custom Container Golang WebSocket function

You can quickly experience one-click deployment of a Golang application on Alibaba Cloud Function Computing Service in just a few steps:

- Initialize the project: `s init start-fc-custom-container-websocket-golang -d start-cc-golang`
- Enter the project: `cd start-cc-golang`
- Modify Image in s.yaml to be your own ACR mirror address
- Deployment project: `s deploy -y`
- Invoke function: `# invoke by browser or postman`

> This application warehouse address: https://github.com/devsapp/start-fc
------------------------------------
> # More
> Welcome to use Alibaba Cloud Function Compute FC component for project development
>
> Component warehouse address/help document: https://github.com/devsapp/fc
>
> Yaml reference documentation: https://github.com/devsapp/fc/blob/main/docs/zh/yaml.md
>
> Quick start:
> - Quickly create an application: https://github.com/devsapp/fc/blob/main/docs/zh/quick_start_application.md
> - Quick use of commands: https://github.com/devsapp/fc/blob/main/docs/zh/quick_start_function.md
------------------------------------
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# 阿里云函数计算 Custom Container Golang WebSocket 函数案例

只需几步就可以快速在阿里云函数计算服务上体验 Golang:

- 初始化项目:`s init start-fc-custom-container-websocket-golang -d start-cc-websocket-golang`
- 进入项目:`cd start-cc-golang`
- 修改 s.yaml 中 Image 为自己的 ACR 镜像地址
- 部署项目:`s deploy -y`
- 调用函数:`# 在浏览器或者 Postman 中进行调用`

即可实现`Custom Container golang`案例的初始化、部署整个流程。

> 本应用仓库地址:https://github.com/devsapp/start-fc
------------------------------------
> # More
> 欢迎您使用阿里云函数计算 FC 组件进行项目开发
> 组件仓库地址/帮助文档:https://github.com/devsapp/fc
> Yaml参考文档:https://github.com/devsapp/fc/blob/main/docs/zh/yaml.md
> 快速入门:
> - 快速创建应用:https://github.com/devsapp/fc/blob/main/docs/zh/quick_start_application.md
> - 快速使用命令:https://github.com/devsapp/fc/blob/main/docs/zh/quick_start_function.md
------------------------------------
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
FROM golang:1.12.16-stretch
RUN mkdir -p $GOPATH/src/golang.org/x/
RUN cd $GOPATH/src/golang.org/x/ && git clone https://github.com/golang/net.git
RUN cd $GOPATH/src/golang.org/x/ && git clone https://github.com/golang/sys.git
RUN go get github.com/awesome-fc/golang-runtime
RUN go get github.com/gorilla/websocket

WORKDIR /tmp
COPY . .

RUN go build -o bootstrap main.go
RUN mkdir -p /usr/src/app
WORKDIR /usr/src/app
RUN cp /tmp/bootstrap ./bootstrap
ENTRYPOINT ["/usr/src/app/bootstrap"]
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
package main

import (
"net/http"

"github.com/gorilla/websocket"
)

var upgrader = websocket.Upgrader{}

func echo(w http.ResponseWriter, r *http.Request) {
c, err := upgrader.Upgrade(w, r, nil)
if err != nil {
return
}
defer c.Close()
for {
mt, message, err := c.ReadMessage()
if err != nil {
break
}
err = c.WriteMessage(mt, message)
if err != nil {
break
}
}
}

func main() {
http.HandleFunc("/", echo)
http.ListenAndServe(":9000", nil)
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
# ------------------------------------
# 欢迎您使用阿里云函数计算 FC 组件进行项目开发
# 组件仓库地址/帮助文档:https://github.com/devsapp/fc
# Yaml参考文档:https://github.com/devsapp/fc/blob/jiangyu-docs/docs/zh/yaml.md
# 关于:
# - Serverless Devs和FC组件的关系、如何声明/部署多个函数、超过50M的代码包如何部署
# - 关于.fcignore使用方法、工具中.s目录是做什么、函数进行build操作之后如何处理build的产物
# 等问题,可以参考文档:https://github.com/devsapp/fc/blob/jiangyu-docs/docs/zh/tips.md
# 关于如何做CICD等问题,可以参考:https://github.com/Serverless-Devs/Serverless-Devs/blob/master/docs/zh/cicd.md
# 有问题快来钉钉群问一下吧:33947367
# ------------------------------------
edition: 1.0.0
name: hello-world-app
access: "{{ access }}"

vars: # 全局变量
region: cn-shanghai
service:
name: hello-world-service
description: 'hello world by serverless devs'

services:
helloworld: # 业务名称/模块名称
component: fc
actions: # 自定义执行逻辑
pre-deploy: # 在deploy之前运行
- run: s build --use-docker --dockerfile ./code/Dockerfile # 要运行的命令行
path: ./ # 命令行运行的路径
# post-deploy: # 在deploy之后运行
# - run: s versions # 要运行的命令行
# path: ./ # 命令行运行的路径
props:
region: ${vars.region}
service: ${vars.service}
function:
name: go-websocket-function
description: 'hello world by serverless devs'
timeout: 60
caPort: 9000
memorySize: 256
runtime: custom-container
customContainerConfig:
#instanceID: cri-v1akeviqpik09jgs 企业实例需要提供
image: registry.cn-shanghai.aliyuncs.com/fc-demo2/custom_container:v3 # 需要换成自己的registry地址
codeUri: ./code
triggers:
- name: http_t
type: http
config:
authType: anonymous
methods:
- GET
# next-function: # 第二个函数的案例,仅供参考
# # 如果在当前项目下执行 s deploy,会同时部署模块:
# # helloworld:服务hello-world-service,函数cpp-event-function
# # next-function:服务hello-world-service,函数next-function-example
# # 如果想单独部署当前服务与函数,可以执行 s + 模块名/业务名 + deploy,例如:s next-function deploy
# # 如果想单独部署当前函数,可以执行 s + 模块名/业务名 + deploy function,例如:s next-function deploy function
# # 更多命令可参考:https://github.com/devsapp/fc/tree/jiangyu-docs/docs#文档相关
# component: fc
# props:
# region: ${vars.region}
# service: ${vars.service} # 应用整体的服务配置
# function: # 定义一个新的函数
# name: next-function-example
# description: 'hello world by serverless devs'
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
- 兼容新版本
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
async function preInit(inputObj) {
console.log(`\n ____ _ _ ___ _ _ _ _____ ____
/ _ \\/ \\ / \\\\ \\/// \\ /\\/ \\ /| / // _\\
| / \\|| | | | \\ / | | ||| |\\ || | __\\| /
| |-||| |_/\\| | / / | \\_/|| | \\|| | | | \\__
\\_/ \\|\\____/\\_//_/ \\____/\\_/ \\| \\_/ \\____/`)
}

async function postInit(inputObj) {
console.log(`\n Welcome to the Aliyun FC start application
This application requires to open these services:
FC : https://fc.console.aliyun.com/
ACR: https://cr.console.aliyun.com/
* 额外说明:s.yaml中声明了actions:
部署前执行:s build --use-docker --dockerfile ./code/Dockerfile
如果不需要每次都构建项目,或者部署前不需要构建,或者已经手动构建了,可以注释掉这部分内容
> PS:部署的时候还需要修改s.yaml中image字段为自己的acr配置的地址
* 项目初始化完成,您可以直接进入项目目录下,并使用 s deploy 进行项目部署
\n`)
}

module.exports = {
postInit,
preInit
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
Type: Application
Name: start-fc-custom-container-websocket-nodejs14
Provider:
- 阿里云
Version: 0.0.1
Description: 快速部署一个基于custom container runtime 的 nodejs14 WebSocket 类型的 Echo 函数到阿里云函数计算
HomePage: https://github.com/devsapp/start-fc
Tags:
- 函数计算
- 你好世界
- 新手入门
Category: 新手入门
Service:
函数计算:
Authorities:
- 创建函数
- 删除函数
- 创建服务
- 删除服务
Runtime: custom container


Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# 阿里云函数计算 Custom Container Node.JS 14 Event 函数案例

只需几步就可以快速在阿里云函数计算服务上体验 Node.JS 14 :

- 初始化项目:`s init start-fc-custom-container-websocket-nodejs14 -d start-cc-websocket-nodejs14`
- 进入项目:`cd start-cc-websocket-nodejs14`
- 修改 s.yaml 中 Image 为自己的 ACR 镜像地址
- 部署项目:`s deploy -y`
- 调用函数:`# 使用浏览器或者 Postman 进行调用`

即可实现`Custom Container Nodejs 14`案例的初始化、部署整个流程。

> 本应用仓库地址:https://github.com/devsapp/start-fc
------------------------------------
> # More
> 欢迎您使用阿里云函数计算 FC 组件进行项目开发
> 组件仓库地址/帮助文档:https://github.com/devsapp/fc
> Yaml参考文档:https://github.com/devsapp/fc/blob/main/docs/zh/yaml.md
> 快速入门:
> - 快速创建应用:https://github.com/devsapp/fc/blob/main/docs/zh/quick_start_application.md
> - 快速使用命令:https://github.com/devsapp/fc/blob/main/docs/zh/quick_start_function.md
------------------------------------
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
# Alibaba Cloud Function Computing Custom Container Node.JS 14 WebSocket function

You can quickly experience one-click deployment of a Node.JS 14 application on Alibaba Cloud Function Computing Service in just a few steps:

- Initialize the project: `s init start-fc-custom-container-websocket-nodejs14 -d start-cc-websocket-nodejs14`
- Enter the project: `cd start-cc-websocket-nodejs14`
- Modify Image in s.yaml to be your own ACR mirror address
- Deployment project: `s deploy -y`
- Invoke function: `# invoke by browser or postman`

> This application warehouse address: https://github.com/devsapp/start-fc
------------------------------------
> # More
> Welcome to use Alibaba Cloud Function Compute FC component for project development
>
> Component warehouse address/help document: https://github.com/devsapp/fc
>
> Yaml reference documentation: https://github.com/devsapp/fc/blob/main/docs/zh/yaml.md
>
> Quick start:
> - Quickly create an application: https://github.com/devsapp/fc/blob/main/docs/zh/quick_start_application.md
> - Quick use of commands: https://github.com/devsapp/fc/blob/main/docs/zh/quick_start_function.md
------------------------------------
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# 阿里云函数计算 Custom Container Node.JS 14 WebSocket 函数案例

只需几步就可以快速在阿里云函数计算服务上体验 Node.JS 14 :

- 初始化项目:`s init start-fc-custom-container-websocket-nodejs14 -d start-cc-websocket-nodejs14`
- 进入项目:`cd start-cc-websocket-nodejs14`
- 修改 s.yaml 中 Image 为自己的 ACR 镜像地址
- 部署项目:`s deploy -y`
- 调用函数:`# 在浏览器或者 Postman 中进行调用`

即可实现`Custom Container Nodejs 14`案例的初始化、部署整个流程。

> 本应用仓库地址:https://github.com/devsapp/start-fc
------------------------------------
> # More
> 欢迎您使用阿里云函数计算 FC 组件进行项目开发
> 组件仓库地址/帮助文档:https://github.com/devsapp/fc
> Yaml参考文档:https://github.com/devsapp/fc/blob/main/docs/zh/yaml.md
> 快速入门:
> - 快速创建应用:https://github.com/devsapp/fc/blob/main/docs/zh/quick_start_application.md
> - 快速使用命令:https://github.com/devsapp/fc/blob/main/docs/zh/quick_start_function.md
------------------------------------
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
FROM node:14.5.0-alpine3.11

# Create app directory
WORKDIR /usr/src/

# Install app dependencies
# A wildcard is used to ensure both package.json AND package-lock.json are copied
# where available (npm@5+)
COPY package*.json ./

RUN npm install
# If you are building your code for production
# RUN npm ci --only=production

# Bundle app source
COPY . .

EXPOSE 9000
ENTRYPOINT [ "node", "server.js" ]
Loading

0 comments on commit 2134f9b

Please sign in to comment.