301 lines
9.6 KiB
YAML
301 lines
9.6 KiB
YAML
- name: Clone BlockScout
|
|
git:
|
|
repo: "{{ blockscout_repo }}"
|
|
dest: "/tmp/blockscout-{{ group_names[0] }}-{{ chain }}"
|
|
version: "{{ branch }}"
|
|
force: true
|
|
when: skip_fetch | bool != true
|
|
tags:
|
|
- build
|
|
|
|
- name: Git clean
|
|
command: "git clean -fdx"
|
|
args:
|
|
chdir: "/tmp/blockscout-{{ group_names[0] }}-{{ chain }}"
|
|
when: skip_fetch | bool != true
|
|
tags:
|
|
- build
|
|
|
|
- name: Merge branches
|
|
command: "git merge {{ merge_commit_item }}"
|
|
args:
|
|
chdir: "/tmp/blockscout-{{ group_names[0] }}-{{ chain }}"
|
|
when: merge_commit_item and not skip_fetch | bool
|
|
vars:
|
|
merge_commit_item: "{{ merge_commit | default(false) }}"
|
|
tags:
|
|
- build
|
|
|
|
- name: Remove static assets from previous deployment, if any
|
|
file:
|
|
path: "/tmp/blockscout-{{ group_names[0] }}-{{ chain }}/apps/block_scout_web/priv/static"
|
|
state: absent
|
|
tags:
|
|
- build
|
|
|
|
- name: Fetch environment variables (via access key)
|
|
set_fact:
|
|
env_compiled: "{{ 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 ) }}"
|
|
vars:
|
|
path: "/{{ group_names[0] }}/{{ chain }}"
|
|
when: aws_access_key is defined
|
|
tags:
|
|
- update_vars
|
|
- build
|
|
|
|
- name: Fetch environment variables (via profile)
|
|
set_fact:
|
|
env_compiled: "{{ lookup('aws_ssm', path, region=aws_region|default('us-east-1'), aws_profile=aws_profile, shortnames=true, bypath=true, recursive=true ) }}"
|
|
vars:
|
|
path: "/{{ group_names[0] }}/{{ chain }}"
|
|
when: aws_access_key is undefined
|
|
tags:
|
|
- update_vars
|
|
- build
|
|
|
|
- name: Make config variables lowercase
|
|
set_fact:
|
|
lower_env: "{{ lower_env | combine ({item.key|lower : item.value}) }}"
|
|
with_dict: "{{ env_vars }}"
|
|
when: env_vars is defined
|
|
vars:
|
|
lower_env: {}
|
|
tags:
|
|
- update_vars
|
|
- build
|
|
|
|
- name: Override env variables
|
|
set_fact:
|
|
env_compiled: "{{ env_compiled | combine(lower_env) }}"
|
|
when: lower_env is defined
|
|
tags:
|
|
- build
|
|
|
|
- name: Uppercase chain
|
|
set_fact:
|
|
upper_env: "{{ upper_env | combine ({item.key|upper : item.value}) }}"
|
|
with_dict: "{{ env_compiled }}"
|
|
vars:
|
|
upper_env: {}
|
|
tags:
|
|
- build
|
|
|
|
- name: Add server port
|
|
set_fact:
|
|
server_port: "{{ 65535|random(seed=inventory_hostname,start=1024) }}"
|
|
tags:
|
|
- build
|
|
|
|
- name: Combine server env
|
|
set_fact:
|
|
server_env: "{{ upper_env | combine({'NETWORK_PATH':'/','PORT':server_port}) }}"
|
|
tags:
|
|
- build
|
|
|
|
- name: Override build variables
|
|
set_fact:
|
|
server_env: "{{ server_env | combine({item.key|regex_replace('BUILD_'):item.value}) if item.key | search('BUILD_') else server_env }}"
|
|
with_dict: "{{ server_env }}"
|
|
tags:
|
|
- build
|
|
|
|
- name: Show Server environment variables
|
|
debug:
|
|
var: server_env
|
|
|
|
- name: Compile BlockScout
|
|
command: "mix do {{ item }}"
|
|
args:
|
|
chdir: "/tmp/blockscout-{{ group_names[0] }}-{{ chain }}"
|
|
environment: "{{ server_env }}"
|
|
with_items:
|
|
- deps.get
|
|
- local.rebar --force
|
|
- deps.compile
|
|
- compile
|
|
- ecto.drop
|
|
- ecto.create
|
|
- ecto.migrate
|
|
tags:
|
|
- build
|
|
|
|
- name: Install Node modules at apps/block_scout_web/assets
|
|
environment: "{{ server_env }}"
|
|
command: npm install
|
|
args:
|
|
chdir: "/tmp/blockscout-{{ group_names[0] }}-{{ chain }}/apps/block_scout_web/assets"
|
|
tags:
|
|
- build
|
|
|
|
- name: Execute webpack.js at apps/block_scout_web/assets/node_modules/webpack/bin
|
|
environment: "{{ server_env }}"
|
|
command: node_modules/webpack/bin/webpack.js --mode production
|
|
args:
|
|
chdir: "/tmp/blockscout-{{ group_names[0] }}-{{ chain }}/apps/block_scout_web/assets"
|
|
tags:
|
|
- build
|
|
|
|
- name: Instal Node modules at apps/explorer
|
|
environment: "{{ server_env }}"
|
|
command: npm install
|
|
args:
|
|
chdir: "/tmp/blockscout-{{ group_names[0] }}-{{ chain }}/apps/explorer"
|
|
tags:
|
|
- build
|
|
|
|
- name: Install SSL certificates
|
|
environment: "{{ server_env }}"
|
|
command: mix phx.gen.cert blockscout blockscout.local
|
|
args:
|
|
chdir: "/tmp/blockscout-{{ group_names[0] }}-{{ chain }}/apps/block_scout_web"
|
|
tags:
|
|
- build
|
|
|
|
- name: Start server
|
|
tags:
|
|
- build
|
|
block:
|
|
- name: Start server
|
|
command: "mix phx.server"
|
|
environment: "{{ server_env }}"
|
|
args:
|
|
chdir: "/tmp/blockscout-{{ group_names[0] }}-{{ chain }}"
|
|
async: 10000
|
|
poll: 0
|
|
|
|
- debug:
|
|
msg: "Please, open your browser at following addresses:"
|
|
run_once: true
|
|
|
|
- debug:
|
|
msg: "{{ ansible_host }}:{{ server_port }}"
|
|
|
|
- name: User prompt
|
|
pause:
|
|
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
|
|
always:
|
|
- name: kill server
|
|
command: "pkill -f {{ item }}"
|
|
with_items:
|
|
- beam.smp
|
|
- webpack.js
|
|
failed_when: false
|
|
|
|
- name: Check for execution interrupt
|
|
fail:
|
|
msg: "Execution aborted"
|
|
when: prompt is failed
|
|
tags:
|
|
- build
|
|
|
|
- name: Build static assets
|
|
environment: "{{ server_env }}"
|
|
command: mix phx.digest
|
|
args:
|
|
chdir: "/tmp/blockscout-{{ group_names[0] }}-{{ chain }}"
|
|
tags:
|
|
- build
|
|
|
|
- name: User prompt
|
|
pause:
|
|
prompt: "Would you like to remove staging dependencies? [Yes[Enter]/No]"
|
|
register: user_answer
|
|
until: user_answer.user_input | lower in conditional
|
|
retries: 10000
|
|
delay: 1
|
|
vars:
|
|
conditional: ["",'yes','no','true','false']
|
|
when: inventory_hostname == groups['all'][0]
|
|
tags:
|
|
- build
|
|
|
|
- name: Remove dev dependencies
|
|
file:
|
|
state: absent
|
|
path: "{{ item }}"
|
|
with_items:
|
|
- "/tmp/blockscout-{{ group_names[0] }}-{{ chain }}/_build/"
|
|
- "/tmp/blockscout-{{ group_names[0] }}-{{ chain }}/deps/"
|
|
- "/tmp/blockscout-{{ group_names[0] }}-{{ chain }}/apps/block_scout_web/assets/node_modules/"
|
|
- "/tmp/blockscout-{{ group_names[0] }}-{{ chain }}/apps/explorer/node_modules/"
|
|
- "/tmp/blockscout-{{ group_names[0] }}-{{ chain }}/logs/dev/"
|
|
when: hostvars[groups['all'][0]].user_answer.user_input == "" or hostvars[groups['all'][0]].user_answer.user_input | lower | bool
|
|
tags:
|
|
- build
|
|
|
|
- name: Fix bug with favicon
|
|
replace:
|
|
regexp: '\"favicon\.ico\"\:\"favicon-[a-z0-9]+?\.ico\"'
|
|
replace: '"images/favicon.ico":"favicon.ico"'
|
|
path: "/tmp/blockscout-{{ group_names[0] }}-{{ chain }}/apps/block_scout_web/priv/static/cache_manifest.json"
|
|
tags:
|
|
- build
|
|
|
|
- name: User prompt
|
|
pause:
|
|
prompt: "Do you want to update the Parameter Store variables? [Yes[Enter]/No]"
|
|
register: user_answer
|
|
until: user_answer.user_input | lower in conditional
|
|
retries: 10000
|
|
delay: 1
|
|
vars:
|
|
conditional: ["",'yes','no','true','false']
|
|
when: inventory_hostname == groups['all'][0]
|
|
tags:
|
|
- update_vars
|
|
|
|
- name: Update chain variables
|
|
aws_ssm_parameter_store:
|
|
name: "/{{ group_names[0] }}/{{ chain }}/{{ item.key }}"
|
|
value: "{{ item.value }}"
|
|
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) }}"
|
|
with_dict: "{{ lower_env | default({}) }}"
|
|
when: hostvars[groups['all'][0]].user_answer.user_input == "" or hostvars[groups['all'][0]].user_answer.user_input | lower | bool
|
|
tags:
|
|
- update_vars
|
|
|
|
- name: User prompt
|
|
pause:
|
|
prompt: "Do you want to deploy BlockScout? [Yes[Enter]/No]"
|
|
register: user_answer
|
|
until: user_answer.user_input | lower in conditional
|
|
retries: 10000
|
|
delay: 1
|
|
vars:
|
|
conditional: ["",'yes','no','true','false']
|
|
when: inventory_hostname == groups['all'][0]
|
|
tags:
|
|
- deploy
|
|
|
|
- name: Upload Blockscout to S3
|
|
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=/tmp/blockscout-{{ group_names[0] }}-{{ chain }} {{ '--profile='~aws_profile~' --region='~aws_region if aws_profile is defined else '' }}"
|
|
register: push_output
|
|
when: hostvars[groups['all'][0]].user_answer.user_input == "" or hostvars[groups['all'][0]].user_answer.user_input | lower | bool
|
|
tags:
|
|
- deploy
|
|
|
|
- name: Upload output
|
|
debug:
|
|
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~' --region'~aws_region if aws_profile is defined else '' }}"
|
|
when: hostvars[groups['all'][0]].user_answer.user_input == "" or hostvars[groups['all'][0]].user_answer.user_input | lower | bool
|
|
tags:
|
|
- deploy
|
|
|
|
|
|
- name: Deploy Blockscout
|
|
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 {{ '--profile='~aws_profile~' --region='~aws_region if aws_profile is defined else '' }}"
|
|
when: hostvars[groups['all'][0]].user_answer.user_input == "" or hostvars[groups['all'][0]].user_answer.user_input | lower | bool
|
|
tags:
|
|
- deploy
|
|
|