Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Test ygtc devops #2

Open
wants to merge 22 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
64 changes: 64 additions & 0 deletions devops/reinstall/docker_sql_workflow.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
---
# This script contains commands to manage "Docker SQL workflow":
# - Running registry rebuild (when modules have been moved to new directory)
# - Running database updates

- name: Exising container name is...
debug: msg={{ existing_container_name }}
when: existing_container_name is defined

# Vagrant build.
- name: Delete old container
shell: docker rm -f {{ mysql_db }}
when: existing_container_name is undefined and (pp_environment == "default" and ((ansible_env.USER is not defined or ansible_env.USER != "{{ ci_server_username }}") and (ansible_env.SUDO_USER is not defined or ansible_env.SUDO_USER != "{{ ci_server_username }}")))
ignore_errors: true

- name: Enable insecure registry for docker
lineinfile: dest='/etc/docker/daemon.json' line='{ "insecure-registries":["{{ docker_registry }}"] }' create=yes
when: docker_registry is defined and existing_container_name is undefined and (pp_environment == "default" and ((ansible_env.USER is not defined or ansible_env.USER != "{{ ci_server_username }}") and (ansible_env.SUDO_USER is not defined or ansible_env.SUDO_USER != "{{ ci_server_username }}")))
sudo: yes

- name: Restart docker with new settings
shell: service docker restart
when: docker_registry is defined and existing_container_name is undefined and (pp_environment == "default" and ((ansible_env.USER is not defined or ansible_env.USER != "{{ ci_server_username }}") and (ansible_env.SUDO_USER is not defined or ansible_env.SUDO_USER != "{{ ci_server_username }}")))
sudo: yes

- name: Update source image
shell: docker pull {{ docker_prod_image }}

- name: Run docker network
shell: docker network create --subnet=172.18.0.0/16 buildnet
ignore_errors: true

# Run docker container.
- name: Obtain unique container for a build
shell: docker run --net buildnet --ip {{ docker_sql_host }} --name {{ mysql_db }} -di {{ docker_prod_image }}
when: existing_container_name is undefined

- name: Run mysql within docker container
shell: docker exec {{ mysql_db }} service mysql start
when: existing_container_name is undefined

- name: Run mysql within docker container
shell: docker exec {{ existing_container_name }} service mysql start
when: existing_container_name is defined

# Run registry rebuild.
- name: Check if registry_rebuild is installed
shell: "{{ php_env_vars }} drush | grep -c registry_rebuild"
register: registry_rebuild_installed
ignore_errors: true

- name: Downloading registry_rebuild
sudo: yes
shell: "{{ php_env_vars }} drush -y dl registry_rebuild"
when: rebuild_registry and registry_rebuild_installed.stdout == "0"

- name: Clear drush cache
sudo: yes
shell: "{{ php_env_vars }} drush cc drush"

- name: Rebuilding drupal registry
sudo: yes
shell: "{{ php_env_vars }} drush -y rr -l {{ site_url }} || true"
when: rebuild_registry
4 changes: 2 additions & 2 deletions devops/reinstall/drush_commands.yml
100644 → 100755
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
---
# This script contains commands to run drush commands that are specified in configuration.
- name: Run general drush commands
shell: "{{ php_env_vars }} drush -y {{ item.name }} {{ item.arguments }}"
shell: "{{ php_env_vars }} drush -y {{ item.name }} {{ item.arguments }} -l {{ site_url }}"
when: item.status == true
with_items: global_env.drush_commands

- name: Run environment specific drush commands
shell: "{{ php_env_vars }} drush -y {{ item.name }} {{ item.arguments }}"
shell: "{{ php_env_vars }} drush -y {{ item.name }} {{ item.arguments }} -l {{ site_url }}"
ignore_errors: true
register: echo
when: item.status == true
Expand Down
4 changes: 2 additions & 2 deletions devops/reinstall/modules_enable.yml
100644 → 100755
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
---
# This script contains commands to enable modules that are specified in configuration.
- name: Enable general modules
shell: "{{ php_env_vars }} drush -y en {{ item.name }}"
shell: "{{ php_env_vars }} drush -y en {{ item.name }} -l {{ site_url }}"
when: item.status == true
with_items: global_env.modules

- name: Enable environment specific modules
shell: "{{ php_env_vars }} drush -y en {{ item.name }}"
shell: "{{ php_env_vars }} drush -y en {{ item.name }} -l {{ site_url }}"
when: item.status == true
with_items: env.modules
47 changes: 47 additions & 0 deletions devops/reinstall/old_source_sql_workflow.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
---
# This script contains commands to manage "SQL/Profile workflow with source DB for migration":
# - Downloading database from remote host or use local dump
# - Importing to database

