Skip to content

Commit a62501b

Browse files
committed
Readme instructions for OpenShift sample
1 parent 77e0977 commit a62501b

File tree

3 files changed

+92
-8
lines changed

3 files changed

+92
-8
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
11
mq-golang-jms20.test
22
vendor
3+
.DS_Store

openshift-app-sample/README.md

Lines changed: 91 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,91 @@
1+
# IBM MQ Golang application tutorial for OpenShift
2+
This sample provides a working template that you can use to build your own Golang
3+
application container image that runs in Red Hat OpenShift under the most secure
4+
"Restricted SCC" and uses the
5+
[IBM MQ Golang](https://github.com/ibm-messaging/mq-golang) or
6+
[IBM MQ Golang JMS](https://github.com/ibm-messaging/mq-golang-jms20) libraries to connect
7+
to an IBM MQ queue manager.
8+
9+
You can build and run your application using the following simple steps;
10+
1. Modify the application file to add your code
11+
2. Build the application into a Docker container image locally
12+
3. Push the container image to your OpenShift cluster
13+
4. Configure the variables and run the application!
14+
15+
16+
Let's get started!
17+
18+
19+
## Step 1: Modify the application file to add your code
20+
Add your application logic into the [main.go](./src/main.go) file using either the
21+
[IBM MQ Golang](https://github.com/ibm-messaging/mq-golang) or
22+
[IBM MQ Golang JMS](https://github.com/ibm-messaging/mq-golang-jms20) interfaces depending
23+
on your preference.
24+
25+
The file contains all the basic details necessary to create a
26+
connection to a queue manager, so you can simply add your logic to send and/or receive
27+
messages at the bottom of the function.
28+
29+
30+
## Step 2: Build the application into a Docker container image locally
31+
Open a command shell to the same directory as this readme file and execute the following command;
32+
```bash
33+
# Run the dockerfile build to create the container image
34+
docker build -t golang-app -f Dockerfile .
35+
```
36+
37+
38+
## Step 3: Push the container image to your OpenShift cluster
39+
This step will vary depending on what sort of OpenShift cluster you are going to deploy to -
40+
for example a registry that is part of the cluster or an external registry that can be
41+
accessed by the cluster.
42+
43+
In this example we are using the IBM Cloud Container Registry (in London) that is hosted
44+
at `uk.icr.io`.
45+
46+
```bash
47+
# Tag the new image against the target registry
48+
docker tag golang-app uk.icr.io/golang-sample/golang-app:1.0
49+
50+
# Push the updated image to your registry
51+
docker push uk.icr.io/golang-sample/golang-app:1.0
52+
```
53+
54+
**Note:** If you are iterating over this step multiple times while testing your application then
55+
don't forget to increase the tag version each time as image caching on cluster may mean
56+
that your updates don't actually get used when you expect them to!
57+
58+
59+
## Step 4: Configure the variables and run the application!
60+
Next we will do a one-time set up of some basic objects on the cluster in order to
61+
supply configuration settings to the application.
62+
63+
```bash
64+
# Create a service account that we can use to deploy using the Restricted SCC
65+
oc apply -f ./yaml/sa-pod-deployer.yaml
66+
67+
# Create a config map containing the details of your queue manager.
68+
#
69+
# If your queue manager is in the same OpenShift cluster then the hostname will be the
70+
# name of the "service".
71+
oc create configmap qmgr-details \
72+
--from-literal=HOSTNAME=mydynamichostname \
73+
--from-literal=PORT=34567 \
74+
--from-literal=QMNAME=QM100 \
75+
--from-literal=CHANNELNAME=SYSTEM.DEF.SVRCONN
76+
77+
# If necessary, create a secret to hold the username and password your application should
78+
# use to authenticate to the queue manager.
79+
oc create secret generic qmgr-credentials \
80+
--from-literal=USERNAME=appuser100 \
81+
--from-literal=PASSWORD='password100'
82+
```
83+
84+
Now run the application!
85+
```bash
86+
# Before you run this command, be sure to update the "image" attribute on
87+
# line 8 of pod-sample.yaml so that it matches your image tag version from step 3.
88+
oc apply -f ./yaml/pod-sample.yaml --as=my-service-account
89+
```
90+
91+
Congratulations - and happy messaging!

openshift-app-sample/src/main.go

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -21,14 +21,6 @@ import (
2121
func main() {
2222
fmt.Println("Beginning world!!!")
2323

24-
fmt.Println("host: ", os.Getenv("HOSTNAME"))
25-
fmt.Println("port: ", os.Getenv("PORT"))
26-
fmt.Println("qm: ", os.Getenv("QMNAME"))
27-
fmt.Println("channel: ", os.Getenv("CHANNELNAME"))
28-
29-
fmt.Println("user: ", os.Getenv("USERNAME"))
30-
fmt.Println("pw: ", os.Getenv("PASSWORD"))
31-
3224
portNum, _ := strconv.Atoi(os.Getenv("PORT"))
3325

3426
// Initialise the attributes of the CF in whatever way you like

0 commit comments

Comments
 (0)