This topic describes how to deploy a Beego application to Function Compute. Compared with traditional deployment methods, you can skip the steps such as purchasing a machine and deploy the traditional Beego application to the remote end for production directly with one click. In addition, you have the auto scaling, pay-as-you-go, and maintenance-free features offered.

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 with some features of Go, such as Interface and Struct, combined.

Step 1: Prepare the environment

You only need to install Funcraft instead of installing Docker. The simplest method is to download the executable binary files.

  1. Install Funcraft on the local machine. For more information, see Install Funcraft.
  2. Run the fun --version command to check whether the installation is successful.

Step 2: Deploy an application

  1. Run the following command to install Beego. For more information, see official example.
    go get github.com/astaxie/beego                    
  2. Run the following command to create a hello.go project.
    package main
    import "github.com/astaxie/beego"
    func main(){
        beego.Run()
    }                    
  3. Use the following command to run the local project.
    go run hello.go                    
  4. Run the fun deploy -y command to deploy the project to Function Compute.
    $fun deploy -y
    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 to Port 0.0.0.0:9000. In the deployment log, Funcraft attempts to detect the start port of the application. If the ports do not match, press enter to modify the port, and 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. bootstrap file and template.yml file, and finally automatic deployment.

    After the deployment is successful, you can see the temporary domain name generated by Function Compute in the log. Through this temporary domain name, you can directly access the just deployed application.

    Note The temporary domain name is only used for demonstration and development and is only valid for a period. For production purposes, bind a domain name that has been filed with Alibaba Cloud.