- name: Checking if latest old site db backup exists
stat: path={{ backup_folder }}/{{ old_source_backup_name }} get_md5=no
register: ob

- name: Droping old site database
mysql_db: name={{ old_source_db_name }} state=absent login_user={{ mysql_user }} login_password={{ mysql_pass }}
when: ob.stat.exists == false and (pp_environment == "demo" or pp_environment == "default")

- name: Creating old site database
mysql_db: name={{ old_source_db_name }} state=present login_user={{ mysql_user }} login_password={{ mysql_pass }}
when: ob.stat.exists == false

# Vagrant build.
- name: Downloading latest old site db backup to local environment
get_url: url={{ old_source_db_name_url }} dest={{ backup_folder }}/{{ old_source_backup_name }} force=yes
when: ob.stat.exists == false and (pp_environment == "default" and ((ansible_env.USER is not defined or ansible_env.USER != "{{ ci_server_username }}") and (ansible_env.SUDO_USER is not defined or ansible_env.SUDO_USER != "{{ ci_server_username }}")))

- name: Removing possible old site abandoned dump
shell: rm -rf {{ backup_folder }}/old_source_db.sql
sudo: yes
when: pp_environment == "default" and ((ansible_env.USER is not defined or ansible_env.USER != "{{ ci_server_username }}") and (ansible_env.SUDO_USER is not defined or ansible_env.SUDO_USER != "{{ ci_server_username }}"))

- name: Importing from remote old site backup
mysql_db: name={{ old_source_db_name }} state=import target={{ backup_folder }}/{{ old_source_backup_name }} login_user={{ mysql_user }} login_password={{ mysql_pass }}
sudo: yes
when: ob.stat.exists == false and (pp_environment == "default" and ((ansible_env.USER is not defined or ansible_env.USER != "{{ ci_server_username }}") and (ansible_env.SUDO_USER is not defined or ansible_env.SUDO_USER != "{{ ci_server_username }}")))

# CI server build.
- name: Copy latest old site backup to build folder
sudo: yes
copy: src={{ backup_folder }}/{{ old_source_backup_name }} dest=./{{ old_source_backup_name }} force=yes mode=0644
when: (old_site_db == true) and (pp_environment == "default" or pp_environment == "demo") and ((ansible_env.USER is defined and ansible_env.USER == "{{ ci_server_username }}") or (ansible_env.SUDO_USER is defined and ansible_env.SUDO_USER == "{{ ci_server_username }}"))

- name: Importing from old site local backup
mysql_db: name={{ old_source_db_name }} state=import target=./{{ old_source_backup_name }} login_user={{ mysql_user }} login_password={{ mysql_pass }}
sudo: yes
when: (old_site_db == true) and (pp_environment == "default" or pp_environment == "demo") and ((ansible_env.USER is defined and ansible_env.USER == "{{ ci_server_username }}") or (ansible_env.SUDO_USER is defined and ansible_env.SUDO_USER == "{{ ci_server_username }}"))

- name: Remove old site local backup from build folder
sudo: yes
file: name=./{{ old_source_backup_name }} state=absent
when: (old_site_db == true) and pp_environment == "default" or pp_environment == "demo"
23 changes: 23 additions & 0 deletions devops/reinstall/pre_drush_commands.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
---
# This script contains commands to run drush commands that are specified in configuration.
- name: Make greetings.
debug:
msg: "Pre drush commands about to run."
when: true

# Check all env/vars/environments/*.yml if you see error here.
- name: Run general pre drush commands
shell: "{{ php_env_vars }} drush -y {{ item.name }} {{ item.arguments }} -l {{ site_url }}"
when: item.status == true
with_items: global_env.pre_drush_commands

- name: Run environment specific pre drush commands
shell: "{{ php_env_vars }} drush -y {{ item.name }} {{ item.arguments }} -l {{ site_url }}"
ignore_errors: true
register: echo
when: item.status == true
with_items: env.pre_drush_commands

- name: Debug pre
debug: var=item.stdout
with_items: echo.results
8 changes: 7 additions & 1 deletion devops/reinstall/pre_settings.yml
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,13 @@

