Murano之:集成docker
murano是如何集成docker?提供了怎样的接口以辅助用户快捷的编写package呢?这个得利于murano自身的架构,murano的package提供了自定义lib的功能,即根据自己的需要,根据murano package的定义规则,自己拓展一个即可。关于murano package的解析请移步murano实践之package分析
DockerInterfacesLibrary
DockerInterfacesLibrary 中提供了对于一个已正确安装docker环境的虚拟机操作docker的接口,首先看下package中的manifest.yaml
见:murano-apps/manifest.yaml
Format: 1.0
Type: Library
FullName: io.murano.apps.docker.Interfaces
Name: Docker Interface Library
Description: |The library provides all necessary interface for Dockerand Kubernetes applications
Author: 'Mirantis, Inc'
Tags: [Docker, Kubernetes]Classes:io.murano.apps.docker.DockerApplication: DockerApplication.yamlio.murano.apps.docker.DockerContainer: DockerContainer.yamlio.murano.apps.docker.DockerContainerHost: DockerContainerHost.yamlio.murano.apps.docker.DockerHelpers: DockerHelpers.yamlio.murano.apps.docker.DockerHostVolume: DockerHostVolume.yamlio.murano.apps.docker.DockerTempVolume: DockerTempVolume.yamlio.murano.apps.docker.DockerVolume: DockerVolume.yamlio.murano.apps.docker.ApplicationPort: ApplicationPort.yaml
重点在Classes中,目前这里面主要封装了
- DockerApplication
- DockerContainer
- DockerContainerHost
- DockerHelpers
- DockerHostVolume
- DockerTempVolume
- DockerVolume
- ApplicationPort
这8个docker相关的接口,我们这里以DockerApplication为例做一个分析,在Classes文件包中找到DockerApplication.yaml
提供了deploy
、destroy
、getConnectionTo
等方法。以deploy
为例,显示了虚拟机使用docker安装application的步骤
deploy:Body:- $.host.deploy()
- $container: $.getContainer()
- $repr: $._getContainerRepresentation($container)
- If: $.getAttr(container, null) != $repr
Then:- $.onInstallationStart()
- Try:
- $.applicationEndpoints: $.host.hostContainer($container)
- $.setAttr(container, $repr)
Catch:- As: e
Do:- $formatString: 'Error: {0}'
- $._environment.reporter.report_error($, $formatString.format($e.message))
- Rethrow:
Else:- $.onInstallationFinish()
首先$.host.deploy()
,这个host
为DockerStandaloneHost
详见DockerStandaloneHost,具有方法deploy
,此处调用的也是deploy方法DockerStandaloneHost
的deploy
方法如下:
deploy:Body:- If: not $.getAttr(deployed, false)
Then:- $._environment.reporter.report($this, 'Create VM for Docker Server')
- $.instance.deploy()
- $resources: new(sys:Resources)
- $template: $resources.yaml('StartDocker.template')
- $.instance.agent.call($template, $resources)
- If: $.dockerRegistry != null and $.dockerRegistry != ''
Then:- $._environment.reporter.report($this, 'Configuring Docker registry')
- $template: $resources.yaml('SetupDockerRegistry.template').bind(dict(
dockerRegistry => $.dockerRegistry))- $.instance.agent.call($template, $resources)
- $._environment.reporter.report($this, 'Docker Server is up and running')
- $.setAttr(deployed, true)
从
- $.instance.deploy()
- $resources: new(sys:Resources)
- $template: $resources.yaml('StartDocker.template')
- $.instance.agent.call($template, $resources)
这四步看出,需要拿到StartDocker.template
交给LinuxMuranoInstance
,StartDocker.template
中的内容如下:
startDocker.template
FormatVersion: 2.0.0
Version: 1.0.0
Name: Start docker serviceBody: |startDocker()Scripts:startDocker:Type: ApplicationVersion: 1.0.0EntryPoint: startDocker.shOptions:captureStdout: falsecaptureStderr: falseverifyExitcode: false
这个template的EntryPoint是startDocker.sh
,内容:
#!/bin/bash
# Licensed under the Apache License, Version 2.0 (the "License"); you may
# not use this file except in compliance with the License. You may obtain
# a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
# License for the specific language governing permissions and limitations
# under the License.service docker start
一句话,启动docker服务,所以$.host.deploy()
其实就是用了启动虚拟机上的docker服务;根据上面的方法,
- $container: $.getContainer()
- $repr: $._getContainerRepresentation($container)
这两步获取container的基础信息
再看- $.host.hostContainer(container)
对应的方法如下:
hostContainer:Arguments:- container:
Contract: $.class(DockerContainer).notNull()Body:- $.deploy()
- $.deleteContainer($container.name)
- $portBindings: {}
- $newEndpoints: []
- $._pullImage(image => $container.image)
- For: applicationPort
In: $container.portsDo:- If: $applicationPort.scope != host
Then:- $hostPort: $._acquirePort($applicationPort, $container.name)
- $containerPort: $._getPortSpec($applicationPort)
- $portBindings[$hostPort]: $containerPort
- If: $applicationPort.scope = public
Then:- $rule:
- ToPort: $hostPort
FromPort: $hostPortIpProtocol: toLower($applicationPort.protocol)External: true- $._environment.securityGroupManager.addGroupIngress($rule)
- $record:
port: $hostPortaddress: $.instance.ipAddresses[0]scope: cloudcontainerPort: $applicationPort.portportScope: $applicationPort.scopeprotocol: $applicationPort.protocolapplicationName: $container.name- $newEndpoints: $newEndpoints + list($record)
- If: $applicationPort.scope = public and $.instance.floatingIpAddress != null
Then:- $record.address: $.instance.floatingIpAddress
- $record.scope: public
- $newEndpoints: $newEndpoints + list($record)
- $volumeMap: {}
- For: path
In: $container.volumesDo:- $volume: $container.volumes.get($path)
- If: $volume.getType() = HostDir
Then:- $hostDir: $volume.getParameters()
- $volumeMap[$hostDir]: $path
- $._environment.reporter.report($this, 'Adding Docker Application')
- $resources: new(sys:Resources)
- $template: $resources.yaml('RunContainer.template').bind(dict(
appName => $container.name,image => $container.image,env => $container.env,portMap => $portBindings,volumeMap => $volumeMap,commands => $container.commands))- $._removeApplicationEndpoints($container.name)
- $privateIp: $.instance.agent.call($template, $resources)
- $record:
port: $applicationPort.portaddress: $privateIpscope: hostcontainerPort: $applicationPort.portportScope: $applicationPort.scopeprotocol: $applicationPort.protocolapplicationName: $container.name- $newEndpoints: $newEndpoints + list($record)
- $._environment.stack.push()
- If: not $container.name in $.containers
Then:- $.containers: $.containers + list($container.name)
- $.applicationEndpoints: $.applicationEndpoints + $newEndpoints
- Return: $.getEndpoints($container.name)
前面几步,判断该container是否存在,如果存在,删除- $._pullImage(image => $container.image)
这一步获取$container.image。中间到- $volumeMap: {}
之前的这一段就是为了组装portBindings和newEndpoints,接着组装volumeMap,完事儿之后呢获取RunContainer.template
。- $privateIp: $.instance.agent.call($template, $resources)
到这一步了自然就是告诉虚拟机,你该调用RunContainer.template
工作啦,RunContainer.template
中其实归根到底就是一段拼装好的执行docker run
命令的脚本。
从上面的分析可以看出来,DockerInterfacesLibrary
事实上是依赖DockerStandaloneHost
与 LinuxMuranoInstance
的这两个对象事实需要创建虚拟机的镜像中包含了murano-agent服务和docker服务的,DockerStandaloneHost
中封装了StandaloneHost对docker的一些操作,如docker run
、service docker start
等,LinuxMuranoInstance
中封装的是获取组装好的模版执行等功能。
以tomcat为例分析
DockerTomcat
Namespaces:=: io.murano.apps.docker
std: io.muranoName: DockerTomcatExtends: DockerApplicationProperties:name:Contract: $.string().notNull()publish:Contract: $.bool().notNull()Default: truepassword:Contract: $.string().notNull()Methods:initialize:Body:- $._environment: $.find(std:Environment).require()
- $._scope: switch($.publish, $ => public, not $ => internal)
getContainer:Body:Return:name: $.nameimage: 'tutum/tomcat'env:TOMCAT_PASS: $.passwordports:- port: 8080
scope: $._scopeonInstallationStart:Body:- $._environment.reporter.report($this, 'Installing Tomcat')
onInstallationFinish:Body:- If: $.publish
Then:- $endpoints: $.applicationEndpoints.where($.scope = $this._scope).
select(format('http://{0}:{1}', $.address, $.port))- $._environment.reporter.report($this, 'Tomcat {0} is available at {1}'.format($.name, join(', ', $endpoints)))
Else:- $._environment.reporter.report($this, 'Tomcat {0} has deployed but is not accessible from outside'.format($.name))
Extends: DockerApplication
直接表明,继承了DockerApplication,也就是上面分析的DockerApplication实例,此处只需要实现getContainer
和 onInstallationFinish
方法即可,deploy
会自动从DockerApplication继承,deploy
方法完成tomcat的具体安装
Murano之:集成docker相关推荐
- springboot项目集成docker
文章目录 一.docker常用命令 0.拉取镜像到本地仓库 1.查看所有镜像 2.创建一个新的容器并运行,返回的是容器的ID -- CONTAINER ID: 3.查看运行中的docker实例 4.查 ...
- 【7】idea集成docker部署项目
[7]idea集成docker部署项目 一.修改docker配置 1.1 修改服务器docker.service服务信息 允许其他主机远程访问服务器的docker vim /usr/lib/syste ...
- maven集成docker插件进行打包镜像并推送私服
使用maven进行集成docker打包成镜像以及推送到docker私服 先水几句 我不会开场啊-默默无闻的送码人.不是吧不是吧.现在还有人用maven打包,然后手动上传jar.然后进行部署吗?你out ...
- IDEA集成Docker插件实现项目打包镜像一键部署与Docker CA加密认证
IDEA集成Docker插件实现项目打包镜像一键部署与Docker CA加密认证 Docker开启远程访问 修改该Docker服务文件 加载配置与重启 验证是否开启成功 IDEA配置docker 编写 ...
- Spring Boot应用集成Docker并结合Log4j2、Kafka、ELK管理Docker日志
Preface 原文链接: http://yangbingdong.com/2018/spring-boot-docker-elk/ 微服务架构下,微服务在带来良好的设计和架构理念的同时,也带来了运维 ...
- DevOps实战系列【第八章】:详解Jenkins集成Docker私服Nexus3
个人亲自录制全套DevOps系列实战教程 :手把手教你玩转DevOps全栈技术 Jenkins集成Docker镜像仓库 docker私服已经搭建完毕,下边我们期望jenkins做的事是: ①通过git ...
- 使用IDEA集成docker部署springboot项目及bug解决并连同redis、MySQL
流程介绍 安装docker(windows) 配置docker源加速 docker安装redis IDEA集成docker # IDEA连接docker 配置springboot项目 打包成docke ...
- 集成docker jenkins github 发布运行
预备知识 docker 容器 jenkins 自动部署 https://jenkins.io/ git 服务器 我这里使用 github 还有其他可以选择的 gitlib gogs 实现一个简单的程序 ...
- 华为平板安装python_教你用树莓派安装集成docker版openwrt、homeassistant等及一些排坑指南...
教你用树莓派安装集成docker版openwrt.homeassistant等及一些排坑指南 2020-04-30 18:45:28 30点赞 290收藏 23评论 小编注:此篇文章来自即可瓜分10万 ...
最新文章
- P2924 [USACO08DEC]大栅栏Largest Fence
- CSP认证	201312-4有趣的数[C++题解]:组合数、数学
- mysql实现树形_Mysql实现树形递归查询
- 前端基础之操作标签—文档处理
- [html] html5都有哪些新的特性?移除了哪些元素?
- 安装MySql卡在Start Service的问题
- Java Web学习笔记08:分页技术
- 关于机器学习的十个实例
- ArcGIS操作小技巧(六)之Network Analyst工具条不能使用的解决方法
- 简易计算机系统综合设计设计报告(VHDL)
- Managing Configuration Data Programmatically in ASP.NET 2.0
- 色彩空间(CIE色度图,SRGB,AdobeRGB...)
- Hello World with Ant
- 自动切换输入法 for Mac(输入法辅助工具)
- LVDS 扫盲基础知识
- 英语12种记忆单词的方法
- 【命令】Java调用Windows运行命令打开\关闭软键盘
- error:Fatal error: Uncaught -- Smarty Compiler: Syntax error in template D:\sms\xampp\htdocs\lanyu
- NAS系列 硬件组装
- java Spring-Boot框架学习视频-百度云盘
热门文章
- 2005年度感动中国人物颁奖词
- matlab中reshape函数按行转换,Matlab中reshape函数的使用
- JavaScript常用的8个数组去重实战源码
- 基于Java+MySQL的三维模型素材交易平台设计
- emul11是鸿蒙吗,EMUI11什么时候更新-EMUI11有什么新功能
- 高并发编程-Thread#join方法的使用及使用场景分析
- spacy自然语言处理工具库--en_core_web_sm
- 电脑风扇声音大怎么办?五个好用的方法【完整教程】
- Linux shutdown命令
- 一加五t android p界面,一加6T出厂搭载Android P 将于11月5日发布