-
Notifications
You must be signed in to change notification settings - Fork 17
/
Copy pathsite.step-45-app-deploy.yml
199 lines (165 loc) · 7.95 KB
/
site.step-45-app-deploy.yml
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
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
- import_playbook: site.common.group-current-hosts.yml
- hosts: app:¤t:!immutable
pre_tasks:
- name: Release artifact sanity check failed
fail:
msg: |
====================================================
== FATAL! No valid release artifacts were found ==
====================================================
No valid composer.json has been found at:
{{ deploy_artifact_composer_json_local_path }}
TIPS:
- Is local artifact dir path is correct?
- Was the project built at least once successfully?
----------------------------------------------------
when: deploy_artifact_composer_json_data.require is not defined
- name: Print artifact composer package information
debug:
msg: |
=============================================
== Artifact Composer Package Information ==
=============================================
{% if deploy_artifact_composer_json_data.name is defined -%}
Main Package: {{ deploy_artifact_composer_json_data.name }}
{% endif %}
Dependencies:
{{ deploy_artifact_composer_json_data.require | to_nice_yaml }}
---------------------------------------------
- name: Set artifact build number fact if available
when: deploy_artifact_build_json_data.nr | default(false, true)
set_fact:
mageops_artifact_build_nr: "{{ deploy_artifact_build_json_data.nr }}"
- name: Check if previous release exists
stat:
path: "{{ deploy_current_release_dir }}"
failed_when: no
register: _current_release_check
- name: Set previous release existence fact
set_fact:
deploy_previous_release_exists: "{{ _current_release_check.stat is defined and _current_release_check.stat.islnk is defined and _current_release_check.stat.islnk }}"
- name: Gather deployment run facts
set_fact:
deploy_release_id: "{{ ansible_date_time.iso8601_basic_short }}"
deploy_keep_current_release: "{{ deploy_skip_installation | default(false) and deploy_previous_release_exists }}"
deploy_previous_release_id: "{{ deploy_previous_release_exists | ternary((_current_release_check.stat.lnk_target | default('')).rstrip('/').split('/') | last, false) }}"
- name: "Skipping installation: reusing previous release"
set_fact:
deploy_release_id: "{{ deploy_previous_release_id }}"
when: deploy_skip_installation | bool
- name: Compute release id
set_fact:
magento_release_id: "{{ deploy_keep_current_release | ternary(deploy_previous_release_id, deploy_release_id) }}"
- name: Print deployment run information
debug:
msg: |
========================================
== Starting Magento Deployment ==
========================================
Previous release id: {{ deploy_previous_release_id | ternary( deploy_previous_release_id, 'None - fresh install') }}
Deployed release id: {{ deploy_release_id }}
{{ deploy_keep_current_release | ternary('Code deploy is skipped!', 'New code will be deployed!') }}
----------------------------------------
roles:
- role: cs.aws-facts-all
aws_facts_gather_ami: no
delegate_to: localhost
delegate_facts: no
become: no
when: aws_use
- role: cs.switch-to-dnf
- role: cs.deploy
deploy_install_actions:
- name: Configure Magento
role: cs.magento-configure
deploy_install_abort: []
deploy_release_actions:
- name: Setup shared storage mounts
role: cs.magento-shared-storage
deploy_release_abort: []
deploy_post_actions:
- name: Link static files version dir
role: cs.magento-configure
tasks_from: 205-static-symlink.yml
- role: cs.aws-magento-cron
- role: cs.magento-preload-fscache
magento_preload_fscache_enable: "{{ mageops_magento_preload_fscache_enable }}"
- role: cs.magento-import-dispatcher
when: magento_import_dispatcher_enable
- role: cs.magento-cache-warmup-crawler
when: magento_page_cache_warmer_enable
- role: cs.php-opcache-prewarm
when: mageops_php_file_cache_web
- role: cs.pio
vars:
pio_tasks: app
when: mageops_pio_worker_enable
- role: cs.pkg-mgr-cleanup
tasks:
- name: Execute custom post deploy tasks
include_tasks: "{{ mageops_extra_tasks_deploy }}"
when: mageops_extra_tasks_deploy is defined and mageops_extra_tasks_deploy
- name: Save deploy release information to file
when: deploy_release_save_info_file_path | default(false, true)
copy:
dest: "{{ deploy_release_save_info_file_path }}"
content: "{{ deploy_release_info | to_nice_json }}"
vars:
deploy_release_info:
app_db_migrations_needed: "{{ magento_release_db_migrations_needed | default(none) }}"
app_db_migrations_info: "{{ magento_release_db_migrations_info | default(none) }}"
release_id: "{{ deploy_release_id | default(none) }}"
build_nr: "{{ mageops_artifact_build_nr | default(none) }}"
delegate_to: localhost
# This speeds up ami creation and starting new instance with asg
# This should be last step in on builder node
- name: Run fstrim to reduce ami size)
command: fstrim -av
when: mageops_fstrim_enable
vars:
deploy_install_new_release: "{{ not deploy_keep_current_release }}"
deploy_keep_current_releases: 2
deploy_copy_previous_release: yes
deploy_directory_permissions: "0775"
deploy_file_permissions: "0664"
deploy_app_user: "{{ magento_user }}"
deploy_app_group: "{{ magento_group }}"
deploy_ssh_key_path: "{{ mageops_ansible_temp_dir }}/ssh-deploy-key.{{ mageops_app_name }}"
deploy_webserver_user: nginx
deploy_root_dir: "{{ mageops_app_web_dir }}"
deploy_artifact_dir: "{{ deploy_artifact_local_path }}"
deploy_artifact_temp_dir: /tmp/ansible-deploy-artifacts-temp
deploy_releases_dir: "{{ deploy_root_dir }}/releases"
deploy_current_release_dir: "{{ deploy_root_dir }}/current"
deploy_shared_dirs_basic:
- 'pub/media'
- 'pub/shared'
- 'var/import'
- 'var/export'
- 'var/global'
deploy_shared_dirs: "{{ deploy_shared_dirs_basic + deploy_shared_dirs_extra }}"
deploy_writable_dirs:
- "var"
- "pub"
- "generated"
deploy_rsync_excludes: "{{ deploy_rsync_excludes_basic + deploy_rsync_excludes_extra }}"
deploy_copy_previous_excludes:
- "/var"
- "/generated"
deploy_perm_fix_find_opts: "-xdev"
deploy_restarted_services:
- php-fpm
- nginx
# Helper variables for sanity checks and messages
deploy_artifact_composer_json_local_path: "{{ deploy_artifact_local_path ~ '/composer.json' }}"
deploy_artifact_composer_json_data: "{{ lookup('file', deploy_artifact_composer_json_local_path, errors='warn', lstrip=true, rstrip=true) | default('{}', true) | from_json }}"
deploy_artifact_build_json_local_path: "{{ deploy_artifact_local_path ~ '/pub/BUILD.json' }}"
deploy_artifact_build_json_data: "{{ lookup('file', deploy_artifact_build_json_local_path, errors='warn', lstrip=true, rstrip=true) | default('{}', true) | from_json }}"
magento_core_config_settings: "{{ magento_core_config_settings_default + magento_core_config_settings_extra }}"
magento_core_config_settings_to_remove: "{{ magento_core_config_settings_to_remove_default + magento_core_config_settings_to_remove_extra }}"
magento_varnish_host: "{{ mageops_varnish_host }}"
magento_varnish_port: "{{ mageops_varnish_port }}"
magento_static_cache_dir: "{{ deploy_releases_dir }}/{{ deploy_release_id }}/pub/static/_cache"
magento_media_dir: "{{ mageops_app_web_dir }}/shared/pub/media"
magento_efs_app_mounts_extra: "{{ magento_efs_app_node_mounts }}"
magento_s3_app_mounts_extra: "{{ magento_s3fs_buckets_extra }}"