制作一个最简单的cartridge

尝试了2天,终于把最简单的如何做一个cartridge做成功了.......

制作过程参考了 https://www.openshift.com/blogs/new-openshift-cartridge-format-part-1 三部曲

自己制作的在 https://github.com/lukeyuan/simplecart 这个是弄了很久后后来重新制作一次成功的,前面问题多多啊-.-


这个cartridge的目录结构如下:

simplecart:
 -bin
  -control  控制Gear的脚本,现在只实现了start,stop,restart
  -setup  创建和更新时用的脚本,不过教程把它弄为空了
  -teardown
-env  环境变量的位置,我没有做任何改变
-etc
  -httpd.conf.erb  服务器配置文件
-logs
-metadata
  -managed_files.yml 管理.erb文件的
  -manifest.yml  表示整个cartridge的结构文件
-modules 软连接/usr/lib64/httpd/modules
-run
  -httpd.pid 这个文件是一定需要存在的,里面随便填个数字。如果不存在的话,服务器端apache的服务会直接起不来
-template  放置资源文件的
 -.openshift
 -index.html
-usr
-README.md

制作步骤如下:

1.在git上创建一个空repository,获得地址后克隆到本地,假设你改的repository名字为  hello,后面你的manifest里面的Name就是hello这个值了

2.在克隆下来的文件夹中,创建etc,logs,run,template文件夹

3.下载 https://github.com/openshift/origin-server/tree/master/cartridges/openshift-origin-cartridge-mock 或把整个origin-server源码打包下载https://github.com/openshift/origin-server/archive/master.zip 找到里面的/cartridges/openshift-origin-cartridge-mock。

把里面的bin,env,metadata,usr复制到刚才的目录下

bin中只留下 control,setup,teardown

在template文件夹下创建 .openshift 文件夹

4.把系统的httpd.conf复制到该目录的etc目录下,重命名为httpd.conf.erb,修改里面的Listen、ServerRoot、DocumentRoot,注释掉第221行#Include conf.d/*.conf

Listen <%= ENV['OPENSHIFT_ABC_IP']%>:<%=ENV['OPENSHIFT_ABC_PORT'] %>
ServerRoot "<%= ENV['OPENSHIFT_ABC_DIR'] %>"
DocumentRoot "<%= ENV['OPENSHIFT_REPO_DIR'] %>"

 需要注意的是ABC是manifest.yml里面Cartridge-Short-Name的对应值

5.改写managed_files.yml

---
locked_files:
- env/
- env/*
processed_templates:
- '**/*.erb'

6.改写manifest.yml

Name: hello
Cartridge-Short-Name: ABC
Display-Name: HTTPD Cartridge
Description: "A httpd cartridge for development use only."
Version: '0.1'
License: "None"
Vendor: Custom Cartridges Inc
Cartridge-Version: 0.0.1
Cartridge-Vendor: customcarts
Categories:
  - service
  - web_framework
Provides:
  - httpd
Cart-Data:
  - Key: OPENSHIFT_ABC_EXAMPLE
    Type: environment
    Description: "An example environment variable using ERB processing"
Group-Overrides:
  - components:
    - httpd
Subscribes:
  set-db-connection-info:
    Type: "NET_TCP:db:connection-info"
    Required: false
Endpoints:
  - Private-IP-Name:   IP
    Private-Port-Name: PORT
    Private-Port:      8080
    Public-Port-Name:  PROXY_PORT
    Mappings:
      - Frontend:      ""
        Backend:       ""
        Options:       { websocket: false }
 这里需要注意的是,层次一定要分明,否则会报错,Cartridge-Vendor只能是小写字母

7.改写bin/control

 /usr/sbin/httpd -f $OPENSHIFT_HTTPD_DIR/etc/httpd.conf -k start
  把function start{xxx},function stop{xxx},function restart{xxx}的内容改为上面的样子start,stop,restart

8.情况bin/setup

echo > bin/setup

9. ln -s /usr/lib64/httpd/modules/ modules
10.在manifest.yml中插入Source-Url: https://github.com/你的github账号/仓库名.git

    这样,openshift就会自动到那下载我们的cartridge了

11.最后,当然是上传到git上咯~

通过创建应用下面的coding anything选项,贴上manifest.yml的raw文件地址(找到你仓库中的manifest.yml,点击raw之后的网址),这样就能够创建了~

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值