aboutsummaryrefslogtreecommitdiffhomepage
path: root/tasks/deploy.yml
blob: 39b5845bc8f4734d5b66fb3504e15be6c1e93425 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
- name: Configure Drain
  when: syslog_server is defined or clever_syslog_server is defined
  command: "{{ ansible_env.HOME }}/{{ clever_user_path }}/clever-set-drain.sh"
  args:
    chdir: "{{ clever_app_root }}"
  environment:
    SYSLOG_UDP_SERVER: "{{ clever_syslog_server | default(syslog_server) }}"
    CONFIGURATION_FILE: "{{ clever_login_file }}"

- name: Configure Domain
  when: domain is defined or clever_domain is defined
  command: "{{ ansible_env.HOME }}/{{ clever_user_path }}/clever-set-domain.sh"
  args:
    chdir: "{{ clever_app_root }}"
  environment:
    DOMAIN: "{{ clever_domain | default(domain) }}"
    CONFIGURATION_FILE: "{{ clever_login_file }}"

- name: Configure Build Instance
  when: clever_build_flavor is defined
  command: "clever scale --build-flavor {{ clever_build_flavor }}"
  args:
    chdir: "{{ clever_app_root }}"
  environment:
    CONFIGURATION_FILE: "{{ clever_login_file }}"

- name: Configure Scalability
  when: clever_scaling is defined
  command: "{{ ansible_env.HOME }}/{{ clever_user_path }}/clever-set-scalability.sh"
  args:
    chdir: "{{ clever_app_root }}"
  environment:
    CONFIGURATION_FILE: "{{ clever_login_file }}"
    INSTANCES: "{{ clever_scaling.instances.fixed | default ('') }}"
    MIN_INSTANCES: "{{ clever_scaling.instances.min | default('') }}"
    MAX_INSTANCES: "{{ clever_scaling.instances.max | default('') }}"
    FLAVOR: "{{ clever_scaling.flavor.fixed | default('') }}"
    MIN_FLAVOR: "{{ clever_scaling.flavor.min | default('') }}"
    MAX_FLAVOR: "{{ clever_scaling.flavor.max | default('') }}"

- name: Configure service dependencies
  include_tasks: service-dep.yml
  vars:
    service_dep: "{{ item }}"
  with_items: "{{ clever_service_dependencies }}"

- name: Push Environment
  shell: "clever env import --json < {{ clever_app_confdir }}/env"
  args:
    chdir: "{{ clever_app_root }}"
  environment:
    CONFIGURATION_FILE: "{{ clever_login_file }}"
  changed_when: false

- name: Deploy to Clever-Cloud
  command: "{{ ansible_env.HOME }}/{{ clever_user_path }}/clever-deploy.sh"
  args:
    chdir: "{{ clever_app_root }}"
  environment:
    CONFIGURATION_FILE: "{{ clever_login_file }}"
  async: 2400 # 40 minutes
  poll: 0
  ignore_errors: true
  register: clever_deploy
  tags:
    - skip_ansible_lint

- name: Wait up to 40 minutes for deployment completion
  async_status:
    jid: "{{ clever_deploy.ansible_job_id }}"
  register: job_result
  until: job_result.finished
  ignore_errors: true
  delay: 30
  retries: 80 # 40 minutes (80 * 30 secs delay)

##################################################################
# Re-deploy only if its the first clever deploy for that project #
##################################################################

- name: Retry deploy to clever-cloud
  include_tasks: redeploy.yml
  when:
    - not job_result.finished or not job_result.rc == 0
    - job_result.stderr is defined
    - job_result.stderr is search("Failed to read git object")

- name: Restart app on clever-cloud when error asks to restart
  include_tasks: restart.yml
  when:
    - not job_result.finished or not job_result.rc == 0
    - job_result.stderr is defined
    - job_result.stderr is search("clever restart")

- name: Deploy logs (stdout)
  debug:
    var: job_result.stdout_lines
  when: job_result.stdout_lines is defined

- name: Deploy error logs (stderr)
  debug:
    var: job_result.stderr_lines
  when: job_result.stderr_lines is defined

- name: Fail in case of timeout or failure
  fail:
    msg: "Deployment failed. Please check logs above."
  when: not job_result.finished or not job_result.rc == 0