Browse code

add a wordpress template

Ben Parees authored on 2015/11/07 06:04:45
Showing 3 changed files
... ...
@@ -61,6 +61,9 @@ func TestExampleObjectSchemas(t *testing.T) {
61 61
 	// TODO: make this configurable and not the default https://github.com/openshift/origin/issues/662
62 62
 	capabilities.Setup(true, capabilities.PrivilegedSources{}, 0)
63 63
 	cases := map[string]map[string]runtime.Object{
64
+		"../examples/wordpress/template": {
65
+			"wordpress-mysql": &templateapi.Template{},
66
+		},
64 67
 		"../examples/hello-openshift": {
65 68
 			"hello-pod":     &kapi.Pod{},
66 69
 			"hello-project": &projectapi.Project{},
67 70
new file mode 100644
... ...
@@ -0,0 +1,41 @@
0
+This example depends on the existence of a "php" imagestream in the "openshift" namespace.  If you do not have one defined, you can create it by using one of the imagestream definition files found here:
1
+https://github.com/openshift/origin/tree/master/examples/image-streams
2
+
3
+	oc create -f image-streams-centos7.json -n openshift
4
+
5
+(you will need to be a cluster admin to create imagestreams in the openshift namespace)
6
+
7
+To use this example, instantiate it with
8
+
9
+	oc new-app -f wordpress-mysql.json
10
+
11
+Take note of the `DATABASE_PASSWORD` that is displayed.
12
+
13
+Wait for the build of the new wordpress image to complete.  You can monitor the build by running
14
+
15
+	oc get builds --watch
16
+
17
+Once the wordpress build completes, determine the wordpress and
18
+mysql service IPs by running:
19
+
20
+	oc get svc
21
+
22
+Navigate to `<wordpress service ip>:8080` in your browser.  You will
23
+be prompted to setup wordpress.
24
+
25
+For the database hostname, provide the mysql service ip.
26
+
27
+For the database username, enter "wordpress"
28
+
29
+For the database password, provide the password generated when you
30
+instantiated the template.
31
+
32
+You should not need to change any other values.
33
+
34
+
35
+Note: this template uses an EmptyDir volume type for database storage.  This type of storage is not persisted.  If you want to ensure the database content is not lost, modify the template to user a persistent volume claim type instead.
36
+
37
+
38
+
39
+
40
+
0 41
new file mode 100644
... ...
@@ -0,0 +1,341 @@
0
+{
1
+  "kind": "Template",
2
+  "apiVersion": "v1",
3
+  "metadata": {
4
+    "name": "wordpress-mysql-example",
5
+    "annotations": {
6
+      "description": "An example wordpress application with a MySQL database.  Note: the MySQL service created by this template uses non-persistent storage.  To setup persisted storage, change this template to use a persistent volume claim instead of emptydir.",
7
+      "tags": "instant-app,php,wordpress,mysql",
8
+      "iconClass": "icon-php"
9
+    }
10
+  },
11
+  "labels": {
12
+    "template": "wordpress-mysql-example"
13
+  },
14
+  "objects": [
15
+    {
16
+      "kind": "Service",
17
+      "apiVersion": "v1",
18
+      "metadata": {
19
+        "name": "wordpress-mysql-example",
20
+        "annotations": {
21
+          "description": "Exposes and load balances the application pods"
22
+        }
23
+      },
24
+      "spec": {
25
+        "ports": [
26
+          {
27
+            "name": "web",
28
+            "port": 8080,
29
+            "targetPort": 8080
30
+          }
31
+        ],
32
+        "selector": {
33
+          "name": "wordpress-mysql-example"
34
+        }
35
+      }
36
+    },
37
+    {
38
+      "kind": "Route",
39
+      "apiVersion": "v1",
40
+      "metadata": {
41
+        "name": "wordpress-mysql-example"
42
+      },
43
+      "spec": {
44
+        "host": "${APPLICATION_DOMAIN}",
45
+        "to": {
46
+          "kind": "Service",
47
+          "name": "wordpress-mysql-example"
48
+        }
49
+      }
50
+    },
51
+    {
52
+      "kind": "ImageStream",
53
+      "apiVersion": "v1",
54
+      "metadata": {
55
+        "name": "wordpress-mysql-example",
56
+        "annotations": {
57
+          "description": "Keeps track of changes in the application image"
58
+        }
59
+      }
60
+    },
61
+    {
62
+      "kind": "BuildConfig",
63
+      "apiVersion": "v1",
64
+      "metadata": {
65
+        "name": "wordpress-mysql-example",
66
+        "annotations": {
67
+          "description": "Defines how to build the application"
68
+        }
69
+      },
70
+      "spec": {
71
+        "source": {
72
+          "type": "Git",
73
+          "git": {
74
+            "uri": "${SOURCE_REPOSITORY_URL}",
75
+            "ref": "${SOURCE_REPOSITORY_REF}"
76
+          },
77
+          "contextDir": "${CONTEXT_DIR}"
78
+        },
79
+        "strategy": {
80
+          "type": "Source",
81
+          "sourceStrategy": {
82
+            "from": {
83
+              "kind": "ImageStreamTag",
84
+              "namespace": "openshift",
85
+              "name": "php:5.5"
86
+            }
87
+          }
88
+        },
89
+        "output": {
90
+          "to": {
91
+            "kind": "ImageStreamTag",
92
+            "name": "wordpress-mysql-example:latest"
93
+          }
94
+        },
95
+        "triggers": [
96
+          {
97
+            "type": "ImageChange"
98
+          },
99
+          {
100
+            "type": "ConfigChange"
101
+          },
102
+          {
103
+            "type": "GitHub",
104
+            "github": {
105
+              "secret": "${GITHUB_WEBHOOK_SECRET}"
106
+            }
107
+          }
108
+        ]
109
+      }
110
+    },
111
+    {
112
+      "kind": "DeploymentConfig",
113
+      "apiVersion": "v1",
114
+      "metadata": {
115
+        "name": "wordpress-mysql-example",
116
+        "annotations": {
117
+          "description": "Defines how to deploy the application server"
118
+        }
119
+      },
120
+      "spec": {
121
+        "strategy": {
122
+          "type": "Rolling"
123
+        },
124
+        "triggers": [
125
+          {
126
+            "type": "ImageChange",
127
+            "imageChangeParams": {
128
+              "automatic": true,
129
+              "containerNames": [
130
+                "wordpress-mysql-example"
131
+              ],
132
+              "from": {
133
+                "kind": "ImageStreamTag",
134
+                "name": "wordpress-mysql-example:latest"
135
+              }
136
+            }
137
+          },
138
+          {
139
+            "type": "ConfigChange"
140
+          }
141
+        ],
142
+        "replicas": 1,
143
+        "selector": {
144
+          "name": "wordpress-mysql-example"
145
+        },
146
+        "template": {
147
+          "metadata": {
148
+            "name": "wordpress-mysql-example",
149
+            "labels": {
150
+              "name": "wordpress-mysql-example"
151
+            }
152
+          },
153
+          "spec": {
154
+            "containers": [
155
+              {
156
+                "name": "wordpress-mysql-example",
157
+                "image": "wordpress-mysql-example",
158
+                "ports": [
159
+                  {
160
+                    "containerPort": 8080
161
+                  }
162
+                ],
163
+                "env": [
164
+                  {
165
+                    "name": "DATABASE_SERVICE_NAME",
166
+                    "value": "${DATABASE_SERVICE_NAME}"
167
+                  },
168
+                  {
169
+                    "name": "DATABASE_ENGINE",
170
+                    "value": "${DATABASE_ENGINE}"
171
+                  },
172
+                  {
173
+                    "name": "DATABASE_NAME",
174
+                    "value": "${DATABASE_NAME}"
175
+                  },
176
+                  {
177
+                    "name": "DATABASE_USER",
178
+                    "value": "${DATABASE_USER}"
179
+                  },
180
+                  {
181
+                    "name": "DATABASE_PASSWORD",
182
+                    "value": "${DATABASE_PASSWORD}"
183
+                  }
184
+                ],
185
+                "volumeMounts": [
186
+                  {
187
+                    "name": "${DATABASE_SERVICE_NAME}-data",
188
+                    "mountPath": "/var/lib/mysql/data"
189
+                  }
190
+                ]
191
+              }
192
+            ],
193
+            "volumes": [
194
+              {
195
+                "name": "${DATABASE_SERVICE_NAME}-data",
196
+                "emptyDir": {
197
+                  "medium": ""
198
+                }
199
+              }
200
+            ]
201
+          }
202
+        }
203
+      }
204
+    },
205
+    {
206
+      "kind": "Service",
207
+      "apiVersion": "v1",
208
+      "metadata": {
209
+        "name": "${DATABASE_SERVICE_NAME}",
210
+        "annotations": {
211
+          "description": "Exposes the database server"
212
+        }
213
+      },
214
+      "spec": {
215
+        "ports": [
216
+          {
217
+            "name": "mysql",
218
+            "port": 3306,
219
+            "targetPort": 3306
220
+          }
221
+        ],
222
+        "selector": {
223
+          "name": "${DATABASE_SERVICE_NAME}"
224
+        }
225
+      }
226
+    },
227
+    {
228
+      "kind": "DeploymentConfig",
229
+      "apiVersion": "v1",
230
+      "metadata": {
231
+        "name": "${DATABASE_SERVICE_NAME}",
232
+        "annotations": {
233
+          "description": "Defines how to deploy the database"
234
+        }
235
+      },
236
+      "spec": {
237
+        "strategy": {
238
+          "type": "Recreate"
239
+        },
240
+        "triggers": [
241
+          {
242
+            "type": "ConfigChange"
243
+          }
244
+        ],
245
+        "replicas": 1,
246
+        "selector": {
247
+          "name": "${DATABASE_SERVICE_NAME}"
248
+        },
249
+        "template": {
250
+          "metadata": {
251
+            "name": "${DATABASE_SERVICE_NAME}",
252
+            "labels": {
253
+              "name": "${DATABASE_SERVICE_NAME}"
254
+            }
255
+          },
256
+          "spec": {
257
+            "containers": [
258
+              {
259
+                "name": "mysql",
260
+                "image": "${MYSQL_IMAGE}",
261
+                "ports": [
262
+                  {
263
+                    "containerPort": 3306
264
+                  }
265
+                ],
266
+                "env": [
267
+                  {
268
+                    "name": "MYSQL_USER",
269
+                    "value": "${DATABASE_USER}"
270
+                  },
271
+                  {
272
+                    "name": "MYSQL_PASSWORD",
273
+                    "value": "${DATABASE_PASSWORD}"
274
+                  },
275
+                  {
276
+                    "name": "MYSQL_DATABASE",
277
+                    "value": "${DATABASE_NAME}"
278
+                  }
279
+                ]
280
+              }
281
+            ]
282
+          }
283
+        }
284
+      }
285
+    }
286
+  ],
287
+  "parameters": [
288
+    {
289
+      "name": "SOURCE_REPOSITORY_URL",
290
+      "description": "The URL of the repository with your application source code",
291
+      "value": "https://github.com/wordpress/wordpress.git"
292
+    },
293
+    {
294
+      "name": "SOURCE_REPOSITORY_REF",
295
+      "description": "Set this to a branch name, tag or other ref of your repository if you are not using the default branch"
296
+    },
297
+    {
298
+      "name": "CONTEXT_DIR",
299
+      "description": "Set this to the relative path to your project if it is not in the root of your repository"
300
+    },
301
+    {
302
+      "name": "APPLICATION_DOMAIN",
303
+      "description": "The exposed hostname that will route to the wordpress service, if left blank a value will be defaulted.",
304
+      "value": ""
305
+    },
306
+    {
307
+      "name": "GITHUB_WEBHOOK_SECRET",
308
+      "description": "A secret string used to configure the GitHub webhook",
309
+      "generate": "expression",
310
+      "from": "[a-zA-Z0-9]{40}"
311
+    },
312
+    {
313
+      "name": "DATABASE_SERVICE_NAME",
314
+      "description": "Database service name",
315
+      "value": "mysql"
316
+    },
317
+    {
318
+      "name": "DATABASE_NAME",
319
+      "description": "Database name",
320
+      "value": "wordpress"
321
+    },
322
+    {
323
+      "name": "DATABASE_USER",
324
+      "description": "Database user name",
325
+      "value": "wordpress"
326
+    },
327
+    {
328
+      "name": "DATABASE_PASSWORD",
329
+      "description": "Database user password",
330
+      "generate": "expression",
331
+      "from": "[a-zA-Z0-9]{16}"
332
+    },
333
+    {
334
+      "name": "MYSQL_IMAGE",
335
+      "description": "Image to use for mysql",
336
+      "value": "openshift/mysql-55-centos7"      
337
+    }
338
+  ]
339
+}
340
+