zoukankan      html  css  js  c++  java
  • OpenShift应用镜像构建(2)

     Openshift对于应用构建提供了三种模式

    • 从应用的源代码构建并部署,Openshift通过一个S2I的构建过程编译打包并实现发布,具体可以参考

    https://www.cnblogs.com/ericnie/p/9677719.html  

    • 从应用的二进制构建和部署,用户可以指定通过其他工具完成的二进制包,比如war,jar之类,然后openshift将这些文件和基础镜像一起打包发布。
    • 在Openshift之外构建源码和镜像

    S2I虽然非常方便,个人认为他的定位是 

    • 适用场景是一些没有通过外部的CICD工具的项目,直接在S2I镜像内完成程序的编译以及形成应用镜像的过程,相对比较小巧而且灵活
    • 会把中间的编译依赖包以及其他中间过程打包到同一个运行镜像,这对于一些公司需要符合公司的标准运行镜像,同时只需要一个标准镜像和编译后的二进制以及应用配置这种模式就不太适合了。

    链式构建就是主要针对这个问题而出现的,过程如下:

    1. 生成Binary的构建

    ericdeMacBook-Pro:~ ericnie$ oc new-build s2i-tomcat~https://github.com/ericnie2015/openshift-tomcat --name=builder
    --> Found image f000bc5 (7 days old) in image stream "openshift/s2i-tomcat" under tag "latest" for "s2i-tomcat"
    
        Tomcat Builder
        --------------
        Platform for building and running JEE applications on Tomcat
    
        Tags: builder, tomcat
    
        * A source build using source code from https://github.com/ericnie2015/openshift-tomcat will be created
          * The resulting image will be pushed to image stream "builder:latest"
          * Use 'start-build' to trigger a new build
    
    --> Creating resources with label build=builder ...
        imagestream "builder" created
        buildconfig "builder" created
    --> Success
        Build configuration "builder" created and build triggered.
        Run 'oc logs -f bc/builder' to stream the build progress.

    构建完成后看到一个名叫builder的构建和镜像

    2.Docker构建生成Runtime Images.

    ricdeMacBook-Pro:chainbuilding ericnie$ oc new-build --name=runtime --docker-image=ericnie2017/tomcat:8.5.34-jre8 --source-image=builder --source-image-path=/tomcat/webapps/ROOT.war:. --dockerfile=$'FROM ericnie2017/tomcat:8.5.34-jre8
    COPY ROOT.war /usr/local/tomcat/webapps/myapp.war' --strategy=docker
    --> Found Docker image 41a54fe (3 weeks old) from Docker Hub for "tomcat:8.5.34-jre8"
    
        * An image stream will be created as "tomcat:8.5.34-jre8" that will track the source image
        * A Docker build using a predefined Dockerfile will be created
          * The resulting image will be pushed to image stream "runtime:latest"
          * Every time "tomcat:8.5.34-jre8" changes a new build will be triggered
    
    --> Creating resources with label build=runtime ...
        imagestream "runtime" created
        buildconfig "runtime" created
    --> Success
        Build configuration "runtime" created and build triggered.
        Run 'oc logs -f bc/runtime' to stream the build progress.

    构建日志如下

    ericdeMacBook-Pro:chainbuilding ericnie$ oc logs -f bc/runtime
    Pulling image tomcat@sha256:e7bff3f32561daf3ba91142bca7c5aeaf49c376ee07e0d6b66e3207aa08a343a ...
    Pulled 8/12 layers, 68% complete
    Pulled 9/12 layers, 78% complete
    Pulled 10/12 layers, 83% complete
    Pulled 11/12 layers, 92% complete
    Pulled 12/12 layers, 100% complete
    Extracting
    Step 1/4 : FROM tomcat@sha256:e7bff3f32561daf3ba91142bca7c5aeaf49c376ee07e0d6b66e3207aa08a343a
     ---> 41a54fe1f79d
    Step 2/4 : COPY ROOT.war /usr/local/tomcat/webapps/
     ---> 265bdbdfd823
    Removing intermediate container 2eb535912c60
    Step 3/4 : ENV "OPENSHIFT_BUILD_NAME" "runtime-1" "OPENSHIFT_BUILD_NAMESPACE" "maven-tomcat"
     ---> Running in ab63b922af0e
     ---> a5452c4705d6
    Removing intermediate container ab63b922af0e
    Step 4/4 : LABEL "io.openshift.build.name" "runtime-1" "io.openshift.build.namespace" "maven-tomcat"
     ---> Running in 95e2f78a51c7
     ---> 5a76fcaecd2a
    Removing intermediate container 95e2f78a51c7
    Successfully built 5a76fcaecd2a
    Pushing image 172.30.1.1:5000/maven-tomcat/runtime:latest ...
    Pushed 0/13 layers, 8% complete
    Pushed 1/13 layers, 8% complete
    Pushed 2/13 layers, 16% complete
    Pushed 3/13 layers, 24% complete
    Pushed 4/13 layers, 34% complete
    Pushed 5/13 layers, 42% complete
    Pushed 6/13 layers, 50% complete
    Pushed 7/13 layers, 59% complete
    Pushed 8/13 layers, 63% complete
    Pushed 9/13 layers, 70% complete
    Pushed 10/13 layers, 79% complete
    Pushed 11/13 layers, 88% complete
    Pushed 12/13 layers, 97% complete
    Pushed 13/13 layers, 100% complete
    Push successful

    3.生成新的应用

    ericdeMacBook-Pro:chainbuilding ericnie$ oc new-app runtime --name=tomcat-app
    --> Found image 5a76fca (About a minute old) in image stream "maven-tomcat/runtime" under tag "latest" for "runtime"
    
        * This image will be deployed in deployment config "tomcat-app"
        * Port 8080/tcp will be load balanced by service "tomcat-app"
          * Other containers can access this service through the hostname "tomcat-app"
        * WARNING: Image "maven-tomcat/runtime:latest" runs as the 'root' user which may not be permitted by your cluster administrator
    
    --> Creating resources ...
        imagestreamtag "tomcat-app:latest" created
        deploymentconfig "tomcat-app" created
        service "tomcat-app" created
    --> Success
        Application is not exposed. You can expose services to the outside world by executing one or more of the commands below:
         'oc expose svc/tomcat-app'
        Run 'oc status' to view your app.

    创建Route后访问,根目录页面

    myapp目录下页面

  • 相关阅读:
    Tarjan强联通分量【模板】
    codevs——T2488 绿豆蛙的归宿
    POJ——T1679 The Unique MST
    POJ——T1125 Stockbroker Grapevine
    POJ——T1789 Truck History
    linux基础(5)- nginx服务、nfs服务
    8-15
    最佳加法表达式(动态规划)
    Zipper(动态规划)
    8-14
  • 原文地址:https://www.cnblogs.com/ericnie/p/9742847.html
Copyright © 2011-2022 走看看