zoukankan      html  css  js  c++  java
  • 在 SAP Kyma 上部署一个 Go MSSQL API Endpoint

    链接:https://developers.sap.com/tutorials/cp-kyma-api-mssql-golang.html

    本地文件:C:Code eferenceCodeSAP Kyma教程例子api-mssql-go

    main.go

    go 应用的入口:

    dockerfile

    该 dockerfile 定义了两个阶段来构造 docker 镜像文件。

    (1)In the first stage, a Go image is used. It copies the related content of the project into the image and builds the application.

    (2)The built application is then copied into the Docker scratch image and exposed on port 8000. The scratch image is an empty image containing no other tools within it so obtaining a shell/bash session is not possible.

    FROM scratch
    WORKDIR /app
    COPY --from=builder /app/api-mssql-go /app/
    

    如果上面三行代码删除,对最后构建好的 docker 镜像文件的影响就是,尺寸会比不注释后的镜像文件尺寸大。这三行代码的作用是,从一个空的 scratch 镜像开始构建,仅将之前 go 镜像 /app/api-mssql-go 文件夹拷贝到新镜像的 app 目录,这样尺寸大大减小。

    apirule:

    从上图可以看到,这个 GO MSSQL API endpoint,支持对订单的增删改查。

    本地运行 go 应用:

    go run ./cmd/api/main.go

    本地 endpoint 如下:

    http://localhost:8000/orders

    读取订单:curl -i -H "Accept: application/json" -H "Content-Type: application/json" -X GET http://localhost:8000/orders

    创建订单:curl --data "{"order_id":"10000003","description":"test from curl"}" http://localhost:8000/orders

    进入 api-mssql-go 文件夹,构建 docker 镜像:

    docker build -t i042416/api-mssql-go -f docker/Dockerfile .

    上传镜像:
    docker push /api-mssql-go

    本地启动镜像:

    docker run -p 8000:8000  --name api-mssql-go 
    -e MYAPP_username="sa" 
    -e MYAPP_password="Yukon900" 
    -e MYAPP_database="DemoDB" 
    -e MYAPP_host="host.docker.internal" 
    -e MYAPP_port="1433" 
    -d <your-docker-id>/api-mssql-go:latest
    
    

    最后,把 k8s 文件夹下所有 yaml 文件,部署到 SAP Kyma 即可。

    更多Jerry的原创文章,尽在:"汪子熙":

  • 相关阅读:
    java注解
    Mac窗口管理管理软件SizeUp
    mac下8080端口到80端口的转发
    mac svn的替代品CornerStone
    模板模式讲解二
    数组和集合List的相互转化
    fastjson使用示例
    模板模式讲解一
    mybatis-generator-core自动生成do、mapping、dao 代码
    maven依赖传递关系
  • 原文地址:https://www.cnblogs.com/sap-jerry/p/14889302.html
Copyright © 2011-2022 走看看