在 SAP Kyma 上部署一个 Go MSSQL API Endpoint
鏈接:https://developers.sap.com/tutorials/cp-kyma-api-mssql-golang.html
本地文件:C:\Code\referenceCode\SAP Kyma教程例子\api-mssql-go
main.go
go 應(yīng)用的入口:
dockerfile
該 dockerfile 定義了兩個(gè)階段來(lái)構(gòu)造 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/如果上面三行代碼刪除,對(duì)最后構(gòu)建好的 docker 鏡像文件的影響就是,尺寸會(huì)比不注釋后的鏡像文件尺寸大。這三行代碼的作用是,從一個(gè)空的 scratch 鏡像開(kāi)始構(gòu)建,僅將之前 go 鏡像 /app/api-mssql-go 文件夾拷貝到新鏡像的 app 目錄,這樣尺寸大大減小。
apirule:
從上圖可以看到,這個(gè) GO MSSQL API endpoint,支持對(duì)訂單的增刪改查。
本地運(yùn)行 go 應(yīng)用:
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
創(chuàng)建訂單:curl --data “{“order_id”:“10000003”,“description”:“test from curl”}” http://localhost:8000/orders
進(jìn)入 api-mssql-go 文件夾,構(gòu)建 docker 鏡像:
docker build -t i042416/api-mssql-go -f docker/Dockerfile .
上傳鏡像:
docker push /api-mssql-go
本地啟動(dòng)鏡像:
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的原創(chuàng)文章,盡在:“汪子熙”:
總結(jié)
以上是生活随笔為你收集整理的在 SAP Kyma 上部署一个 Go MSSQL API Endpoint的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問(wèn)題。
- 上一篇: 在 SAP Kyma 上使用 Redis
- 下一篇: 使用 SAP CDS view SQL