Skip to content

Commit 287c26c

Browse files
authored
Update readme (openshift-online#2)
Signed-off-by: clyang82 <[email protected]>
1 parent c3e42b1 commit 287c26c

File tree

2 files changed

+59
-24
lines changed

2 files changed

+59
-24
lines changed

Makefile

+15-12
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,9 @@ image_tag:=$(version)
2121
environment:=${USER}
2222
namespace:=ocm-${USER}
2323

24+
# a tool for managing containers and images, etc. You can set it as docker
25+
container_tool ?= podman
26+
2427
# In the development environment we are pushing the image directly to the image
2528
# registry inside the development cluster. That registry has a different name
2629
# when it is accessed from outside the cluster and when it is accessed from
@@ -77,7 +80,7 @@ help:
7780

7881
# Encourage consistent tool versions
7982
OPENAPI_GENERATOR_VERSION:=5.4.0
80-
GO_VERSION:=go1.21.0
83+
GO_VERSION:=go1.21.
8184

8285
### Constants:
8386
version:=$(shell date +%s)
@@ -185,10 +188,10 @@ test-integration: install
185188
# Regenerate openapi client and models
186189
generate:
187190
rm -rf pkg/api/openapi
188-
podman build -t ams-openapi -f Dockerfile.openapi .
189-
$(eval OPENAPI_IMAGE_ID=`podman create -t ams-openapi -f Dockerfile.openapi .`)
190-
podman cp $(OPENAPI_IMAGE_ID):/local/pkg/api/openapi ./pkg/api/openapi
191-
podman cp $(OPENAPI_IMAGE_ID):/local/data/generated/openapi/openapi.go ./data/generated/openapi/openapi.go
191+
$(container_tool) build -t ams-openapi -f Dockerfile.openapi .
192+
$(eval OPENAPI_IMAGE_ID=`$(container_tool) create -t ams-openapi -f Dockerfile.openapi .`)
193+
$(container_tool) cp $(OPENAPI_IMAGE_ID):/local/pkg/api/openapi ./pkg/api/openapi
194+
$(container_tool) cp $(OPENAPI_IMAGE_ID):/local/data/generated/openapi/openapi.go ./data/generated/openapi/openapi.go
192195
.PHONY: generate
193196

194197
run: install
@@ -259,11 +262,11 @@ project:
259262

260263
.PHONY: image
261264
image: cmds
262-
podman build -t "$(external_image_registry)/$(image_repository):$(image_tag)" .
265+
$(container_tool) build -t "$(external_image_registry)/$(image_repository):$(image_tag)" .
263266

264267
.PHONY: push
265268
push: image
266-
podman push "$(external_image_registry)/$(image_repository):$(image_tag)"
269+
$(container_tool) push "$(external_image_registry)/$(image_repository):$(image_tag)"
267270

268271
deploy-%: project %-template
269272
$(oc) apply --filename="templates/$*-template.json" | egrep --color=auto 'configured|$$'
@@ -303,19 +306,19 @@ undeploy: \
303306

304307
.PHONY: db/setup
305308
db/setup:
306-
podman run --name psql-example -e POSTGRES_DB=$(db_name) -e POSTGRES_USER=$(db_user) -e POSTGRES_PASSWORD=$(db_password) -p $(db_port):5432 -d $(db_image)
309+
$(container_tool) run --name psql-example -e POSTGRES_DB=$(db_name) -e POSTGRES_USER=$(db_user) -e POSTGRES_PASSWORD=$(db_password) -p $(db_port):5432 -d $(db_image)
307310

308311
.PHONY: db/login
309312
db/login:
310-
podman exec -it psql-example bash -c "psql -h localhost -U $(db_user) $(db_name)"
313+
$(container_tool) exec -it psql-example bash -c "psql -h localhost -U $(db_user) $(db_name)"
311314

312315
.PHONY: db/teardown
313316
db/teardown:
314-
podman stop psql-example
315-
podman rm psql-example
317+
$(container_tool) stop psql-example
318+
$(container_tool) rm psql-example
316319

317320
crc/login:
318321
@echo "Logging into CRC"
319322
@crc console --credentials -ojson | jq -r .clusterConfig.adminCredentials.password | oc login --username kubeadmin --insecure-skip-tls-verify=true https://api.crc.testing:6443
320-
@oc whoami --show-token | podman login --username kubeadmin --password-stdin "$(external_image_registry)"
323+
@oc whoami --show-token | $(container_tool) login --username kubeadmin --password-stdin "$(external_image_registry)"
321324
.PHONY: crc/login

README.md

+44-12
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ ocmexample=# \dt
7474
public | dinosaurs | table | ocm_example_service
7575
public | events | table | ocm_example_service
7676
public | migrations | table | ocm_example_service
77-
(2 rows)
77+
(3 rows)
7878

7979

8080
```
@@ -83,43 +83,54 @@ ocmexample=# \dt
8383

8484
```shell
8585

86-
$ make test
87-
$ make test-integration
86+
make test
87+
make test-integration
8888

8989
```
9090

9191
### Running the Service
9292

93-
```
94-
./ocm-example-service serve
93+
```shell
94+
95+
make run
96+
9597
```
9698

9799
To verify that the server is working use the curl command:
98100

99-
$ curl http://localhost:8000//api/ocm-example-service/v1/dinosaurs | jq
101+
```shell
102+
103+
curl http://localhost:8000/api/ocm-example-service/v1/dinosaurs | jq
100104

105+
```
101106

102107
That should return a 401 response like this, because it needs authentication:
103108

104109
```
105110
{
106111
"kind": "Error",
107112
"id": "401",
108-
"href": "//api/ocm-example-service/errors/401",
113+
"href": "/api/ocm-example-service/errors/401",
109114
"code": "API-401",
110115
"reason": "Request doesn't contain the 'Authorization' header or the 'cs_jwt' cookie"
111116
}
112117
```
113118

114119

115120
Authentication in the default configuration is done through the RedHat SSO, so you need to login with a Red Hat customer portal user in the right account (created as part of the onboarding doc) and then you can retrieve the token to use below on https://console.redhat.com/openshift/token
116-
To authenticate, use the ocm tool against your local service:
121+
To authenticate, use the ocm tool against your local service. The ocm tool is available on https://console.redhat.com/openshift/downloads
122+
123+
#### Login to your local service
124+
```
125+
ocm login --token=${OCM_ACCESS_TOKEN} --url=http://localhost:8000
117126
118-
### Get a new Dinosaur
127+
```
128+
129+
#### Get a new Dinosaur
119130
This will be empty if no Dinosaur is ever created
120131

121132
```
122-
(base) ➜ ~ ocm get /api/ocm-example-service/v1/dinosaurs
133+
ocm get /api/ocm-example-service/v1/dinosaurs
123134
{
124135
"items": [],
125136
"kind": "DinosaurList",
@@ -129,10 +140,9 @@ This will be empty if no Dinosaur is ever created
129140
}
130141
```
131142

132-
### Post a new Dinosaur
143+
#### Post a new Dinosaur
133144

134145
```shell
135-
ocm login --token=${OCM_ACCESS_TOKEN} --url=http://localhost:8000
136146

137147
ocm post /api/ocm-example-service/v1/dinosaurs << EOF
138148
{
@@ -142,6 +152,28 @@ EOF
142152

143153
```
144154

155+
#### Get your Dinosaur
156+
157+
```shell
158+
ocm get /api/ocm-example-service/v1/dinosaurs
159+
{
160+
"items": [
161+
{
162+
"created_at":"2023-10-26T08:15:54.509653Z",
163+
"href":"/api/ocm-example-service/v1/dinosaurs/2XIENcJIi9t2eBblhWVCtWLdbDZ",
164+
"id":"2XIENcJIi9t2eBblhWVCtWLdbDZ",
165+
"kind":"Dinosaur",
166+
"species":"foo",
167+
"updated_at":"2023-10-26T08:15:54.509653Z"
168+
}
169+
],
170+
"kind":"DinosaurList",
171+
"page":1,
172+
"size":1,
173+
"total":1
174+
}
175+
```
176+
145177
#### Run in CRC
146178

147179
Use OpenShift Local to deploy to a local openshift cluster. Be sure to have CRC running locally:

0 commit comments

Comments
 (0)