环境:OCP 3.4
缩写 MLB 代表 Major League Baseball,美国职棒大联盟。
1. 下载 mlbparks 源代码(在 MAC 机器上做)
cd ~/mygit
git clone -b 1.0.0 https://github.com/openshift-roadshow/mlbparks.git
scp -r mlbparks/ root@registry.example.com:/opt/
2. 初始化 mlbparks git 仓库(在 Registry 机器上操作)
mkdir -p /opt/git/repo/mlbparks.git;
cd /opt/git/repo/mlbparks.git;
git init --bare;
git update-server-info;
mv hooks/post-update.sample hooks/post-update;
3. 拷贝 mlbparks 代码,并提交(在 Registry 机器上操作)
cd /opt;
mv mlbparks mlbparks-demo
git clone file:///opt/git/repo/mlbparks.git/;
cp mlbparks-demo/* mlbparks -rf;
cp mlbparks-demo/.sti mlbparks -rf;
cp mlbparks-demo/.htaccess mlbparks -rf;
cp mlbparks-demo/.gitignore mlbparks -rf;
cd mlbparks;
git add .;
git commit -m 'initial upload';
git push origin master;
4. 克隆 mlbparks git 仓库,并部署 mlbparks 应用(在 Master 上操作)
cd /tmp;
git clone http://git.example.com/git/mlbparks.git;
修改 /tmp/mlbparks/ose3/application-template-eap.json
把 parameters 中的 GIT_URI 值改为 http://git.example.com/git/mlbparks.git
把 parameters 中的 MAVEN_MIRROR_URL 值改为 http://192.168.56.1:8081/nexus/content/groups/public/
创建 template
cd /tmp/mlbparks/ose3
oc create -f application-template-eap.json
创建 jboss-eap70-openshift Image Stream
由于 template 中使用了 jboss-eap70-openshift Image Stream,因此需要创建该 IS,否则会报如下错误:
An error occurred while starting the build.Error resolving ImageStreamTag jboss-eap70-openshift:1.4 in namespace openshift: imagestreams "jboss-eap70-openshift" not found
关于如何创建 jboss-eap70-openshift IS,请参考《部署 MyBank 到 JBoss EAP 7》。
创建应用
oc new-app mlbparks --name=mlbparks
输出如下:
--> Deploying template "applications/mlbparks" to project applications
mlbparks
---------
Application template MLBParks backend running on JBoss EAP and using MongoDB
* With parameters:
* Application Name=mlbparks
* Application route=
* Mongodb App=mongodb-mlbparks
* Git source repository=http://git.example.com/git/mlbparks.git
* Git branch/tag reference=master
* Maven mirror url=http://192.168.56.1:8081/nexus/content/groups/public/
* Database name=mongodb
* MONGODB_NOPREALLOC=
* MONGODB_SMALLFILES=
* MONGODB_QUIET=
* Database user name=userdEl # generated
* Database user password=aa7rm6gw # generated
* Database admin password=h7adaF7C # generated
* GitHub Trigger=5oAIAQI4 # generated
* Generic Trigger=IcsEXf8s # generated
--> Creating resources ...
configmap "mlbparks" created
service "mongodb-mlbparks" created
deploymentconfig "mongodb-mlbparks" created
imagestream "mlbparks" created
buildconfig "mlbparks" created
deploymentconfig "mlbparks" created
service "mlbparks" created
route "mlbparks" created
--> Success
Build scheduled, use 'oc logs -f bc/mlbparks' to track its progress.
Run 'oc status' to view your app.
OpenShift 做了如下事情:
oc new-app mlbparks --name=mlbparks -p GIT_URI=http://git.example.com/git/mlbparks.git
5. 清理(在 Master 上操作)
参考文献:
1. http://labs.openshift3roadshow.com/roadshow/
2. https://github.com/openshift-roadshow/mlbparks
缩写 MLB 代表 Major League Baseball,美国职棒大联盟。
1. 下载 mlbparks 源代码(在 MAC 机器上做)
cd ~/mygit
git clone -b 1.0.0 https://github.com/openshift-roadshow/mlbparks.git
scp -r mlbparks/ root@registry.example.com:/opt/
2. 初始化 mlbparks git 仓库(在 Registry 机器上操作)
mkdir -p /opt/git/repo/mlbparks.git;
cd /opt/git/repo/mlbparks.git;
git init --bare;
git update-server-info;
mv hooks/post-update.sample hooks/post-update;
3. 拷贝 mlbparks 代码,并提交(在 Registry 机器上操作)
cd /opt;
mv mlbparks mlbparks-demo
git clone file:///opt/git/repo/mlbparks.git/;
cp mlbparks-demo/* mlbparks -rf;
cp mlbparks-demo/.sti mlbparks -rf;
cp mlbparks-demo/.htaccess mlbparks -rf;
cp mlbparks-demo/.gitignore mlbparks -rf;
cd mlbparks;
git add .;
git commit -m 'initial upload';
git push origin master;
4. 克隆 mlbparks git 仓库,并部署 mlbparks 应用(在 Master 上操作)
cd /tmp;
git clone http://git.example.com/git/mlbparks.git;
修改 /tmp/mlbparks/ose3/application-template-eap.json
把 parameters 中的 GIT_URI 值改为 http://git.example.com/git/mlbparks.git
把 parameters 中的 MAVEN_MIRROR_URL 值改为 http://192.168.56.1:8081/nexus/content/groups/public/
创建 template
cd /tmp/mlbparks/ose3
oc create -f application-template-eap.json
创建 jboss-eap70-openshift Image Stream
由于 template 中使用了 jboss-eap70-openshift Image Stream,因此需要创建该 IS,否则会报如下错误:
An error occurred while starting the build.Error resolving ImageStreamTag jboss-eap70-openshift:1.4 in namespace openshift: imagestreams "jboss-eap70-openshift" not found
关于如何创建 jboss-eap70-openshift IS,请参考《部署 MyBank 到 JBoss EAP 7》。
创建应用
oc new-app mlbparks --name=mlbparks
输出如下:
--> Deploying template "applications/mlbparks" to project applications
mlbparks
---------
Application template MLBParks backend running on JBoss EAP and using MongoDB
* With parameters:
* Application Name=mlbparks
* Application route=
* Mongodb App=mongodb-mlbparks
* Git source repository=http://git.example.com/git/mlbparks.git
* Git branch/tag reference=master
* Maven mirror url=http://192.168.56.1:8081/nexus/content/groups/public/
* Database name=mongodb
* MONGODB_NOPREALLOC=
* MONGODB_SMALLFILES=
* MONGODB_QUIET=
* Database user name=userdEl # generated
* Database user password=aa7rm6gw # generated
* Database admin password=h7adaF7C # generated
* GitHub Trigger=5oAIAQI4 # generated
* Generic Trigger=IcsEXf8s # generated
--> Creating resources ...
configmap "mlbparks" created
service "mongodb-mlbparks" created
deploymentconfig "mongodb-mlbparks" created
imagestream "mlbparks" created
buildconfig "mlbparks" created
deploymentconfig "mlbparks" created
service "mlbparks" created
route "mlbparks" created
--> Success
Build scheduled, use 'oc logs -f bc/mlbparks' to track its progress.
Run 'oc status' to view your app.
OpenShift 做了如下事情:
- 配置并启动了一个 build
- 克隆 git 仓库
- 配置并部署 MongoDB
- 自动生成 user, password, database name
- 配置环境变量,使得应用连接到 MongoDB
- 创建 services
- 为应用的 route 增加 label:type=parksmap-backend
oc new-app mlbparks --name=mlbparks -p GIT_URI=http://git.example.com/git/mlbparks.git
但这样设置后,build 的时候依然会失败,因为默认会去访问外网 Maven 仓库,由于无法访问,所以报错。
可以在控制台的 BuildConfig 中增加该参数MAVEN_MIRROR_URL=http://192.168.56.1:8081/nexus/content/groups/public/
也可以用命令行重新 build
可以在控制台的 BuildConfig 中增加该参数MAVEN_MIRROR_URL=http://192.168.56.1:8081/nexus/content/groups/public/
也可以用命令行重新 build
oc new-app mlbparks --name=mlbparks -p GIT_URI=http://git.example.com/git/mlbparks.git -p MAVEN_MIRROR_URL=http://192.168.56.1:8081/nexus/content/groups/public/
注意 build 时间比较长,10分钟左右,这次成功了!
注意 build 时间比较长,10分钟左右,这次成功了!
如果有错,执行以下命令清理,然后重做:
oc delete configmaps/mlbparks is/mlbparks bc/mlbparks dc/mlbparks svc/mlbparks routes/mlbparks dc/mongodb-mlbparks svc/mongodb-mlbparks
1. http://labs.openshift3roadshow.com/roadshow/
2. https://github.com/openshift-roadshow/mlbparks
没有评论:
发表评论