Skip to content
Merged
Show file tree
Hide file tree
Changes from 10 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ Running various samples requires access to the Kyma environment. There are also
| Name | Description | References |
| ------------------------------------------------------------------------- | ----------------------------------------------------------------------------------------------------------- | ------------------------------------------------------------------------------ |
| [MS SQL database](./database-mssql/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) |
| [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) |
| [Golang MS SQL database API](./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) |
Comment thread
grego952 marked this conversation as resolved.
Outdated

## Advanced Scenarios

Expand Down
178 changes: 0 additions & 178 deletions api-mssql-go/README.md

This file was deleted.

10 changes: 0 additions & 10 deletions api-mssql-go/k8s/configmap.yaml

This file was deleted.

56 changes: 0 additions & 56 deletions api-mssql-go/k8s/deployment-servicebinding.yaml

This file was deleted.

11 changes: 0 additions & 11 deletions api-mssql-go/k8s/secret.yaml

This file was deleted.

78 changes: 78 additions & 0 deletions api-postgresql-go/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
# Golang PostgreSQL database API
Comment thread
grego952 marked this conversation as resolved.
Outdated

## Overview

> [!NOTE]
> This sample is used in the Deploy a Go PostgreSQL API Endpoint in SAP BTP, Kyma Runtime tutorial.
Comment thread
grego952 marked this conversation as resolved.

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.

## PostgreSQL database example
Comment thread
grego952 marked this conversation as resolved.
Outdated

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.

This sample demonstrates how to:

- Create a development Namespace in the Kyma runtime.
Comment thread
grego952 marked this conversation as resolved.
Outdated
- Deploy the following Kubernetes resources:
- API deployment written in GO
- API Rule
- Service
- ConfigMap

## Prerequisites

- SAP BTP, Kyma runtime instance
- PostgreSQL Service Instance and Service Binding in Kyma cluster
Comment thread
grego952 marked this conversation as resolved.
Outdated
- [Docker](https://www.docker.com/)
- [Go](https://golang.org/doc/install)
- [kubectl](https://kubernetes.io/docs/tasks/tools/install-kubectl/) configured to use the `KUBECONFIG` file downloaded from the Kyma runtime

## Steps
Comment thread
grego952 marked this conversation as resolved.
Outdated

### Build the Docker image
Comment thread
grego952 marked this conversation as resolved.
Outdated

1. Build and push the image to your Docker repository:

```shell script
docker build -t {your-docker-account}/api-postgresql-go -f docker/Dockerfile .
docker push {your-docker-account}/api-postgresql-go
```

### Deploy the API

1. Create a new `dev` Namespace:
Comment thread
grego952 marked this conversation as resolved.
Outdated

```shell script
kubectl create namespace dev
kubectl label namespaces dev istio-injection=enabled
```

2. Apply the ConfigMap:

```shell script
kubectl -n dev apply -f ./k8s/configmap.yaml
```

3. Apply the Deployment:

```shell script
kubectl -n dev apply -f ./k8s/deployment.yaml
```

4. Apply the APIRule:

```shell script
kubectl -n dev apply -f ./k8s/apirule.yaml
```

5. Verify that the Deployment is up and running:

```shell script
kubectl -n dev get deployment api-postgresql-go
```

6. Use the APIRule:

- `https://api-postgresql-go.{cluster-domain}/orders`
- `https://api-postgresql-go.{cluster-domain}/orders/10000001`
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import (

"github.com/gorilla/mux"

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

func main() {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
FROM golang:1.14 as builder
FROM golang:1.21 as builder

ENV GO111MODULE=on

Expand All @@ -12,11 +12,11 @@ COPY cmd ./cmd
COPY internal ./internal

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

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

EXPOSE 8000
ENTRYPOINT ["/app/api-mssql-go"]
ENTRYPOINT ["/app/api-postgresql-go"]
5 changes: 2 additions & 3 deletions api-mssql-go/go.mod → api-postgresql-go/go.mod
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
module github.com/SAP-samples/kyma-runtime-extension-samples/api-mssql-go
module github.com/SAP-samples/kyma-runtime-extension-samples/api-postgresql-go

go 1.14

require (
github.com/denisenkom/go-mssqldb v0.0.0-20200910202707-1e08a3fab204
github.com/gorilla/mux v1.8.0
github.com/lib/pq v1.10.9
github.com/vrischmann/envconfig v1.3.0
golang.org/x/crypto v0.0.0-20200622213623-75b288015ac9 // indirect
)
Loading