You can migrate web projects in C++ by using the Custom Runtime and HTTP triggers of Function Compute. You can access a function by using a browser or HTTP client tools such as cURL.

Prerequisites

Before you begin, make sure that you have completed the following operations:
  • Install Node.js 8.6.0 or later. For more information, visit Downloads.
  • Install Docker. For more information, visit Docker Hub.
Note The examples in this topic apply to scenarios where Docker is installed. If you do not want to use Docker, you must install .NET Core 3.1. For more information about how to install .NET Core 3.1, see dot.net.core3.1. For more information about the commands of .NET Core 3.1, see fc-custom-demo.

Procedure

  1. Run the following command to clone the sample project to the on-premises machine:
    git clone https://github.com/awesome-fc/fc-custom-demo          
    Note If you do not install Git, you can download the sample project from https://github.com/awesome-fc/fc-custom-demo.
  2. Optional:Modify the sample code in the cpp-http-demo directory to implement your business logic.
  3. Run the following command to go to the cloned sample project:
    1. Run the following command to go to the cpp-http-demo directory:
      cd cpp-http-demo
  4. Run the following command to build the bootstrap:
    make deploy
    The following output is returned:
    docker build -t fc-cpp-runtime  -f build-image/Dockerfile build-image
    Sending build context to Docker daemon  2.048kB
    Step 1/3 : FROM aliyunfc/runtime-custom:base
     ---> 5bbdcf6377bd
    ...
    Step 3/3 : RUN apt-get install -y cmake
     ---> Using cache
     ---> a244cd26cec2
    Successfully built a244cd26cec2
    Successfully tagged fc-cpp-runtime:latest
    docker run --rm -it -v $(pwd):/tmp fc-cpp-runtime bash -c "cd /tmp && ./build.sh"
    -- The C compiler identification is GNU 6.3.0
    -- The CXX compiler identification is GNU 6.3.0
    -- Check for working C compiler: /usr/bin/cc
    -- Check for working C compiler: /usr/bin/cc -- works
    ...
    Scanning dependencies of target cppruntime
    [ 33%] Building CXX object CMakeFiles/cppruntime.dir/src/handler.cpp.o
    [ 66%] Building CXX object CMakeFiles/cppruntime.dir/src/logging.cpp.o
    [100%] Linking CXX shared library /tmp/bin/libcppruntime.so
    ...
    -- Build files have been written to: /tmp/sample/release
    ...
    [100%] Built target bootstrap
  5. Run the following command to deploy the project to Function Compute:
    fun deploy -y
    The following output is returned:
    Waiting for service cpp_http_demo to be deployed...
            Waiting for function fc_cpp_http to be deployed...
                    Waiting for packaging function fc_cpp_http code...
                    The function fc_cpp_http has been packaged. A total of 2 files were compressed and the final size was 446.37 KB
                    Waiting for HTTP trigger http_t to be deployed...
                    triggerName: http_t
                    methods: [ 'GET', 'POST', 'PUT', 'DELETE' ]
                    trigger http_t deploy success
            function fc_cpp_http deploy success
    service cpp_http_demo deploy success
    
    Detect 'DomainName:Auto' of custom domain 'my_domain'
    The assigned temporary domain is http://********-****************.test.functioncompute.com, expired at 2021-04-03 15:07:42, limited by 1000 per day.
    
    Waiting for custom domain my_domain to be deployed...
    custom domain my_domain deploy success
  6. Run the following command to invoke the deployed function:
    Notice
    • http://********-*********.test.functioncompute.com can be obtained from the output of Step 5.
    • If you use the Windows operating system, you must convert the format of the bootstrap file to UNIX.
    curl http://********-****************.test.functioncompute.com -d "Hello World"
    The following output is returned:
    Hello World