我正在使用 Ansible 和 Docker 部署 ROR 应用程序,创建 Ruby Docker 映像并推送到 Docker HUB,Ansible 将应用程序从私有仓库克隆到目标服务器,成功创建了 docker 容器,但无法运行 Ruby 命令,例如捆绑安装、数据库迁移、Rake 任务。这些命令需要在从 Ansible Code 以交互模式部署时运行。
以及如何在使用 unicorn 运行上述任务后启动应用程序。
这是为了使用 Ansible 自动化部署过程,以前使用 Capistrano,但现在我们正在从 Capistrano 迁移到 Ansible。
---
- hosts: Ec2-Instance
become: true
tasks:
- name: Creating Deploy path
file:
state: directory
path: "/var/www/"
- name: Copying SSH Key | Temp
copy:
src: ~/.ssh/id_rsa
dest: ~/.ssh/id_rsa
owner: deployer
group: deployer
mode: 400
- name: Cloning a web application to the application path
git:
repo: private repo
version: master
dest: /var/www/app-path/
accept_hostkey: yes
register: git
- name: Remove SSH Key
shell: "sudo rm -rf ~/.ssh/id_rsa"
- name: Run Ruby Docker Container
docker_container:
name: 'container_name'
image: 'docker-hub/ruby-2.4.1:0.1'
tty: yes
detach: true
restart: yes # not required. Use with started state to force a matching container to be stopped and restarted.
interactive: yes # not required. Keep stdin open after a container is launched, even if not attached.
state: started
volumes: /var/www/app-path:/var/www/app-path/
working_dir: /var/www/app-path/
env:
gem_path: /var/www/app-path
gemfile: /var/www/app-path
bundler:
deployment_mode: production
我希望 Ansible Playbook 使用 Docker / Nginx / Unicorn 部署 Ruby on Rails 应用程序