Skip to content

Commit 3244ee9

Browse files
committed
Added the draw.io file and adjusted the readme
1 parent c4f024b commit 3244ee9

File tree

5 files changed

+768
-8
lines changed

5 files changed

+768
-8
lines changed

cos-to-sql/README.md

Lines changed: 28 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22

33
This sample demonstrates how to read CSV files hosted on a IBM Cloud Object Storage and save their contents line by line into relational PostgreSQL database.
44

5+
![Architecture overview](./docs/trusted-profiles-part2-arch-overview.png)
6+
57
## Prerequisites
68

79
Make sure the following [IBM Cloud CLI](https://cloud.ibm.com/docs/cli/reference/ibmcloud?topic=cloud-cli-getting-started) and the following list of plugins are installed
@@ -23,7 +25,7 @@ ibmcloud login -r ${REGION} -g $RESOURCE_GROUP
2325
* Create the Code Engine project
2426
```
2527
export CE_INSTANCE_NAME=cos-to-sql--ce
26-
ibmcloud code-engine project create -n ${CE_INSTANCE_NAME}
28+
ibmcloud code-engine project create --name ${CE_INSTANCE_NAME}
2729
2830
export CE_INSTANCE_GUID=$(ibmcloud ce project current -o json | jq -r .guid)
2931
export CE_INSTANCE_ID=$(ibmcloud resource service-instance ${CE_INSTANCE_NAME} --output json | jq -r '.[0] | .id')
@@ -93,7 +95,10 @@ ibmcloud iam authorization-policy-create secrets-manager databases-for-postgresq
9395
* Create the service credential to access the PostgreSQL instance
9496
```
9597
SM_SECRET_FOR_PG_NAME=pg-access-credentials
96-
ibmcloud secrets-manager secret-create --secret-type="service_credentials" --secret-name="$SM_SECRET_FOR_PG_NAME" --secret-source-service="{\"instance\": {\"crn\": \"$DB_INSTANCE_ID\"},\"parameters\": {},\"role\": {\"crn\": \"crn:v1:bluemix:public:iam::::serviceRole:Writer\"}}"
98+
ibmcloud secrets-manager secret-create \
99+
--secret-type="service_credentials" \
100+
--secret-name="$SM_SECRET_FOR_PG_NAME" \
101+
--secret-source-service="{\"instance\": {\"crn\": \"$DB_INSTANCE_ID\"},\"parameters\": {},\"role\": {\"crn\": \"crn:v1:bluemix:public:iam::::serviceRole:Writer\"}}"
97102
98103
export SM_SECRET_FOR_PG_ID=$(ibmcloud sm secret-by-name --name $SM_SECRET_FOR_PG_NAME --secret-type service_credentials --secret-group-name default --output JSON|jq -r '.id')
99104
```
@@ -126,16 +131,32 @@ ibmcloud code-engine app create \
126131
* Create a trusted profile that grants a Code Engine app access to your COS bucket
127132
```
128133
ibmcloud iam trusted-profile-create ${TRUSTED_PROFILE_FOR_COS_NAME}
129-
ibmcloud iam trusted-profile-link-create ${TRUSTED_PROFILE_FOR_COS_NAME} --name ce-app-${CE_APP_NAME} --cr-type CE --link-crn ${CE_INSTANCE_ID} --link-component-type application --link-component-name ${CE_APP_NAME}
130-
ibmcloud iam trusted-profile-policy-create ${TRUSTED_PROFILE_FOR_COS_NAME} --roles "Content Reader" --service-name cloud-object-storage --service-instance ${COS_INSTANCE_ID} --resource-type bucket --resource ${COS_BUCKET_NAME}
134+
ibmcloud iam trusted-profile-link-create ${TRUSTED_PROFILE_FOR_COS_NAME} \
135+
--name ce-app-${CE_APP_NAME} \
136+
--cr-type CE --link-crn ${CE_INSTANCE_ID} \
137+
--link-component-type application \
138+
--link-component-name ${CE_APP_NAME}
139+
ibmcloud iam trusted-profile-policy-create ${TRUSTED_PROFILE_FOR_COS_NAME} \
140+
--roles "Content Reader" \
141+
--service-name cloud-object-storage \
142+
--service-instance ${COS_INSTANCE_ID} \
143+
--resource-type bucket \
144+
--resource ${COS_BUCKET_NAME}
131145
```
132146

133147

134148
* Create the trusted profile to access Secrets Manager
135149
```
136150
ibmcloud iam trusted-profile-create ${TRUSTED_PROFILE_FOR_SM_NAME}
137-
ibmcloud iam trusted-profile-link-create ${TRUSTED_PROFILE_FOR_SM_NAME} --name ce-app-${CE_APP_NAME} --cr-type CE --link-crn ${CE_INSTANCE_ID} --link-component-type application --link-component-name ${CE_APP_NAME}
138-
ibmcloud iam trusted-profile-policy-create ${TRUSTED_PROFILE_FOR_SM_NAME} --roles "SecretsReader" --service-name secrets-manager --service-instance ${SM_INSTANCE_ID}
151+
ibmcloud iam trusted-profile-link-create ${TRUSTED_PROFILE_FOR_SM_NAME} \
152+
--name ce-app-${CE_APP_NAME} \
153+
--cr-type CE --link-crn ${CE_INSTANCE_ID} \
154+
--link-component-type application \
155+
--link-component-name ${CE_APP_NAME}
156+
ibmcloud iam trusted-profile-policy-create ${TRUSTED_PROFILE_FOR_SM_NAME} \
157+
--roles "SecretsReader" \
158+
--service-name secrets-manager \
159+
--service-instance ${SM_INSTANCE_ID}
139160
```
140161

141162
## Setting up eventing
@@ -153,6 +174,7 @@ ibmcloud iam authorization-policy-create codeengine cloud-object-storage \
153174
ibmcloud ce sub cos create \
154175
--name "coswatch-${CE_APP_NAME}" \
155176
--bucket ${COS_BUCKET_NAME} \
177+
--event-type "write" \
156178
--destination ${CE_APP_NAME} \
157179
--destination-type app \
158180
--path /cos-to-sql

cos-to-sql/build

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
#!/bin/bash
2+
3+
# Env Vars:
4+
# REGISTRY: name of the image registry/namespace to store the images
5+
# NOCACHE: set this to "--no-cache" to turn off the Docker build cache
6+
#
7+
# NOTE: to run this you MUST set the REGISTRY environment variable to
8+
# your own image registry/namespace otherwise the `docker push` commands
9+
# will fail due to an auth failure. Which means, you also need to be logged
10+
# into that registry before you run it.
11+
12+
set -ex
13+
export REGISTRY=${REGISTRY:-icr.io/codeengine}
14+
15+
# Build the image
16+
docker build ${NOCACHE} -t ${REGISTRY}/cos-to-sql . --platform linux/amd64
17+
18+
# And push it
19+
docker push ${REGISTRY}/cos-to-sql

0 commit comments

Comments
 (0)