2016-11-16 63 views
1

我目前正在建立一个依赖Salt和Docker的部署系统。为了简单起见,假设我想在同一台服务器上为2个客户端部署一个gitlab。组织支柱和州部署码头集装箱用盐

我的应用程序的所有参数都存储在Pillar中。

猫/srv/pillar/top.sls

'myminion': 
- client1.git 
- client2.git 

猫/srv/pillar/client1/git.sls

gitlab: 
    client1: 
     domains: 
      - git.client1.net 
     container_no : 1 

猫/ srv/pillar/client2/git.sls

gitlab: 
    client2: 
     domains: 
      - git.client2.com 
     container_no : 2 

到目前为止,我的Salt状态包含部署不同应用程序配置文件(Django,NodeJS,Gitlab ...)的具体说明。对于Gitlab这将是:

$猫/srv/salt/profile/gitlab/init.sls

{% for app_name,config in pillar.get('gitlab', {}).items() %} 
configure reverse proxy for {{app_name}}: 
    module.run: 
    - name: haproxyctl.add 
    - app_name: {{app_name}} 
    - domains: {{ config['domains'] }} 

[...] 
{% endfor %} 

,一切工作正常。但有了这个,我无法一次部署一个应用程序。我要做的:

盐myminion state.apply profile.gitlab

,这将部署在服务器上的所有应用程序gitlab。但我想只能触发一个应用程序。

我并没有长时间玩Salt,但我觉得在所有应用程序上的这种循环并不是一个完美的工作方式。咸的方法是什么?

+0

现在有一个简短的猜测 - 你可以让循环内部的所有状态都需要你的第一个'git.latest'状态 - 这种方式只有在有新版本时才能执行。这实际上意味着你仍然应用一切 - 但只有所有状态,如果有变化...... – dahrens

+0

但是,如果我正确理解你说的话,这也意味着我必须为每个应用程序编写一个状态文件,而现在我只需要在支柱中声明另一组参数,并且我的新应用程序将与gitlab配置文件状态一起部署。 – Plup

回答

1

我想在评论中说的并不强制你为每个应用程序创建状态文件。想想这样的事情:

{% for app_name,config in pillar.get('gitlab', {}).items() %} 
fetch_{{app_name}}: 
    git.latest: 
    - name: https://mydomain.tld/apps/foo.git 
    - target: /var/www/foo 
haproxy_{{app_name}}: 
    module.run: 
    - name: haproxyctl.add 
    - app_name: {{app_name}} 
    - domains: {{ config['domains'] }} 
    - onchanges: 
     - git: fetch_{{app_name}} 
# all following states should "listen to" the git.latest state 
[...] 
{% endfor %} 

这样,你仍然可以直接触发一个应用程序在你的奴才要升级,但实际上盐将只执行所有关于是否有某个应用程序状态存储库中的更改。

这不完全是你要求的 - 但它可能是一个可能的解决方案。

Read more about requisites

+0

确实,这不是我想要的,但我会试一试。谢谢。 – Plup