环境:OCP 3.4
本实验全部材料来自我的同事陈耿,在此表示感谢!
MyBank 是一个基于 Maven 构建的 Java Web 应用。
1. 克隆 mybank 到本地 (在 MAC 机器上操作)
cd ~/mygit
git clone https://github.com/nichochen/mybank-demo-maven.git
2. 拷贝到 Registry 机器上(在 MAC 机器上操作)
cd ~/mygit
scp -r mybank-demo-maven/ root@registry.example.com:/opt/
3. 初始化 mybank git 仓库(在 Registry 机器上操作)
mkdir -p /opt/git/repo/mybank.git;
cd /opt/git/repo/mybank.git;
git init --bare;
git update-server-info;
mv hooks/post-update.sample hooks/post-update;
4. 拷贝 mybank 代码,并提交(在 Registry 机器上操作)
cd /opt;
git clone file:///opt/git/repo/mybank.git/;
cp mybank-demo-maven/* mybank -rf;
cp mybank-demo-maven/.sti mybank -rf;
cp mybank-demo-maven/.htaccess mybank -rf;
cp mybank-demo-maven/.gitignore mybank -rf;
cd mybank;
git add .;
git commit -m 'initial upload';
git push origin master;
5. 验证 mybank git 仓库是否创建成功(在所有机器上操作)
cd /tmp;
git clone http://git.example.com/git/mybank.git/;
6. 从 OCP 控制台部署 MyBank
搜索 eap,选择 eap70-basic-s2i
选择 mybank bc,点击 Start Build
An error occurred while starting the build.Error resolving ImageStreamTag jboss-eap70-openshift:1.4 in namespace openshift: imagestreams "jboss-eap70-openshift" not found
oc get is jboss-eap70-openshift -n openshift
发现确实没有 jboss-eap70-openshift Image Stream
7. 克隆 application-templates 到本地 (在 MAC 机器上操作)
cd ~/mygit
git clone https://github.com/jboss-openshift/application-templates.git
8. 拷贝 application-templates 到 Master 机器上(在 MAC 机器上操作)
cd ~/mygit
scp -r application-templates/ root@master.example.com:/opt/
9. 创建 JBoss Image Stream(在 Master 机器上操作)
cd /opt
由于默认的 Image Stream 指向的是 registry.access.redhat.com,需要修改为 registry.example.com:5000。
REDHAT_REG="registry.access.redhat.com";
PRIVATE_REG="registry.example.com:5000";
sed s/"${REDHAT_REG}"/"${PRIVATE_REG}"/g application-templates/jboss-image-streams.json |sed '/"creationTimestamp": null/a\\t,"annotations": {"openshift.io/image.insecureRepository": "true"}' |oc create -n openshift -f - ;
检查 jboss-eap70-openshift Image Stream 是否创建成功
oc get is -n openshift
输出如下:
NAME DOCKER REPO TAGS
jboss-eap70-openshift registry.example.com:5000/jboss-eap-7/eap70-openshift
如果不成功,删除所有导入的 Image Stream,然后在重试。
oc delete is jboss-amq-62 -n openshift
oc delete is jboss-datagrid65-openshift -n openshift
oc delete is jboss-datavirt63-openshift -n openshift
oc delete is jboss-decisionserver62-openshift -n openshift
oc delete is jboss-decisionserver63-openshift -n openshift
oc delete is jboss-eap64-openshift -n openshift
oc delete is jboss-eap70-openshift -n openshift
oc delete is jboss-processserver63-openshift -n openshift
oc delete is jboss-webserver30-tomcat7-openshift -n openshift
oc delete is jboss-webserver30-tomcat8-openshift -n openshift
oc delete is redhat-sso70-openshift -n openshift
导入后的 Image Stream 有个问题,就是没有 Tags,还需要导入相应的 Image。
docker tag registry.access.redhat.com/jboss-eap-7/eap70-openshift:latest registry.example.com:5000/jboss-eap-7/eap70-openshift:latest (之前已做)
docker push registry.example.com:5000/jboss-eap-7/eap70-openshift (之前已做)
oc import-image jboss-eap70-openshift --insecure -n openshift
再次检查 jboss-eap70-openshift Image Stream 是否创建成功,这次有了 Tag:latest
oc get is -n openshift
NAME DOCKER REPO TAGS UPDATED
jboss-eap70-openshift registry.example.com:5000/jboss-eap-7/eap70-openshift latest
10. 从命令行部署 MyBank
检查 template 参数
oc describe template eap70-basic-s2i -n openshift
oc process --parameters eap70-basic-s2i -n openshift
创建应用
oc new-app --template=eap70-basic-s2i --param=APPLICATION_NAME=mybank --param=SOURCE_REPOSITORY_URL=http://git.example.com/git/mybank.git --param=SOURCE_REPOSITORY_REF=master --param=CONTEXT_DIR=
发现错误依旧,发现是 template 要去寻找 jboss-eap70-openshift:1.4 镜像。
修改 template
oc edit template eap70-basic-s2i -n openshift
把 name: jboss-eap70-openshift:1.4 改成 name: jboss-eap70-openshift:latest。
重新部署,终于开始 build 了,不过有 Maven 错误,原来是无法下载外网的 Maven 构件。
启动 MAC 上的 Nexus,作为 Maven 镜像代理。
重新发起一次新的 build,这次终于成功了!
oc start-build mybank -e MAVEN_MIRROR_URL='http://192.168.56.1:8081/nexus/content/groups/public/'
参考文献:
1. https://github.com/nichochen/mybank-demo-maven
本实验全部材料来自我的同事陈耿,在此表示感谢!
MyBank 是一个基于 Maven 构建的 Java Web 应用。
1. 克隆 mybank 到本地 (在 MAC 机器上操作)
cd ~/mygit
git clone https://github.com/nichochen/mybank-demo-maven.git
2. 拷贝到 Registry 机器上(在 MAC 机器上操作)
cd ~/mygit
scp -r mybank-demo-maven/ root@registry.example.com:/opt/
3. 初始化 mybank git 仓库(在 Registry 机器上操作)
mkdir -p /opt/git/repo/mybank.git;
cd /opt/git/repo/mybank.git;
git init --bare;
git update-server-info;
mv hooks/post-update.sample hooks/post-update;
4. 拷贝 mybank 代码,并提交(在 Registry 机器上操作)
cd /opt;
git clone file:///opt/git/repo/mybank.git/;
cp mybank-demo-maven/* mybank -rf;
cp mybank-demo-maven/.sti mybank -rf;
cp mybank-demo-maven/.htaccess mybank -rf;
cp mybank-demo-maven/.gitignore mybank -rf;
cd mybank;
git add .;
git commit -m 'initial upload';
git push origin master;
5. 验证 mybank git 仓库是否创建成功(在所有机器上操作)
cd /tmp;
git clone http://git.example.com/git/mybank.git/;
6. 从 OCP 控制台部署 MyBank
搜索 eap,选择 eap70-basic-s2i
选择 mybank bc,点击 Start Build
An error occurred while starting the build.Error resolving ImageStreamTag jboss-eap70-openshift:1.4 in namespace openshift: imagestreams "jboss-eap70-openshift" not found
oc get is jboss-eap70-openshift -n openshift
发现确实没有 jboss-eap70-openshift Image Stream
7. 克隆 application-templates 到本地 (在 MAC 机器上操作)
cd ~/mygit
git clone https://github.com/jboss-openshift/application-templates.git
8. 拷贝 application-templates 到 Master 机器上(在 MAC 机器上操作)
cd ~/mygit
scp -r application-templates/ root@master.example.com:/opt/
9. 创建 JBoss Image Stream(在 Master 机器上操作)
cd /opt
由于默认的 Image Stream 指向的是 registry.access.redhat.com,需要修改为 registry.example.com:5000。
REDHAT_REG="registry.access.redhat.com";
PRIVATE_REG="registry.example.com:5000";
sed s/"${REDHAT_REG}"/"${PRIVATE_REG}"/g application-templates/jboss-image-streams.json |sed '/"creationTimestamp": null/a\\t,"annotations": {"openshift.io/image.insecureRepository": "true"}' |oc create -n openshift -f - ;
检查 jboss-eap70-openshift Image Stream 是否创建成功
oc get is -n openshift
输出如下:
NAME DOCKER REPO TAGS
jboss-eap70-openshift registry.example.com:5000/jboss-eap-7/eap70-openshift
如果不成功,删除所有导入的 Image Stream,然后在重试。
oc delete is jboss-amq-62 -n openshift
oc delete is jboss-datagrid65-openshift -n openshift
oc delete is jboss-datavirt63-openshift -n openshift
oc delete is jboss-decisionserver62-openshift -n openshift
oc delete is jboss-decisionserver63-openshift -n openshift
oc delete is jboss-eap64-openshift -n openshift
oc delete is jboss-eap70-openshift -n openshift
oc delete is jboss-processserver63-openshift -n openshift
oc delete is jboss-webserver30-tomcat7-openshift -n openshift
oc delete is jboss-webserver30-tomcat8-openshift -n openshift
oc delete is redhat-sso70-openshift -n openshift
导入后的 Image Stream 有个问题,就是没有 Tags,还需要导入相应的 Image。
docker tag registry.access.redhat.com/jboss-eap-7/eap70-openshift:latest registry.example.com:5000/jboss-eap-7/eap70-openshift:latest (之前已做)
docker push registry.example.com:5000/jboss-eap-7/eap70-openshift (之前已做)
oc import-image jboss-eap70-openshift --insecure -n openshift
再次检查 jboss-eap70-openshift Image Stream 是否创建成功,这次有了 Tag:latest
oc get is -n openshift
NAME DOCKER REPO TAGS UPDATED
jboss-eap70-openshift registry.example.com:5000/jboss-eap-7/eap70-openshift latest
10. 从命令行部署 MyBank
检查 template 参数
oc describe template eap70-basic-s2i -n openshift
oc process --parameters eap70-basic-s2i -n openshift
创建应用
oc new-app --template=eap70-basic-s2i --param=APPLICATION_NAME=mybank --param=SOURCE_REPOSITORY_URL=http://git.example.com/git/mybank.git --param=SOURCE_REPOSITORY_REF=master --param=CONTEXT_DIR=
发现错误依旧,发现是 template 要去寻找 jboss-eap70-openshift:1.4 镜像。
修改 template
oc edit template eap70-basic-s2i -n openshift
把 name: jboss-eap70-openshift:1.4 改成 name: jboss-eap70-openshift:latest。
重新部署,终于开始 build 了,不过有 Maven 错误,原来是无法下载外网的 Maven 构件。
启动 MAC 上的 Nexus,作为 Maven 镜像代理。
重新发起一次新的 build,这次终于成功了!
oc start-build mybank -e MAVEN_MIRROR_URL='http://192.168.56.1:8081/nexus/content/groups/public/'
参考文献:
1. https://github.com/nichochen/mybank-demo-maven
没有评论:
发表评论