- name: Adding database variable to settings.php
sudo: yes
lineinfile: dest='{{ platform_settings_file }}' line='$databases = array(\"default\" => array (\"default\" => array (\"database\" => \"{{ mysql_db }}\", \"username\" => \"{{ mysql_user }}\", \"password\" => \"{{ mysql_pass }}\", \"host\" => \"127.0.0.1\", \"port\" => \"\", \"driver\" => \"mysql\", \"prefix\" => \"\", ), ), );'
lineinfile: dest='{{ platform_settings_file }}' line='$databases = array(\"default\" => array (\"default\" => array (\"database\" => \"{{ mysql_db }}\", \"username\" => \"{{ mysql_user }}\", \"password\" => \"{{ mysql_pass }}\", \"host\" => \"{{ mysql_host }}\", \"port\" => \"\", \"driver\" => \"mysql\", \"prefix\" => \"\", ), ), );'
when: not docker_sql

- name: Adding database variable to settings.php
sudo: yes
lineinfile: dest='{{ platform_settings_file }}' line='$databases = array(\"default\" => array (\"default\" => array (\"database\" => \"{{ docker_sql_db }}\", \"username\" => \"{{ mysql_user }}\", \"password\" => \"{{ mysql_pass }}\", \"host\" => \"{{ docker_sql_host }}\", \"port\" => \"\", \"driver\" => \"mysql\", \"prefix\" => \"\", ), ), );'
when: docker_sql

- name: Add general pre-settings to settings.php
lineinfile: dest='{{ platform_settings_file }}' line='{{ item.name }} = \"{{ item.value }}\";'
Expand Down
2 changes: 1 addition & 1 deletion devops/reinstall/prepare_environment.yml
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -50,4 +50,4 @@
service:
name: mysql
state: started
enabled: true
enabled: true
25 changes: 25 additions & 0 deletions devops/reinstall/reactapps.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
---
# This script contains commands to build react applications from docroot/reactapps folder.

- name: Current site url
debug:
var: site_url

- name: Set environment variables
lineinfile:
line: 'REACT_APP_API_URL="{{ site_url }}"'
dest: 'reactapps/prgreg/.env.local'
create: 'yes'
sudo: yes

- name: Install dependencies
shell: cd reactapps/prgreg && yarn install
sudo: yes

- name: Build application
shell: cd reactapps/prgreg && yarn build
sudo: yes

- name: Build storybook
shell: cd reactapps/prgreg && yarn storybook-build
sudo: yes
15 changes: 15 additions & 0 deletions devops/reinstall/shell_commands.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
---
# This script contains commands to manage "shell commands":
# - Running registry rebuild (when modules have been moved to new directory)
# - Running database updates

- name: Run shell commands
sudo: yes
shell: "{{ item.arguments }}"
when: item.status == true
with_items: env.shell_commands

# Update database.
- name: Updating database
sudo: yes
shell: "{{ php_env_vars }} drush -dvy updb -l {{ site_url }}"
19 changes: 15 additions & 4 deletions devops/reinstall/sql_workflow.yml
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -41,10 +41,21 @@
sudo: yes
file: name=./latest.sql.gz state=absent
when: pp_environment == "default" or pp_environment == "demo"


# Run registry rebuild.
- name: Check if registry_rebuild is installed
shell: "{{ php_env_vars }} drush | grep -c registry_rebuild"
register: registry_rebuild_installed
ignore_errors: true

- name: Downloading registry_rebuild
sudo: yes
shell: "{{ php_env_vars }} drush -y dl registry_rebuild"
when: rebuild_registry and registry_rebuild_installed.stdout == "0"

- name: Clear drush cache
sudo: yes
shell: "{{ php_env_vars }} drush cc drush"
shell: "{{ php_env_vars }} drush cc drush -l {{ site_url }}"
when: rebuild_registry and registry_rebuild_installed.stdout == "0"

- name: Rebuilding drupal registry
Expand All @@ -59,7 +70,7 @@
# Update database. See https://www.youtube.com/watch?v=vFsgNjhGr4Y how-to update configs with http://dgo.to/confi
- name: Updating database
sudo: yes
shell: "{{ php_env_vars }} drush -y updb -l {{ site_url }}"
shell: "{{ php_env_vars }} drush -dvy updb -l {{ site_url }}"
register: updates

- name: Apply pending entity schema updates
Expand All @@ -80,7 +91,7 @@
sudo: yes
shell: "{{ php_env_vars }} drush -y config-set stage_file_proxy.settings origin {{ origin_site_url }} -l {{ site_url }}"
when: stage_file_proxy

