2017年1月26日星期四

OpenShift_043:RoadShow 回顾之三:部署 nationalparks

环境:OCP 3.4


1. 克隆 nationalparks 源代码 (在 MAC 机器上操作)
cd ~/mygit
git clone -b 1.2.1 https://github.com/openshift-roadshow/nationalparks.git
scp -r nationalparks/ root@registry.example.com:/opt/

2. 初始化 nationalparks git 仓库(在 Registry 机器上操作)
mkdir -p /opt/git/repo/nationalparks.git;
cd /opt/git/repo/nationalparks.git;
git init --bare;
git update-server-info;
mv hooks/post-update.sample hooks/post-update;

3. 拷贝 nationalparks 代码,并提交(在 Registry 机器上操作)
cd /opt;
mv nationalparks nationalparks-demo

git clone file:///opt/git/repo/nationalparks.git/;

cp nationalparks-demo/* nationalparks -rf;
cp nationalparks-demo/.sti nationalparks -rf;
cp nationalparks-demo/.htaccess nationalparks -rf;
cp nationalparks-demo/.gitignore nationalparks -rf;
cd nationalparks;
git add .;
git commit -m 'initial upload';
git push origin master;

4. 下载 Builder Image(在 MAC 机器上做)
docker pull jorgemoralespou/s2i-java
docker save -o s2i-java.tar.gz jorgemoralespou/s2i-java
scp s2i-java.tar.gz root@192.168.56.112:/opt/ose/images/
说明:之所以下载 jorgemoralespou/s2i-java,是因为在 nationalparks/ose/application-template.json 中使用了它。

5. 加载 Builder Image(在 Registry 机器上做)
docker load -i s2i-java.tar.gz
docker tag jorgemoralespou/s2i-java:latest registry.example.com:5000/jorgemoralespou/s2i-java:latest
docker push registry.example.com:5000/jorgemoralespou/s2i-java:latest

6. 为 Builder Image 创建 Image Stream(在 Master 机器上做)
cd /opt
oc create -f simple-s2i-java-is.json -n openshift
其中 simple-s2i-java-is.json 内容如下:
{
    "kind": "ImageStream",
    "apiVersion": "v1",
    "metadata": {
        "name": "simple-java-s2i",
        "namespace": "openshift",
        "creationTimestamp": null
    },
    "spec": {
        "dockerImageRepository": "registry.example.com:5000/jorgemoralespou/s2i-java",
        "tags": [
            {
                "name": "latest",
                "annotations": {
                    "description": "Simple Java 1.8 S2I builder",
                    "iconClass": "icon-jboss",
                    "supports": "java:8",
                    "tags": "builder,java",
                    "version": "1.0"
                },
                "from": {
                    "kind": "DockerImage",
                    "name": "registry.example.com:5000/jorgemoralespou/s2i-java"
                },
                "generation": 1,
                "importPolicy": {
                    "insecure": true
                }
            }
        ]
    }
}

7. 部署 nationalparks 应用

别忘了在 Build Config 中增加环境变量:
MAVEN_MIRROR_URL = http://192.168.56.1:8081/nexus/content/groups/public/

8. 访问 nationalparks 应用
http://nationalparks-applications.apps.example.com/ws/info/
输出如下:
{"id":"nationalparks","displayName":"National Parks","center":{"latitude":"47.039304","longitude":"14.505178"},"zoom":4}

9. 清理
如果有错,执行以下命令清理,然后重做:
oc delete is/nationalparks bc/nationalparks dc/nationalparks svc/nationalparks routes/nationalparks

参考文献:
1. http://labs.openshift3roadshow.com/roadshow/
2. https://github.com/jorgemoralespou/s2i-java
3. https://github.com/openshift-roadshow/nationalparks

没有评论: