码迷,mamicode.com
首页 > 其他好文 > 详细

bashible docker集成使用

时间:2020-03-29 01:47:27      阅读:72      评论:0      收藏:0      [点我收藏+]

标签:keyword   osi   volume   http   tag   rip   rom   page   span   

bashible 是一个很不错的基于bash 的dsl 框架,类似ansible,但是简单使用也比较灵活,以下是集成docker 的使用
以下是一个集成openresty 的demo

集成bashible 的openresty 镜像

目的很简单,就是集成bashible到openresty 镜像中,方便测试以及生成配置,然后我们可以通过
docker 的multi stage 进行配置copy减少镜像的大小

  • Dockerfile
 
FROM openresty/openresty:1.15.8.3-stretch
RUN apt update && apt-get install -y wget net-tools
RUN wget https://raw.githubusercontent.com/mig1984/bashible/master/bashible
RUN wget https://raw.githubusercontent.com/mig1984/bashible/master/bashible.edit.bash
RUN wget https://raw.githubusercontent.com/mig1984/bashible/master/bashible.net.bash
RUN wget https://raw.githubusercontent.com/mig1984/bashible/master/bashible.template.bash
RUN wget https://raw.githubusercontent.com/mig1984/bashible/master/bashible.timeout.bash
RUN chmod 755 bashible && chmod 755 bashible.edit.bash && chmod 755 bashible.net.bash && chmod 755 bashible.template.bash && chmod 755 bashible.timeout.bash
RUN mv bashible /usr/local/bin && mv bashible.edit.bash /usr/local/bin && mv bashible.net.bash /usr/local/bin && mv bashible.template.bash /usr/local/bin && mv bashible.timeout.bash /usr/local/bin
CMD ["sh", "-c", "cd /opt/content/ && bashible t.bash && /usr/bin/openresty -g ‘daemon off;‘"]
  • 简单说明
    这个镜像约定bashible的配置都在/opt/content 中

简单使用

  • 项目结构
 
├── Dockerfile
├── Dockerfile-multi
├── README.md
├── content
├── index.html.tpl
├── js
├── bar.js
└── foo.js
├── parts
├── body.tpl
└── head.tpl
└── t.bash
└── docker-compose.yaml
  • 说明
    content 中为基于bashible 的nginx index.html 生成,使用了bashible 提供的模板技术
    t.bash:
 
use template
# set some variables for the template
FOO_OR_BAR=bar
@ Creating index page for home
  - output_to /usr/local/openresty/nginx/html/index.html template index.html.tpl

index.html.tpl:

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>bashible</title>
    $( template parts/head.tpl )
</head>
<body>
    $( template parts/body.tpl )
  </body>
</html>

head.tpl index 的头部,使用了cat 引入content

<script type=‘text/javascript‘>
  $( cat js/$FOO_OR_BAR.js )
</script>

body.tpl 使用了系统函数date

<div style="text-align:center">
<h1> Now is $( date ) </h1>
</div>
  • 多阶段集成使用
FROM dalongrong/openresty:bashible as build
WORKDIR /opt
COPY content/ /opt/content
RUN cd /opt/content/ && bashible t.bash
?
FROM openresty/openresty:alpine
COPY --from=build /usr/local/openresty/nginx/html/index.html /usr/local/openresty/nginx/html/index.html
  • docker-compose 文件
version: "3"
services: 
  web:
   build: 
    context: .
    dockerfile: Dockerfile-multi
   volumes: 
   - "./content/:/opt/content/"
   ports: 
   - "80:80"

说明

使用bashible 作为一个配置管理工具简洁、高效,同时集成在容器中也是一个很不错的选择

参考资料

https://hub.docker.com/repository/docker/dalongrong/openresty
https://hub.docker.com/repository/docker/dalongrong/bashible
https://github.com/mig1984/bashible

bashible docker集成使用

标签:keyword   osi   volume   http   tag   rip   rom   page   span   

原文地址:https://www.cnblogs.com/rongfengliang/p/12590264.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!