Skip to content

Commit ddca862

Browse files
authored
Merge pull request #604 from grego952/add-api-go-folder
Add api-postgres-go and delete api-mssql-go
2 parents feccd3b + 967d821 commit ddca862

43 files changed

Lines changed: 146 additions & 329 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,8 +91,8 @@ Running various samples requires access to the Kyma environment. There are also
9191

9292
| Name | Description | References |
9393
| ------------------------------------------------------------------------- | ----------------------------------------------------------------------------------------------------------- | ------------------------------------------------------------------------------ |
94+
| [Deploy a Go PostgreSQL API Endpoint in SAP BTP, Kyma Runtime](./api-postgresql-go/README.md) | This sample provides a Golang API endpoint for communication with an MS SQL database | [Tutorial](https://developers.sap.com/tutorials/cp-kyma-api-mssql-golang.html) |
9495
| [Use and Seed SAP BTP PostgreSQL in SAP BTP, Kyma Runtime](./database-postgres/README.md) | This sample demonstrates how to containerize and deploy an MS SQL database | [Tutorial](https://developers.sap.com/tutorials/cp-kyma-mssql-deployment.html) |
95-
| [Golang MS SQL database API](./api-mssql-go/README.md) | This sample provides a Golang API endpoint for communication with an MS SQL database | [Tutorial](https://developers.sap.com/tutorials/cp-kyma-api-mssql-golang.html) |
9696

9797
## Advanced Scenarios
9898

api-mssql-go/README.md

Lines changed: 0 additions & 178 deletions
This file was deleted.

api-mssql-go/k8s/configmap.yaml

Lines changed: 0 additions & 10 deletions
This file was deleted.

api-mssql-go/k8s/deployment-servicebinding.yaml

Lines changed: 0 additions & 56 deletions
This file was deleted.

api-mssql-go/k8s/secret.yaml

Lines changed: 0 additions & 11 deletions
This file was deleted.

api-postgresql-go/README.md

Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
# Deploy a Go PostgreSQL API Endpoint in SAP BTP, Kyma Runtime
2+
3+
## Overview
4+
5+
> [!NOTE]
6+
> This sample is used in the Deploy a Go PostgreSQL API Endpoint in SAP BTP, Kyma Runtime tutorial.
7+
8+
This sample provides a Golang API endpoint for communication with PostgreSQL databases. The API connects to a BTP-managed PostgreSQL instance using Service Binding credentials available in the Kyma cluster.
9+
10+
## PostgreSQL Database Example
11+
12+
For the PostgreSQL example, use the `deployment.yaml` file. It provides the Deployment definition as well as an APIRule to expose the API without authentication. The Deployment references the PostgreSQL Service Binding Secret for connection credentials.
13+
14+
This sample demonstrates how to:
15+
16+
- Create a development namespace in the Kyma runtime.
17+
- Deploy the following Kubernetes resources:
18+
- API deployment written in GO
19+
- API Rule
20+
- Service
21+
- ConfigMap
22+
23+
## Prerequisites
24+
25+
- SAP BTP, Kyma runtime instance
26+
- PostgreSQL Service Instance and Service Binding in the Kyma cluster
27+
- [Docker](https://www.docker.com/)
28+
- [Go](https://golang.org/doc/install)
29+
- [kubectl](https://kubernetes.io/docs/tasks/tools/install-kubectl/) configured to use the `KUBECONFIG` file downloaded from the Kyma runtime
30+
31+
## Procedure
32+
33+
### Build the Docker Image
34+
35+
1. Build and push the image to your Docker repository:
36+
37+
```shell script
38+
docker build -t {your-docker-account}/api-postgresql-go -f docker/Dockerfile .
39+
docker push {your-docker-account}/api-postgresql-go
40+
```
41+
42+
### Deploy the API
43+
44+
1. Create a new `dev` namespace:
45+
46+
```shell script
47+
kubectl create namespace dev
48+
kubectl label namespaces dev istio-injection=enabled
49+
```
50+
51+
2. Apply the ConfigMap:
52+
53+
```shell script
54+
kubectl -n dev apply -f ./k8s/configmap.yaml
55+
```
56+
57+
3. Apply the Deployment:
58+
59+
```shell script
60+
kubectl -n dev apply -f ./k8s/deployment.yaml
61+
```
62+
63+
4. Apply the APIRule:
64+
65+
```shell script
66+
kubectl -n dev apply -f ./k8s/apirule.yaml
67+
```
68+
69+
5. Verify that the Deployment is up and running:
70+
71+
```shell script
72+
kubectl -n dev get deployment api-postgresql-go
73+
```
74+
75+
6. Use the APIRule:
76+
77+
- `https://api-postgresql-go.{cluster-domain}/orders`
78+
- `https://api-postgresql-go.{cluster-domain}/orders/10000001`
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import (
66

77
"github.com/gorilla/mux"
88

9-
"github.com/SAP-samples/kyma-runtime-extension-samples/api-mssql-go/internal/api"
9+
"github.com/SAP-samples/kyma-runtime-extension-samples/api-postgresql-go/internal/api"
1010
)
1111

1212
func main() {
Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
FROM golang:1.14 as builder
1+
FROM golang:1.21 as builder
22

33
ENV GO111MODULE=on
44

@@ -12,11 +12,11 @@ COPY cmd ./cmd
1212
COPY internal ./internal
1313

1414
RUN ls /app/
15-
RUN CGO_ENABLED=0 GOOS=linux go build -v -a -o api-mssql-go ./cmd/api
15+
RUN CGO_ENABLED=0 GOOS=linux go build -v -a -o api-postgresql-go ./cmd/api
1616

1717
FROM scratch
1818
WORKDIR /app
19-
COPY --from=builder /app/api-mssql-go /app/
19+
COPY --from=builder /app/api-postgresql-go /app/
2020

2121
EXPOSE 8000
22-
ENTRYPOINT ["/app/api-mssql-go"]
22+
ENTRYPOINT ["/app/api-postgresql-go"]
Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,9 @@
1-
module github.com/SAP-samples/kyma-runtime-extension-samples/api-mssql-go
1+
module github.com/SAP-samples/kyma-runtime-extension-samples/api-postgresql-go
22

33
go 1.14
44

55
require (
6-
github.com/denisenkom/go-mssqldb v0.0.0-20200910202707-1e08a3fab204
76
github.com/gorilla/mux v1.8.0
7+
github.com/lib/pq v1.10.9
88
github.com/vrischmann/envconfig v1.3.0
9-
golang.org/x/crypto v0.0.0-20200622213623-75b288015ac9 // indirect
109
)

0 commit comments

Comments
 (0)