2019-03-19 10:09:10 -07:00
- name : Clone BlockScout
git :
repo : "{{ blockscout_repo }}"
2019-05-20 13:38:14 -07:00
dest : "blockscout-{{ group_names[0] }}-{{ chain }}"
version : "{{ branch }}"
2019-03-19 10:09:10 -07:00
force : true
when : skip_fetch | bool != true
2019-03-20 09:20:47 -07:00
- name : Git clean
command : "git clean -fdx"
args :
2019-05-20 13:38:14 -07:00
chdir : "blockscout-{{ group_names[0] }}-{{ chain }}"
2019-03-20 09:20:47 -07:00
when : skip_fetch | bool != true
2019-03-19 10:09:10 -07:00
- name : Merge branches
2019-05-20 13:38:14 -07:00
command : "git merge {{ merge_commit_item }}"
2019-03-19 10:09:10 -07:00
args :
2019-05-20 13:38:14 -07:00
chdir : "blockscout-{{ group_names[0] }}-{{ chain }}"
when : merge_commit_item and not skip_fetch | bool
2019-03-19 10:09:10 -07:00
vars :
2019-05-20 13:38:14 -07:00
merge_commit_item : "{{ merge_commit | default(false) }}"
2019-03-19 10:09:10 -07:00
- name : Copy web config files
copy :
2019-05-20 13:38:14 -07:00
src : "blockscout-{{ group_names[0] }}-{{ chain }}/apps/block_scout_web/config/dev.secret.exs.example"
dest : "blockscout-{{ group_names[0] }}-{{ chain }}/apps/block_scout_web/config/dev.secret.exs"
2019-03-19 10:09:10 -07:00
2019-05-20 13:38:14 -07:00
- name : Template explorer config files
2019-03-19 10:09:10 -07:00
template :
src : dev.secret.exs.j2
2019-05-20 13:38:14 -07:00
dest : "blockscout-{{ group_names[0] }}-{{ chain }}/apps/explorer/config/dev.secret.exs"
when : ps_user is defined
2019-04-23 17:02:33 -07:00
- name : Copy default explorer config files
copy :
2019-05-20 13:38:14 -07:00
src : "blockscout-{{ group_names[0] }}-{{ chain }}/apps/explorer/config/dev.secret.exs.example"
dest : "blockscout-{{ group_names[0] }}-{{ chain }}/apps/explorer/config/dev.secret.exs"
when : ps_user is undefined or ps_user == ""
2019-03-19 10:09:10 -07:00
- name : Remove static assets from previous deployment, if any
file :
2019-05-20 13:38:14 -07:00
path : "blockscout-{{ group_names[0] }}-{{ chain }}/apps/block_scout_web/priv/static"
2019-03-19 10:09:10 -07:00
state : absent
- name : Compile BlockScout
2019-03-20 09:20:47 -07:00
command : "mix do {{ item }}"
2019-03-19 10:09:10 -07:00
args :
2019-05-20 13:38:14 -07:00
chdir : "blockscout-{{ group_names[0] }}-{{ chain }}"
2019-03-20 09:20:47 -07:00
with_items :
- deps.get
- local.rebar --force
- deps.compile
- compile
- ecto.drop
- ecto.create
- ecto.migrate
2019-03-19 10:09:10 -07:00
- name : Install Node modules at apps/block_scout_web/assets
2019-03-20 09:20:47 -07:00
command : npm install
2019-03-19 10:09:10 -07:00
args :
2019-05-20 13:38:14 -07:00
chdir : "blockscout-{{ group_names[0] }}-{{ chain }}/apps/block_scout_web/assets"
2019-03-19 10:09:10 -07:00
2019-03-20 09:20:47 -07:00
- name : Execute webpack.js at apps/block_scout_web/assets/node_modules/webpack/bin
command : node_modules/webpack/bin/webpack.js --mode production
args :
2019-05-20 13:38:14 -07:00
chdir : "blockscout-{{ group_names[0] }}-{{ chain }}/apps/block_scout_web/assets"
2019-03-20 09:20:47 -07:00
2019-03-19 10:09:10 -07:00
- name : Instal Node modules at apps/explorer
command : npm install
args :
2019-05-20 13:38:14 -07:00
chdir : "blockscout-{{ group_names[0] }}-{{ chain }}/apps/explorer"
2019-03-19 10:09:10 -07:00
- name : Install SSL certificates
command : mix phx.gen.cert blockscout blockscout.local
args :
2019-05-20 13:38:14 -07:00
chdir : "blockscout-{{ group_names[0] }}-{{ chain }}/apps/block_scout_web"
2019-03-19 10:09:10 -07:00
2019-04-23 17:02:33 -07:00
- name : Fetch environment variables (via access key)
2019-03-27 08:32:51 -07:00
set_fact :
2019-05-20 13:38:14 -07:00
env : "{{ lookup('aws_ssm', path, aws_access_key=aws_access_key, aws_secret_key=aws_secret_key, region=aws_region|default('us-east-1'), shortnames=true, bypath=true, recursive=true ) }}"
2019-03-27 08:32:51 -07:00
vars :
2019-05-20 13:38:14 -07:00
path : "/{{ group_names[0] }}/{{ chain }}"
2019-04-23 17:02:33 -07:00
when : aws_access_key is defined
- name : Fetch environment variables (via profile)
set_fact :
2019-05-20 13:38:14 -07:00
env_compiled : "{{ lookup('aws_ssm', path, aws_profile=aws_profile, shortnames=true, bypath=true, recursive=true ) }}"
2019-04-23 17:02:33 -07:00
vars :
2019-05-20 13:38:14 -07:00
path : "/{{ group_names[0] }}/{{ chain }}"
2019-05-01 12:26:39 -07:00
when : aws_access_key is undefined
2019-03-27 08:32:51 -07:00
2019-04-18 07:12:21 -07:00
- name : Make config variables lowercase
2019-03-27 08:32:51 -07:00
set_fact :
2019-05-20 13:38:14 -07:00
lower_env : "{{ lower_env | combine ({item.key|lower : item.value}) }}"
with_dict : "{{ custom_environment_chain }}"
when : custom_environment_chain|length > 0
2019-03-27 08:32:51 -07:00
vars :
2019-05-20 13:38:14 -07:00
lower_env : {}
custom_environment_chain : "{{ env_vars | default({}) if env_vars>0 else {} }}"
2019-04-18 07:12:21 -07:00
- name : Override env variables
set_fact :
2019-05-20 13:38:14 -07:00
env_compiled : "{{ env_compilated | combine(lower_env) }}"
when : lower_env is defined
2019-03-27 08:32:51 -07:00
- name : Uppercase chain
set_fact :
2019-05-20 13:38:14 -07:00
upper_env : "{{ upper_env | combine ({item.key|upper : item.value}) }}"
with_dict : "{{ env_compiled }}"
2019-03-27 08:32:51 -07:00
vars :
2019-05-20 13:38:14 -07:00
upper_env : {}
2019-03-27 08:32:51 -07:00
2019-03-19 10:09:10 -07:00
- name : Start server
2019-03-20 09:20:47 -07:00
block :
2019-05-20 13:38:14 -07:00
- set_fact :
server_port : "{{ 65535|random(seed=inventory_hostname,start=1024) }}"
- set_fact :
server_env : "{{ upper_env | combine({'NETWORK_PATH':'/','PORT':server_port,'MIX_ENV':'prod'}) }}"
2019-03-20 09:20:47 -07:00
- name : Start server
command : "mix phx.server"
2019-05-20 13:38:14 -07:00
environment : "{{ server_env }}"
2019-03-20 09:20:47 -07:00
args :
2019-05-20 13:38:14 -07:00
chdir : "blockscout-{{ group_names[0] }}-{{ chain }}"
2019-03-20 09:20:47 -07:00
async : 10000
poll : 0
2019-05-20 13:38:14 -07:00
- debug :
msg : "Please, open your browser at following addresses:"
run_once : true
- debug :
msg : "{{ ansible_host }}:{{ server_port }}"
2019-03-20 09:20:47 -07:00
- name : User prompt
pause :
2019-05-20 13:38:14 -07:00
prompt : "BlockScout should appear. Ensure that there is no visual artifacts and then press Enter to continue. Press Ctrl+C and then A if you face any issues to cancel the deployment. Note: Localhost stands for the machine were Ansible is currently run."
run_once : true
register : prompt
2019-03-20 09:20:47 -07:00
always :
- name : kill server
2019-04-23 17:02:33 -07:00
command : "pkill -f {{ item }}"
2019-03-20 09:20:47 -07:00
with_items :
- beam.smp
2019-05-20 13:38:14 -07:00
- webpack.js
failed_when : false
- name : Check for execution interrupt
fail :
msg : "Execution aborted"
when : prompt is failed
2019-03-20 09:20:47 -07:00
2019-03-19 10:09:10 -07:00
- name : Build static assets
command : mix phx.digest
args :
2019-05-20 13:38:14 -07:00
chdir : "blockscout-{{ group_names[0] }}-{{ chain }}"
2019-03-19 10:09:10 -07:00
2019-03-27 08:32:51 -07:00
- name : User prompt
pause :
2019-04-17 07:15:45 -07:00
prompt : "Would you like to remove staging dependencies? [Yes/No] Default: Yes"
2019-03-27 08:32:51 -07:00
register : user_answer
2019-05-20 13:38:14 -07:00
until : user_answer.user_input|lower != "false" and user_answer.user_input|lower != "no" and user_answer.user_input|lower != "true" and user_answer.user_input|lower != "yes"
retries : 10000
delay : 1
2019-03-27 08:32:51 -07:00
2019-03-19 10:09:10 -07:00
- name : Remove dev dependencies
file :
state : absent
path : "{{ item }}"
with_items :
2019-05-20 13:38:14 -07:00
- "blockscout-{{ group_names[0] }}-{{ chain }}/_build/"
- "blockscout-{{ group_names[0] }}-{{ chain }}/deps/"
- "blockscout-{{ group_names[0] }}-{{ chain }}/apps/block_scout_web/assets/node_modules/"
- "blockscout-{{ group_names[0] }}-{{ chain }}/apps/explorer/node_modules/"
- "blockscout-{{ group_names[0] }}-{{ chain }}/logs/dev/"
when : user_answer.user_input | lower | bool
2019-03-19 10:09:10 -07:00
2019-04-16 04:58:25 -07:00
- name : Fix bug with favicon
2019-04-30 03:19:13 -07:00
replace :
2019-05-02 09:42:17 -07:00
regexp : '\"favicon\.ico\"\:\"favicon-[a-z0-9]+?\.ico\"'
replace : '"images/favicon.ico":"favicon.ico"'
2019-05-20 13:38:14 -07:00
path : "blockscout-{{ group_names[0] }}-{{ chain }}/apps/block_scout_web/priv/static/cache_manifest.json"
2019-04-16 04:58:25 -07:00
2019-03-19 10:09:10 -07:00
- name : Upload Blockscout to S3
2019-05-20 13:38:14 -07:00
command : "{{ 'AWS_ACCESS_KEY='~aws_access_key~' AWS_SECRET_ACCESS_KEY='~aws_secret_key~' AWS_DEFAULT_REGION='~aws_region if aws_profile is undefined else '' }} aws deploy push --application-name={{ group_names[0] }}-explorer --s3-location s3://{{ group_names[0] }}-explorer-codedeploy-releases/blockscout-{{ group_names[0] }}-{{ chain }}.zip --source=blockscout-{{ group_names[0] }}-{{ chain }} {{ '--profile='~aws_profile if aws_profile is defined else '' }}"
2019-03-19 10:09:10 -07:00
register : push_output
2019-03-27 08:32:51 -07:00
- name : Upload output
debug :
2019-04-24 04:30:29 -07:00
msg : "If deployment will fail, you can try to deploy blockscout manually using the following commands: {{ 'AWS_ACCESS_KEY=XXXXXXXXXXXXXX AWS_SECRET_ACCESS_KEY=XXXXXXXXXXXX AWS_DEFAULT_REGION='~aws_region if aws_profile is undefined else '' }} {{ push_output.stdout_lines }} {{ '--profile='~aws_profile if aws_profile is defined else '' }}"
2019-03-27 08:32:51 -07:00
2019-03-19 10:09:10 -07:00
- name : User prompt
pause :
2019-04-17 07:15:45 -07:00
prompt : "Do you want to update the Parameter Store variables? [Yes/No] Default: Yes"
2019-03-19 10:09:10 -07:00
register : user_answer
2019-05-20 13:38:14 -07:00
until : user_answer.user_input | lower != "false" and user_answer.user_input | lower != "no" and user_answer.user_input | lower != "true" and user_answer.user_input | lower != "yes"
retries : 10000
delay : 1
2019-03-19 10:09:10 -07:00
- name : Update chain variables
aws_ssm_parameter_store :
2019-05-20 13:38:14 -07:00
name : "/{{ group_names[0] }}/{{ chain }}/{{ item.key }}"
2019-03-19 10:09:10 -07:00
value : "{{ item.value }}"
2019-04-23 17:02:33 -07:00
profile : "{{ profile }}"
aws_access_key : "{{ access_key }}"
aws_secret_key : "{{ secret_key }}"
region : "{{ region }}"
vars :
access_key : "{{ aws_access_key|default(omit) }}"
secret_key : "{{ aws_secret_key|default(omit) }}"
profile : "{{ aws_profile|default(omit) }}"
region : "{{ aws_region|default(omit) }}"
2019-05-20 13:38:14 -07:00
with_dict : "{{ lower_env }}"
when : user_answer.user_input | lower | bool
2019-03-27 08:32:51 -07:00
- name : User prompt
pause :
2019-04-17 07:15:45 -07:00
prompt : "Do you want to deploy BlockScout? [Yes/No] Default: Yes"
2019-03-27 08:32:51 -07:00
register : user_answer
2019-05-20 13:38:14 -07:00
until : user_answer.user_input | lower != "false" and user_answer.user_input | lower != "no" and user_answer.user_input | lower != "true" and user_answer.user_input | lower != "yes"
retries : 10000
delay : 1
2019-03-19 10:09:10 -07:00
- name : Deploy Blockscout
2019-05-20 13:38:14 -07:00
command : "{{ 'AWS_ACCESS_KEY='~aws_access_key~' AWS_SECRET_ACCESS_KEY='~aws_secret_key~' AWS_DEFAULT_REGION='~aws_region if aws_profile is undefined else '' }} {{ push_output.stdout_lines[1] }} --deployment-group-name {{ group_names[0] }}-explorer-dg{{ groups[group_names[0]].index(inventory_hostname) }} --deployment-config-name CodeDeployDefault.OneAtATime --description '{{ env_compiled['BLOCKSCOUT_VERSION'] }}' {{ '--profile='~aws_profile if aws_profile is defined else '' }}"
when : user_answer.user_input | lower | bool