- name: Set folder for stage file proxy
sudo: yes
shell: "{{ php_env_vars }} drush -y config-set stage_file_proxy.settings origin_dir {{ origin_site_directory }} -l {{ site_url }}"
Expand Down
6 changes: 4 additions & 2 deletions devops/reinstall/vars/environments/default_env.yml
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@ env:
- { name: '$settings["install_profile"]', status: true, value: "{{ installation_profile_name }}" }
- { name: '$settings["file_public_path"]', status: true, value: 'sites/{{ settings_site_folder }}/files' }
- { name: '$config["system.file"]["path.temporary"]', status: true, value: '/tmp' }
pre_drush_commands:
- { name: 'status', status: false, arguments: "" }
shell_commands:
- { name: 'Demo', status: false, arguments: "pwd"}
modules:
- { name: 'devel shield', status: false }
drush_commands:
Expand All @@ -24,6 +28,4 @@ env:
- { name: 'en', status: true, arguments: "openy_development || true" }
post_settings:
- { name: '$config_directories["staging"]', status: true, value: 'sites/default/config/staging' }
- { name: '$settings["cache"]["bins"]["render"]', status: false, value: 'cache.backend.memory' }
- { name: '$config["stage_file_proxy.settings"]["origin"]', status: false, value: '{{ origin_site_url }}' }

2 changes: 2 additions & 0 deletions devops/reinstall/vars/environments/demo_env.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ env:
- { name: '$settings["install_profile"]', status: true, value: "{{ installation_profile_name }}" }
- { name: '$settings["file_public_path"]', status: true, value: 'sites/{{ settings_site_folder }}/files' }
- { name: '$config["system.file"]["path.temporary"]', status: true, value: '/tmp' }
pre_drush_commands: []
shell_commands: []
modules:
- { name: 'devel shield', status: false }
drush_commands:
Expand Down
2 changes: 2 additions & 0 deletions devops/reinstall/vars/environments/global_env.yml
100644 → 100755
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
---
global_env:
pre_settings: []
pre_drush_commands: []
shell_commands: []
modules: []
drush_commands: []
post_settings:
Expand Down
8 changes: 8 additions & 0 deletions devops/reinstall/vars/environments/production_env.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
---
env:
pre_settings: []
pre_drush_commands: []
shell_commands: []
modules: []
drush_commands: []
post_settings: []
29 changes: 6 additions & 23 deletions devops/reinstall/vars/environments/staging_env.yml
100644 → 100755
Original file line number Diff line number Diff line change
@@ -1,25 +1,8 @@
---
env:
pre_settings:
- { name: '$settings["hash_salt"]', status: true, value: 'g1W4KZgWCeWh7Af9_gSb9D9HOiNaBdWPvQD-8x0yWpcgNpTBppaHR5VNGQBGvh2k8P8uWa1V8w'}
- { name: '$config_directories["staging"]', status: false, value: 'sites/default/config/staging' }
- { name: '$settings["install_profile"]', status: true, value: "{{ installation_profile_name }}" }
- { name: '$settings["file_public_path"]', status: true, value: 'sites/{{ settings_site_folder }}/files' }
- { name: '$config["system.file"]["path.temporary"]', status: true, value: '/tmp' }
- { name: '$config_directories["sync"]', status: true, value: 'sites/default/config/sync' }
modules:
- { name: 'devel shield', status: false }
drush_commands:
- { name: 'pm-uninstall', status: true, arguments: "update -y" }
- { name: 'user-password', status: true, arguments: "{{ drupal_user }} --password={{ drupal_pass }}" }
- { name: 'cr', status: true, arguments: "" }
- { name: 'config-set', status: false, arguments: "shield.settings user {{ http_user }} -y" }
- { name: 'config-set', status: false, arguments: "shield.settings pass {{ http_pass }} -y" }
- { name: 'config-set', status: false, arguments: "system.site uuid USER_YOUR_UUID_HERE -y" }
- { name: 'config-set', status: false, arguments: "stage_file_proxy.settings origin {{ origin_site_url }} -y" }
- { name: 'config-set', status: true, arguments: "geolocation.settings google_map_api_key 'AIzaSyDIFPdDmDsBOFFZcmavCaAqHa3VNKkXLJc' -y" }
post_settings:
- { name: '$config_directories["staging"]', status: true, value: 'sites/default/config/staging' }
- { name: '$config_directories["sync"]', status: true, value: 'sites/default/config/staging' }
- { name: '$settings["cache"]["bins"]["render"]', status: false, value: 'cache.backend.memory' }
- { name: '$config["stage_file_proxy.settings"]["origin"]', status: false, value: '{{ origin_site_url }}' }
pre_settings: []
pre_drush_commands: []
shell_commands: []
modules: []
drush_commands: []
post_settings: []
Loading