This topic describes how to deploy a Beego application to Function Compute. Function
Compute provides a method different from traditional deployment methods. You can deploy
a traditional Beego application to Function Compute and use the application for production
without performing steps such as purchasing a machine. Your Beego application can
use the auto-scaling, pay-as-you-go, and O&M-free features of Function Compute.
Background information
Beego is an HTTP framework that is used to quickly develop Go applications. It is
a RESTful framework used to quickly develop various applications, such as APIs and
web applications and backend services. Beego is mainly inspired by Tornado, Sinatra,
and Flask and integrated with some features of Go, such as Interface and Struct.
Step 1: Prepare the environment
You do not need to install Docker but only Funcraft. The easiest way to install Funcraft
is to download the executable binary files.
- Install Funcraft. For more information, see Install Funcraft.
- Run the
fun --version
command to check whether the installation is successful.
- Configure Funcraft. For more information, see Configure Funcraft.
Step 2: Migrate the application
- Run the following command to install Beego. For more information, see Documentation.
go get github.com/astaxie/beego
- Run the following command to create a
hello.go
project.package main
import "github.com/astaxie/beego"
func main(){
beego.Run()
}
- Run the following command to run the on-premises application:
- Run the
fun deploy -y
command to deploy the application to Function Compute.fun deploy -y
A similar output is displayed.
current folder is not a fun project.
Fun detected your application doesn't listen on '0.0.0.0:9000' in hello.go
Fun will replace your addr to '0.0.0.0:9000', and also backup your origin file hello.go to hello.go.bak
? Are your sure? Yes
Could not find any bin files from current folder.
Before using 'fun deploy', you must use 'GOARCH=amd64 GOOS=linux go build -ldflags "-s -w"' to compile your project.
? Let Fun exec this command for you? Yes
Executing command 'GOARCH=amd64 GOOS=linux go build -ldflags "-s -w"'...
Tips:
You must use 'GOARCH=amd64 GOOS=linux go build -ldflags "-s -w"' to recompile your project every time before using fun deploy.
Generating template.yml...
Generate Fun project successfully!
========= Fun will use 'fun deploy' to deploy your application to Function Compute! =========
... ..... .....
trigger httpTrigger deploy success
function express deploy success
service express deploy success
Detect 'DomainName:Auto' of custom domain 'Domain'
Fun will reuse the temporary domain 15014775-XXX.test.functioncompute.com, expired at 2020-04-03 09:52:55, limited by 1000 per day.
Waiting for custom domain Domain to be deployed...
custom domain Domain deploy success
Function Compute must start the service and listen on the 0.0.0.0:9000 port. For more
information, see
Overview. The deployment log indicates that Funcraft attempts to detect the startup port of
the application. If the ports do not match, press Enter to modify the port. Then,
Funcraft automatically detects the executable program generated by the build. If no
executable program is detected, you are prompted to compile with the specified command.
Funcraft will compile the code after you press Enter. The
bootstrap file and
template.yml file are automatically generated and deployed.
After the project is deployed, check the log to find the temporary domain name that
Function Compute generated. You can use this temporary domain name to access the deployed
application.
Note The temporary domain name is used only for demonstration and development purposes.
It is valid for a limited period of time. To use an application in a production environment,
you must bind the application to a domain name that has obtained an Internet Content
Provider (ICP) filing from Alibaba Cloud. For more information, see
Bind a custom domain name.