云引擎 Go 运行环境
信息
这篇文档是针对 Go 运行环境的深入介绍,如希望快速地开始使用云引擎,请查看 快速开始部署云引擎应用。
云引擎目前只支持通过 Go Modules 管理依赖的项目。
所有 Go 项目都必须在根目录下包含一个 go.mod
文件才会被云引擎正确识别。
构建和启动命令
云引擎默认使用 go build -o main
进行构建,然后执行构建出的可执行文件(main
),你可以在 leanengine.yaml
中来自定义构建和启动命令:
leanengine.yaml
build: go build -o myapp
run: ./myapp
配置 Go 版本
云引擎会从 go.mod
中读取 Go 的版本:
go.mod
go 1.14
备注
如未设置 Go 版本,云引擎会默认使用最新的稳定版本。
安装依赖(go.mod
)
云引擎会 自动安装 go.mod
和 go.sum
中列出的依赖。
自定义构建过程
除了默认的构建过程和运行命令外,开发者还可以在 leanengine.yaml
中进一步地调整运行命令(run
)、依赖安装命令(install
)和构建命令(build
),覆盖默认的行为:
leanengine.yaml
run: echo 'run another command'
install:
- {use: 'default'}
- echo 'install additional dependencies here'
build:
- echo 'overwrite default build command here'
详细的说明见 Reference: leanengine.yaml
。系统级依赖
在云引擎的线上环境中,开发者可以在 leanengine.yaml
中定义额外的系统级依赖:
leanengine.yaml
systemDependencies:
- imagemagick
支持的完整列表见 Reference: leanengine.yaml。
构建日志
默认情况下构建过程中产生的日志不会显示到控制台,只有构建失败时,最后一个步骤的日志才会被显示在控制台上。
如需打印完整的构建日志以便调试,可以在部署时勾选「打印构建日志」或命令行工具添加参数 --options 'printBuildLogs=true'
。