f500.project_deploy_module

项目部署模块 (deploy_helper)

这个模块是为 ansible-modules-extra 提出的 deploy_helper 模块。

一般说明,从一个项目的示例文件夹结构开始:

根目录: 发布: - 20140415234508 - 20140415235146 - 20140416082818

共享:
    - 会话
    - 上传

当前:-> 发布/20140416082818

“发布”文件夹包含所有可用的版本。一个版本是要部署的应用程序的完整构建。这可以是一个代码库的克隆,或者是你文件系统上本地文件夹的同步。使用带时间戳的文件夹是一种区分不同版本的方法,但你也可以选择自己的策略,比如使用 git 标签或提交哈希值。

在部署过程中,应该在发布文件夹中创建一个新文件夹,并执行所需的构建步骤。当新构建准备好后,部署过程通过用新构建替换“当前”符号链接来“完成”。

“共享”文件夹包含在不同版本间共享的任何资源。这些资源的例子包括 web 服务器的会话文件,或用户上传的文件。通常会在一个发布文件夹中创建指向共享/子文件夹的符号链接,创建这些链接的过程会作为构建步骤的一部分自动化。

“当前”符号链接指向其中一个版本。通常是最新的版本,除非有正在进行的部署。项目的 web 服务器根目录会通过这个符号链接访问,因此切换到新版本时的“停机时间”仅限于切换链接所需的时间。

为了区分成功构建和未完成的构建,可以在当前正在进行的版本的文件夹中放置一个文件。这个文件的存在将标记其为未完成,并允许在清理时自动删除它。

典型用法:

- name: 初始化部署根目录并收集信息
  deploy_helper: path=/path/to/root
- name: 将项目克隆到新的发布文件夹
  git: repo=git://foosball.example.org/path/to/repo.git dest={{ deploy_helper.new_release_path }} version=v1.1.1
- name: 添加未完成文件,以便在成功完成时进行清理
  file: path={{ deploy_helper.new_release_path }}/{{ deploy_helper.unfinished_filename }} state=touch
- name: 执行一些构建步骤,比如运行依赖管理工具
  composer: command=install working_dir={{ deploy_helper.new_release_path }}
- name: 在共享文件夹中创建一些文件夹
  file: path='{{ deploy_helper.shared_path }}/{{ item }}' state=directory
  with_items: ['sessions', 'uploads']
- name: 从新版本添加到共享文件夹的符号链接
  file: path='{{ deploy_helper.new_release_path }}/{{ item.path }}'
        src='{{ deploy_helper.shared_path }}/{{ item.src }}'
        state=link
  with_items:
      - { path: "app/sessions", src: "sessions" }
      - { path: "web/uploads",  src: "uploads" }
- name: 完成部署,删除未完成文件并切换符号链接
  deploy_helper: path=/path/to/root release={{ deploy_helper.new_release }} state=finalize

在运行部署前获取信息

- name: 运行 'state=query' 收集信息而不改变任何内容
  deploy_helper: path=/path/to/root state=query

记得在稍后实际调用 'state=present' 时设置 'release' 参数

- name: 初始化部署根目录
  deploy_helper: path=/path/to/root release={{ deploy_helper.new_release }} state=present

所有路径都可以是绝对路径或相对路径(相对于 'path' 参数)

- deploy_helper: path=/path/to/root
                 releases_path=/var/www/project/releases
                 shared_path=/var/www/shared
                 current_path=/var/www/active

使用自己的版本命名策略(在这种情况下是版本标签):

- deploy_helper: path=/path/to/root release=v1.1.1 state=present
- deploy_helper: path=/path/to/root release={{ deploy_helper.new_release }} state=finalize

使用不同的未完成文件名:

- deploy_helper: path=/path/to/root
                 unfinished_filename=README.md
                 release={{ deploy_helper.new_release }}
                 state=finalize

推迟清理旧版本:

- deploy_helper: path=/path/to/root release={{ deploy_helper.new_release }} state=finalize clean=False
- deploy_helper: path=/path/to/root state=clean

或者在新部署前进行清理

- deploy_helper: path=/path/to/root state=clean
- deploy_helper: path=/path/to/root state=present

保留更多旧版本:

- deploy_helper: path=/path/to/root release={{ deploy_helper.new_release }} state=finalize keep_releases=10

或者,如果在完成时使用 'clean=false':

- deploy_helper: path=/path/to/root state=clean keep_releases=10

删除整个项目根文件夹

- deploy_helper: path=/path/to/root state=absent

调试模块返回的信息

- deploy_helper: path=/path/to/root
- debug: var=deploy_helper

许可证

LGPL

作者信息

Ramon de la Fuente,ramon@delafuente.nl

关于项目

Deploy_helper module for building (Capistrano like) deploy roles

安装
ansible-galaxy install f500.project_deploy_module
许可证
lgpl-3.0
下载
6.8k
拥有者
Open source contributions by Future500