首页
关于
Search
1
分享一些收集的Sync Key
5,507 阅读
2
mysql错误ERROR 1130 (HY000): Host 'localhost' is not allowed to connect to this MySQL server
1,634 阅读
3
对比win10系统上的三种软件包管理器scoop、chocolatey、winget
1,626 阅读
4
Resilio Sync 许可证下载
1,594 阅读
5
阿里云盘资源分享
1,249 阅读
前端
CSS
NodeJS
Javascript
小程序
Webpack
Vue
Typescript
Linux
软件教程
云服务器
脚本编程
技术扩展
Scoop
SSR
Youtube-dl
You-Get
Typecho
Annie
奇技淫巧
资源分享
Sync Key
随笔
疑难杂症
mysql
Docker
Python
Serverless
登录
Search
标签搜索
docker
K3S
powershell
scoop
webstorm
jQuery
webpack
typecho
mysql
windows10
linux
typescript
ssh
windows11
vue
git
Sync
fastify
winget
github
偏向技术
累计撰写
99
篇文章
累计收到
2
条评论
首页
栏目
前端
CSS
NodeJS
Javascript
小程序
Webpack
Vue
Typescript
Linux
软件教程
云服务器
脚本编程
技术扩展
Scoop
SSR
Youtube-dl
You-Get
Typecho
Annie
奇技淫巧
资源分享
Sync Key
随笔
疑难杂症
mysql
Docker
Python
Serverless
页面
关于
搜索到
5
篇与
Serverless
的结果
2021-07-27
快速使用 - 部署fastify项目
#操作步骤 #1. 拉取模板代码 powershell复制 fun init -n custom-fastify https://github.com/liuqian1996/fc-fastify # Or fun init -n custom-fastify gh:liuqian1996/fc-fastify # Typescript fun init -n custom-fastify-ts gh:liuqian1996/fc-fastify --var lang=ts 12345 #2. 开发 本地 powershell复制 # 安装依赖 npm install # Development npm run dev # Build (Only Typescript) npm run build # Test npm run test 12345678 FC powershell复制 # 安装依赖 fun install # Development fun local start Domain # Build fun build # Deploy fun deploy 12345678 #注意事项 如果出现以下错误,undefined, 请不要使用temp文件夹或在.funignore中出现的文件夹名称 powershell复制 build function using image: fun-cache-af0ac9c8-2cf0-48e3-8c63-bdd9ca06ee28 running task: flow NpmTaskFlow running task: CopySource undefined 1234 如果出现以下错误,"Cannot read property 'stop' of null",先删除.fun文件夹再重新执行fun install powershell复制 skip pulling image aliyunfc/runtime-custom:1.9.17... reloading success, stop old container background... Cannot read property 'stop' of null stopping old container successfully 1234
2021年07月27日
266 阅读
0 评论
0 点赞
2021-07-27
快速使用 - 部署express项目
#操作步骤 #1. 拉取模板代码 shell复制 # 拉取模板代码 fun init -n express-demo https://github.com/muxiangqiu/fc-express-nodejs8.git # Or fun init -n express-demo gh:muxiangqiu/fc-express-nodejs8 1234 #2. 本地开发 shell复制 # 进入项目目录 cd express-demo # 安装项目依赖 npm install # 安装concurrently npm install concurrently -D 123456 修改package.json中scripts的dev字段 json复制 "dev": "webpack --config webpack.dev.js" "dev": "concurrently -k -p \"[{name}]\" -n \"Webpack,Fun\" -c \"yellow.bold,cyan.bold\" \"webpack --watch --config webpack.dev.js\" \"fun local start\"" 12 执行命令,这样,修改js文件,刷新浏览器就能看到最新效果 shell复制 npm run dev 1 #3. 编译 shell复制 # 生产编译 npm run build 12 #4. 部署 shell复制 fun deploy 1
2021年07月27日
95 阅读
0 评论
0 点赞
2021-07-27
Fun Init 自定义模板
#模板项目目录结构 powershell复制 custom-fastify # ① 模板项目根目录 |-- metadata.js # ② 模板项目配置文件 `-- {{ projectName }} # ③ 模板根目录 |-- Funfile |-- README.md |-- bin |-- bootstrap |-- package.json |-- src |-- template.yml `-- test 1234567891011 目录结构说明: ① 模板项目根目录:如果模板项目需要上传到 github,则模板项目名称就是仓库名称 ② 模板项目配置文件:模板项目配置文件不是必须的,支持两种类型的文件:metadata.json 和 metadata.js ③ 模板根目录:fun init 会从模板根目录开始渲染输出,该目录必须是一个模板表达式。projectName 模板变量来自 fun init --name foo 的 --name 参数。绝大多数场景,模板根目录叫 {{ projectName }} 即可 #模板项目配置文件 js复制 module.exports = { // ① 模板项目名称 "name": "custom-fastify", // ② 模板项目描述 "description": "Fastify template for Custom Runtime", // ③ 隐式变量 "vars": { "service": "{{ projectName }}", "removeLines": str => str.replace(/^\s*$(?:\r\n?|\n)/gm, '') }, // ④ 提示输入变量(显式变量) "userPrompt": [ { "type": "confirm", // ⑤ 提示输入类型 "name": "httpTrigger", // ⑥ 模板变量名 "message": "Http Trigger?", // ⑦ 提示信息 "default": true // ⑧ 模板变量默认值 }, { "type": "confirm", "name": "customDomain", "message": "Custom domain?", "default": true } ], "copyOnlyPaths": [ "test" ], // ⑨ 设置某些目录和文件不需要渲染,只是简单的拷贝 "ignorePaths": [ "*.log" ] // ⑩ 拷贝时忽略某些目录和文件 } 12345678910111213141516171819202122232425262728 配置文件说明: ① 模板项目名称:对模板项目简单介绍 ② 模板项目描述:对模板项目详细介绍 ③ 隐式变量:相对显式变量而言,隐式变量不提示用户输入,可以通过 fun init --var baz=xxx 覆盖配置文件的隐式变量,如果显式和隐式有相同的变量,则该变量不会再提示用户输入,但是这种方式是不推荐使用的,也不要依赖此特性,即显式变量和隐式变量不要有交叉 ④ 提示输入变量(显式变量):在用户初始化模板项目的时候,会显式提示用户输入模板变量,底层用的是 Inquirer在新窗口打开,⑤、⑥、⑦和⑧ 详情可以参考: Inquirer 文档在新窗口打开。当通过 fun init --var foo=xxx 设置了 foo 变量后,则不会再提示用户输入 foo 变量的值,其他没有设置过的显式变量仍然提示输入 ⑨ 设置某些目录和文件不需要渲染,只是简单的拷贝:比如一些二进制文件。格式和 gitignore 是一样的,具体可以参考:gitignore 规范在新窗口打开 ⑩ 拷贝时忽略某些目录和文件:格式和 gitignore 是一样的,具体可以参考:gitignore 规范在新窗口打开 配置文件也可以使用变量,其中,projectName 模板变量来自 fun init --name foo 的 --name 参数,还可以使用 fun init --var abc=xxx 中的 abc 变量,但是,如果你不通过 --var 传 abc 变量,在渲染配置文件的时候,可能报变量未定义的错误,可以在使用的时候先判断一下,如:{{ typeof x === 'undefined' ? '' : x}} #支持模板语法的位置 模板项目配置文件 模板根目录 模板根目录下的子目录名称(支持多层嵌套) 模板根目录下的文件名称(支持多层嵌套) 模板根目录下的文件内容(支持多层嵌套) #模板变量设置方式 有三种种方式设置模板变量: 参数设置。通过 -V,--var 参数设置模板变量 显式变量。配置文件中的 userPrompt 隐式变量。配置文件中的 vars 优先级:参数设置 > 隐式变量。 优先级:显式变量 > 隐式变量。 说明:参数设置和显示变量互斥出现,优先级比较没有意义。 #模板语法 模板渲染底层是基于 lodash在新窗口打开 ,详情请参考:lodash 文档在新窗口打开。 主要用法: 模板表达式 模板表达式的正则表达式规则:/{{([\s\S]+?)}}/g ,以 {{ 开头,}} 结尾,中间可以是任意字符。 复制 # 假设 foo = 'bar' hello {{ foo }}! 输出:hello bar! {{ foo === 'bar' }} 输出:true {{ foo ? foo :'unknown' }} 输出:bar 1234 模板代码 模板代码的正则表达式规则:/<%([\s\S]+?)%>/g ,以 <% 开头,%> 结尾,中间可以是任意字符。 复制 <% if (foo === 'bar') { %> xxxxxxxxx <% } %> 1 #小结 自定义模板,支持通过配置文件定义渲染规则,模板引擎根据渲染规则渲染模板项目。其中,模板引擎支持模板表达式和模板代码,我们可以通过命令行参数和提示输入方式传递模板变量。 #相关文章 Inquirer 文档在新窗口打开 lodash 文档在新窗口打开 gitignore 规范在新窗口打开 开发函数计算的正确姿势 —— 使用 Fun Init 初始化项目在新窗口打开 开发函数计算的正确姿势 —— 使用 Fun Local 本地运行与调试在新窗口打开 开发函数计算的正确姿势 —— 爬虫在新窗口打开 开发函数计算的正确姿势 —— 排查超时问题在新窗口打开 Fun Repo在新窗口打开 Fun specs在新窗口打开 Fun examples在新窗口打开 Fun 发布 2.0 新版本啦在新窗口打开
2021年07月27日
123 阅读
0 评论
0 点赞
2021-07-27
Funcraft使用
Funcraft在新窗口打开是一个支持阿里云Serverless应用部署的工具,通过配置template.yml文件来协助进行开发、构建、部署等操作 #安装 #fun 建议使用npm进行安装,其他安装方式在新窗口打开 shell复制 npm install @alicloud/fun -g # 查看版本 fun --version 123 #docker Docker官网在新窗口打开 #配置 #1 .env文件 在template.yml文件所在目录,新建.env文件 ini复制 ACCOUNT_ID=xxxxxxxx REGION=cn-shanghai ACCESS_KEY_ID=xxxxxxxxxxxx ACCESS_KEY_SECRET=xxxxxxxxxx FC_ENDPOINT=https://{accountid}.{region}.fc.aliyuncs.com TIMEOUT=10 RETRIES=3 1234567 #2 fun config命令 通过执行fun config命令,依次配置Account ID、AccessKey ID、AccessKey Secret、Default Region Name等参数,其中Account ID就是账号ID,AccessKey ID可以在函数计算控制台右上角的AccessKey 管理 - 开始使用子用户AccessKey - 创建用户,创建成功后,可以看到AccessKey ID和AccessKey Secret,离开页面后AccessKey Secret将不可见,所以务必在离开时进行复制,Default Region Name可以参考Region List在新窗口打开,如下图所示。 #3 通过环境变量配置 针对不同的平台,通过环境变量配置Funcraft的步骤不同,通过环境变量进行配置时,可选配置项与.env相同 #命令说明 shell复制 > fun Usage: fun [options] [command] The fun command line provides a complete set of commands to define, develop, test serverless applications locally, and deploy them to the Alibaba Cloud. Options: --version output the version number -v, --verbose verbose output -h, --help display help for command Commands: config Configure the fun init Initialize a new fun project install Install dependencies which are described in fun.yml build Build the dependencies local Run your serverless application locally edge Run your serverless application at edge validate Validate a fun template deploy Deploy a fun application nas Operate NAS file system package Package a Function Compute application invoke Remote invoke function help [command] display help for command 123456789101112131415161718192021222324 #init shell复制 ❯ fun init --help Usage: fun init [options] [template] Initialize a new project based on a template. A template can be a folder containing template metadata and boilerplate files, a name of a pre-built template, or a url that resolves to a template. You can find more information about template at https://yq.aliyun.com/articles/674364. Options: -o, --output-dir [path] Where to output the initialized app into (default: ".") -n, --name [name] The name of your project to be generated as a folder (default: "") -m, --merge [merge] Merge into the template.[yml|yaml] file if it already exist (default: false) --no-input Disable prompting and accept default values defined template config -V, --var [vars] Template variable -h, --help display help for command Examples: $ fun init $ fun init event-nodejs8 $ fun init foo/bar $ fun init gh:foo/bar $ fun init gl:foo/bar $ fun init bb:foo/bar $ fun init github:foo/bar $ fun init gitlab:foo/bar $ fun init bitbucket:foo/bar $ fun init git+ssh://git@github.com/foo/bar.git $ fun init hg+ssh://hg@bitbucket.org/bar/foo $ fun init git@github.com:foo/bar.git $ fun init https://github.com/foo/bar.git $ fun init /path/foo/bar $ fun init -n fun-app -V foo=bar /path/foo/bar 123456789101112131415161718192021222324252627282930 直接使用fun init可以选择默认官方文档,也可直接指定在线模板地址,以express为例如下所示:更多使用方式在新窗口打开 shell复制 fun init -n express-fc https://github.com/awesome-fc/fc-express-nodejs8 # Or fun init -n express-fc gh:awesome-fc/fc-express-nodejs8 123 #install 安装第三方依赖,更多信息查看官方文档在新窗口打开 shell复制 ❯ fun install -h Usage: fun install [-f|--function <[service/]function>] [-r|--runtime <runtime>] [-p|--package-type <type>] [--save] [-e|--env key=val ...] [packageNames...] install dependencies which are described in fun.yml file. Options: -f, --function <[service/]function> Specify which function to execute installation task. -e, --env <env> environment variable, ex. -e PATH=/code/bin (default: []) -d, --use-docker Use docker container to install function dependencies -b, --use-buildkit Use buildkit to build functions -r, --runtime <runtime> function runtime, avaliable choice is: nodejs6, nodejs8, nodejs10, nodejs12, python2.7, python3, java8, java11, php7.2, dotnetcore2.1, custom, custom-container -p, --package-type <type> avaliable package type option: pip, apt, npm. --save add task to fun.yml file. --registry <npm-url> Configure npm to use any compatible registry, and even run your own registry. --index-url <pip-url> Base URL of Python Package Index (default https://pypi.org/simple). This should point to a repository compliant with PEP 503 (the simple repository API) or a local directory laid out in the same format. -h, --help display help for command Commands: init initialize fun.yml file. env print environment varables. sbox [options] Start a local sandbox for installation dependencies or configuration 123456789101112131415161718192021222324 如果存在Funfile文件,将会按照Funfile文件中的步骤依次执行命令 shell复制 ❯ fun install using template: template.yml start installing function dependencies without docker building custom-fastify/custom-fastify Funfile exist, Fun will use container to build forcely Step 1/3 : FROM registry.cn-beijing.aliyuncs.com/aliyunfc/runtime-custom:build-1.9.17 as custom ---> e6282033ae8d Step 2/3 : COPY ./package.json . ---> Using cache ---> d7ec10d6d715 Step 3/3 : RUN npm install ---> Using cache ---> b3e13efbe135 sha256:******************************************* 123456789101112131415 #local 需要开启docker服务 shell复制 ❯ fun local --help Usage: fun local [options] [command] Run your serverless application locally for quick development & testing. Options: -h, --help display help for command Commands: invoke Invoke a function locally once start Runs your HttpTriggers and APIs locally help [command] display help for command 123456789101112 #build 将源码构建成交付产物,构建过程中会优先执行Funfile文件中的步骤,构建完成后,将会在根目录下创建一个.fun文件夹,更多信息请访问官方文档在新窗口打开,我们可以通过Funfile结合.funignore来指定要提交到函数计算的文件以及如何编译,例如:(将一个typescript项目进行打包部署) .funignore shell复制 # Funcraft template.yml .env .fun src test .vscode .idea node_modules 123456789 Funfile 复制package.json,接着执行依赖安装npm install,复制src目录和tsconfig.json文件,接着执行build命令 shell复制 RUNTIME custom COPY ./package.json . RUN npm install COPY ./src ./src COPY ./tsconfig.json . RUN npm run build 123456 bootstrap 该文件用于指明函数计算中函数的入口如何执行 shell复制 #!/usr/bin/env bash export PORT=9000 npm run start 123 #deploy fun deploy将会将build构建后的代码.fun/build/artifacts/{projectName}/{projectName}下的内容部署到阿里云函数计算,更多内容在新窗口打开 shell复制 ❯ fun deploy using template: .fun\build\artifacts\template.yml (node:112168) Warning: Accessing non-existent property 'validateParameters' of module exports inside circular dependency (Use `node --trace-warnings ...` to show where the warning was created) using region: cn-shanghai using accountId: ***********9600 using accessKeyId: ***********GHex using timeout: 120 Collecting your services information, in order to caculate devlopment changes... Resources Changes(Beta version! Only FC resources changes will be displayed): ┌────────────────┬──────────────────────────────┬────────┬─────────────┐ │ Resource │ ResourceType │ Action │ Property │ ├────────────────┼──────────────────────────────┼────────┼─────────────┤ │ custom-fastify │ Aliyun::Serverless::Service │ Add │ Description │ ├────────────────┼──────────────────────────────┼────────┼─────────────┤ │ │ │ │ Handler │ │ │ │ ├─────────────┤ │ │ │ │ Runtime │ │ custom-fastify │ Aliyun::Serverless::Function │ Add ├─────────────┤ │ │ │ │ MemorySize │ │ │ │ ├─────────────┤ │ │ │ │ CodeUri │ ├────────────────┼──────────────────────────────┼────────┼─────────────┤ │ │ │ │ AuthType │ │ httpTrigger │ HTTP │ Add ├─────────────┤ │ │ │ │ Methods │ └────────────────┴──────────────────────────────┴────────┴─────────────┘ ? Please confirm to continue. (Y/n) 1234567891011121314151617181920212223242526272829303132 #相关文件 主要又template.yml、Funfile、.funignore、bootstrap、.env文件 #template.yml 用来描述serverless应用,具体内容请访问template.yml在新窗口打开 #Funfile 使用Funfile文件安装第三方依赖(推荐),Dockerfile支持的命令,例如COPY、RUN、ENV、USER和WORKDIR等,Funfile也同样支持,通过Funfile我们可以进行依赖安装、项目测试、项目打包等一系列操作,Funfile会影响fun install和fun build命令,更多内容请访问官方文档在新窗口打开,例如: shell复制 RUNTIME custom COPY ./package.json . RUN npm install 123 #.funignore 在 template.yml 所在的目录放置一个 .funignore 文件,打包 zip 文件的时候可以排除掉 .funignore 内描述的文件或者文件夹。.funignore会影响fun build命令,例如: shell复制 # Logs logs/ *.log # Dependency directories node_modules/ !bb/node_modules 1234567 打包时会忽略 logs/ 目录 、*.log 文件。所有层级的 node_modules/ 目录会被忽略,但是 bb/node_modules 会被保留。.funignore 遵从 .gitignore 的语法。 #bootstrap 使用Custom Runtime运行环境时,会默认调用bootstrap文件启动自定义的HTTP Server,更多内容请访问bootstrap在新窗口打开,例如: shell复制 #!/usr/bin/env bash export PORT=9000 npm run start 123 #.env ini复制 ACCOUNT_ID=xxxxxxxx REGION=cn-shanghai ACCESS_KEY_ID=xxxxxxxxxxxx ACCESS_KEY_SECRET=xxxxxxxxxx FC_ENDPOINT=https://{accountid}.{region}.fc.aliyuncs.com TIMEOUT=10 RETRIES=3 1234567
2021年07月27日
186 阅读
0 评论
0 点赞
2021-07-27
为什么使用Serverless?
购买了服务器之后,在部署项目之前,需要考虑如何来进行安全设置,比如安全组策略、服务器补丁等,防止部署项目之后,服务器出现被注入木马等安全漏洞问题,我之前就因为忽略了示警短信和邮件,导致服务器被注入了木马挖矿程序,虽然最终花费了两天解决掉问题,但因为我无法知道是哪里出的问题,最终只能重装系统和部署项目,这次不友好经历,让不擅长运维的我开始思索,部署项目到服务器对我来说是否值得? 在没有出现安全漏洞问题之前,以为运维就是在系统上点击几下,当真的出现了木马,发现需要进入系统仔细排查,比如占用资源较高的进程、定时任务等等,是极其消耗精力的,更重要的是无法确定原因,通过购买云安全产品,能有效防止这一问题,此外,近几年出现的Serverless架构能够从根本上解决运维问题 无服务器运算(Serverless computing),又被称为功能即服务(Function-as-a-Service,缩写为 FaaS),是云端运算的一种模型。以平台即服务(PaaS)为基础,无服务器运算提供一个微型的架构,终端客户不需要部署、配置或管理服务器服务,程序代码运行所需要的服务器服务皆由云端平台来提供。由于Serverless降低人工成本、降低风险、降低资源投入成本、提高扩展性、减少交付周期的五大优势,让Serverless更加炙手可热 函数计算FC(Function Compute),是阿里云对Serverless架构的一种实现,我们能够节省服务器费用,降低成本,将程序代码部署到云上,无需服务器运维工作,极大的方便了许多中小企业和个人开发者,让我们能够更加专注于业务代码
2021年07月27日
94 阅读
0 评论
0 点赞