Merge branch 'add-rake-tasks' into 'master'

Add rake tasks

See merge request agaric/sites/agaric-com!63
This commit is contained in:
mlncn 2019-02-20 21:07:08 +00:00
commit 7c1b025ac7
12 changed files with 211 additions and 43 deletions

4
.gitignore vendored
View file

@ -21,6 +21,10 @@ vendor/
## Ignore folder for SQL dumps ## Ignore folder for SQL dumps
/sql /sql
## Ignore other template-built files:
drush/sites/local.site.yml
drush/drush.yml
## What you CAN commit: ## What you CAN commit:
# config # config
# web/themes/custom/*/templates # web/themes/custom/*/templates

View file

@ -28,18 +28,21 @@ help: ##@Targets Show this text (or just run make)
# Configure sync' # Configure sync'
ALIAS_LIVE := @live.live ALIAS_LIVE := @live.live
ALIAS_TEST := @test.dev ALIAS_TEST := @test.test
SRV := root@elizabeth.mayfirst.org SRV_TEST := root@elizabeth.mayfirst.org
FILES_LIVE := /home/agaric_live/files/ SRV_LIVE := $(SRV_TEST)
FILES_LIVE := /home/agaric_live/files
FILES_TEST := /home/agaric_test/files FILES_TEST := /home/agaric_test/files
ECHO := $(if $(TEST),@echo) ECHO := $(if $(TEST),@echo)
synclivetotest: syncfiles syncdb ##@Targets Sync live environment to test synclivetotest: ##@Targets Sync live environment to test (pass TEST=true to echo commands)
syncdb:
$(ECHO) drush -y $(ALIAS_TEST) sql-drop $(ECHO) drush -y $(ALIAS_TEST) sql-drop
$(ECHO) drush -y sql-sync $(ALIAS_LIVE) $(ALIAS_TEST) $(ECHO) drush -y sql-sync $(ALIAS_LIVE) $(ALIAS_TEST)
ifeq ($(SRV_TEST), $(SRV_LIVE))
syncfiles: $(ECHO) ssh -A $(SRV_LIVE) rsync -rz --stats --exclude styles \
$(ECHO) ssh -A $(SRV) rsync -rz --stats --exclude styles \
--exclude css --exclude js $(FILES_LIVE) \ --exclude css --exclude js $(FILES_LIVE) \
--delete ${FILES_TEST} --delete ${FILES_TEST}
else
$(ECHO) drush -y sync $(ALIAS_LIVE)/public/%files $(ALIAS_TEST)/public/%files
endif

23
Rakefile Normal file
View file

@ -0,0 +1,23 @@
# "dev" => {
# "host" => "vlad@simone.mayfirst.org",
# "path" => "/var/local/drupal/findit/web",
# "backups" => "/tmp",
# },
ENVIRONMENTS = {
"test" => {
"host" => "agaric_test@drutopia.org",
"path" => "/home/agaric_test/site/web",
"drush" => "/home/agaric_test/site/vendor/bin/drush",
"backups" => "/tmp",
},
"live" => {
"host" => "agaric_live@drutopia.org",
"path" => "/home/agaric_live/site/web",
"drush" => "/home/agaric_live/site/vendor/bin/drush",
"backups" => "/tmp",
},
}
TAGNAMES = %w(stable)
DRUPAL = "web"
PROFILE = "agaric"
BUILDDIR = "/tmp/build"

View file

@ -1,17 +0,0 @@
<?php
$aliases['dev'] = [
'root' => '/var/www/drutopia/web',
'uri' => 'http://agaric-com.test/',
];
$aliases['test'] = [
'root' => '/home/agaric_test/site/web',
'uri' => 'https://agaric-test.drutopia.org',
'remote-user' => 'agaric_test',
'remote-host' => 'elizabeth.mayfirst.org',
'path-aliases' => [
'%drush' => '/home/agaric_test/site/vendor/drush/drush',
'%drush-script' => '/home/agaric_test/site/vendor/bin/drush',
],
];

View file

@ -1,4 +0,0 @@
<?php
$options['l'] = 'http://agaric-com.test';
$options['r'] = '/var/www/drutopia/web';

View file

@ -1,4 +1,4 @@
dev: test:
host: elizabeth.mayfirst.org host: elizabeth.mayfirst.org
paths: paths:
drush: /home/agaric_test/site/vendor/drush/drush drush: /home/agaric_test/site/vendor/drush/drush

View file

@ -155,7 +155,7 @@ installed_extras:
- nodejs - nodejs
- pimpmylog - pimpmylog
# - redis # - redis
# - ruby - ruby
# - selenium # - selenium
# - solr # - solr
# - tideways # - tideways
@ -206,13 +206,6 @@ php_opcache_max_accelerated_files: 4096
php_max_input_vars: "4000" php_max_input_vars: "4000"
php_packages_extra: ['php7.1-zip'] php_packages_extra: ['php7.1-zip']
# Run specified scripts before or after VM is provisioned. Use {{ playbook_dir }}
# to reference the provisioning/ folder in Drupal VM or {{ config_dir }} to
# reference the directory where your `config.yml` is.
pre_provision_scripts: []
post_provision_scripts: []
# - "{{ playbook_dir }}/../examples/scripts/configure-solr.sh"
# MySQL Configuration. # MySQL Configuration.
mysql_root_password: root mysql_root_password: root
mysql_slow_query_log_enabled: true mysql_slow_query_log_enabled: true
@ -229,7 +222,7 @@ npm_config_prefix: "/home/{{ drupalvm_user }}/.npm-global"
# Ruby Configuration (if enabled above). # Ruby Configuration (if enabled above).
ruby_install_gems_user: "{{ drupalvm_user }}" ruby_install_gems_user: "{{ drupalvm_user }}"
ruby_install_gems: [] ruby_install_gems: ['rake']
# Varnish Configuration (if enabled above). # Varnish Configuration (if enabled above).
varnish_listen_port: "81" varnish_listen_port: "81"
@ -272,5 +265,5 @@ hostname_configure: true
hostname_fqdn: "{{ vagrant_hostname }}" hostname_fqdn: "{{ vagrant_hostname }}"
ssh_home: "{{ drupal_core_path }}" ssh_home: "{{ drupal_core_path }}"
post_provision_tasks_dir: ../../provisioning/box/post-tasks/*.yml
pre_provision_tasks_dir: ../../provisioning/box/pre-tasks/*.yml pre_provision_tasks_dir: ../../provisioning/box/pre-tasks/*.yml
post_provision_tasks_dir: ../../provisioning/box/post-tasks/*.yml

View file

@ -51,7 +51,7 @@
dest: "{{ drupal_core_path }}/sites/default/settings.local.php" dest: "{{ drupal_core_path }}/sites/default/settings.local.php"
- name: Check if site is already installed. - name: Check if site is already installed.
command: "{{ drupal_composer_install_dir }}/vendor/bin/drush --root={{ drupal_core_path}}/ status bootstrap" command: "{{ drupal_composer_install_dir }}/vendor/bin/drush --root={{ drupal_core_path }}/ status bootstrap"
args: args:
chdir: "{{ drupal_core_path }}" chdir: "{{ drupal_core_path }}"
register: drupal_site_installed register: drupal_site_installed
@ -59,6 +59,16 @@
changed_when: false changed_when: false
become: no become: no
- name: create drush.yml
template:
src: "drush.yml.j2"
dest: "{{ drupal_composer_install_dir }}/drush/drush.yml"
- name: create local.site.yml
template:
src: "local.site.yml.j2"
dest: "{{ drupal_composer_install_dir }}/drush/sites/local.site.yml"
- name: Install Drupal with drush. - name: Install Drupal with drush.
command: > command: >
{{ drupal_composer_install_dir }}/vendor/bin/drush site-install -y {{ drupal_composer_install_dir }}/vendor/bin/drush site-install -y

View file

@ -0,0 +1,3 @@
options:
uri: "http://{{ vagrant_hostname }}"
root: "{{ drupal_core_path }}"

View file

@ -0,0 +1,7 @@
dev:
root: "{{ drupal_core_path }}"
uri: "http://{{ vagrant_hostname }}"
local:
root: "{{ drupal_core_path }}"
uri: "http://{{ vagrant_hostname }}"

106
rakelib/agaric.rake Normal file
View file

@ -0,0 +1,106 @@
# As agaric.rake did not know how to deploy to Drutopia,
# all deployment features have been removed.
# Use drutopia_host to deploy.
require 'date'
require 'rake/clean'
CLEAN.include("#{BUILDDIR}")
ENVIRONMENTS.keys.each do |env|
settings_source = "#{BUILDDIR}/#{env}/#{DRUPAL}/sites/default/#{env}.settings.php"
settings_target = "#{BUILDDIR}/#{env}/#{DRUPAL}/sites/default/settings.php"
release_host = ENVIRONMENTS[env]["host"]
release_path = ENVIRONMENTS[env]["path"]
release_backups = ENVIRONMENTS[env]["backups"]
release_tag = ENVIRONMENTS[env]["tag"]
drush_path = ENVIRONMENTS[env]["drush"]
drush_path = drush_path ? drush_path : "drush"
db_backup_task = "db_backup_#{env}".to_sym
task db_backup_task do
file = "#{release_backups}/backup-#{env}-#{DateTime.now}.sql.gz"
sh "ssh #{release_host} '#{drush_path} -r #{release_path} sql-dump --structure-tables-key=common --gzip > #{file}'"
end
db_drop_tables_task = "db_drop_tables_#{env}".to_sym
task db_drop_tables_task => db_backup_task do
sh "ssh #{release_host} #{drush_path} -y -r #{release_path} sql-drop"
end
file_sync_task = "file_sync_#{env}_to_local".to_sym
desc "Sync files from #{env} to local environment."
task file_sync_task do
sh "rsync -rz --stats --exclude styles --exclude css --exclude js --delete \
#{release_host}:#{release_path}/sites/default/files/ \
#{DRUPAL}/sites/default/files/"
end
db_sync_task = "db_sync_#{env}_to_local".to_sym
desc "Sync database from #{env} to local environment."
task db_sync_task do
sh "drush -y sql-drop"
sh "ssh -C #{release_host} #{drush_path} -r #{release_path} \
sql-dump --structure-tables-key=common | drush sql-cli"
end
ENVIRONMENTS.keys.each do |e|
unless e == env then
from_host = ENVIRONMENTS[e]["host"]
from_path = ENVIRONMENTS[e]["path"]
from_drush = ENVIRONMENTS[e]["drush"]
from_drush = from_drush ? from_drush : "drush"
file_sync_task = "file_sync_#{e}_to_#{env}".to_sym
desc "Sync files from #{e} to #{env} environment."
task file_sync_task do
sh "ssh -A #{from_host} rsync -rz --stats --exclude styles \
--exclude css --exclude js #{from_path}/sites/default/files/ \
--delete " + (from_host == release_host ? "" : "#{release_host}:") + "#{release_path}/sites/default/files/"
end
db_sync_task = "db_sync_#{e}_to_#{env}".to_sym
desc "Sync database from #{e} to #{env} environment."
task db_sync_task => db_drop_tables_task do
sh "ssh -C #{from_host} #{from_drush} -r #{from_path} \
sql-dump --structure-tables-key=common | \
ssh -C #{release_host} #{drush_path} -r #{release_path} sql-cli"
end
end
end
end
TAGNAMES.each do |tagname|
desc "Tag a commit with #{tagname}."
task "tag_#{tagname}".to_sym do
sh "git fetch --tags"
num = `git tag`.scan(Regexp.new(tagname + "-")).size + 1
sh "git tag -am '#{tagname.upcase} Release #{num}' #{tagname}-#{num}"
sh "git tag -afm 'Current #{tagname.upcase} Release' #{tagname}"
sh "git push origin :refs/tags/#{tagname}"
sh "git push origin --tags"
end
end
desc "Detect coding standard violations in profile and custom modules."
task :sniff do
files = ["web/profiles/#{PROFILE}", 'web/sites/all/modules/custom'].join(' ')
extensions = ['module', 'profile', 'install', 'inc', 'php'].join(',')
sh "phpcs --extensions=#{extensions} #{files}"
end
namespace :tests do
desc "Run integration tests."
task "integration" do
sh "phpunit --process-isolation --bootstrap=tests/bootstrap.php tests/integration"
end
end
if defined? PROFILE
desc "Delete and re-install a site from its installation profile."
task "site_install" do
sh "#{drush_path} -y site-install #{PROFILE}"
end
end

40
rakelib/init.rake Normal file
View file

@ -0,0 +1,40 @@
desc "Create a central bare repository from the local repository."
task :init_repo do
repo_id = File.basename(Dir.getwd)
repo_path = "/srv/git/#{repo_id}.git"
post_receive = "/usr/bin/kgb-client --git-reflog - --conf /etc/kgb-client/kgb.conf --repository git --repo-id #{repo_id}"
commands = [
"mkdir #{repo_path}",
"cd #{repo_path}",
"git init --bare",
# For HTTP access such as gitweb
"mv hooks/post-update.sample hooks/post-update",
# For KGB to send commit notifications over IRC.
# This still requires additional server-side configuration, see
# http://my.agaric.com/agaric/node/11694
"echo #{post_receive} >> hooks/post-receive",
"chmod a+x hooks/post-receive"
].join(" && ")
sh "ssh git.agaric.com '#{commands}'"
sh "git remote add origin git.agaric.com:#{repo_path}"
sh "git push origin master"
end
desc "Add .gitignore file with basic project specific patterns."
task ".gitignore" do
open(".gitignore", "a") do |f|
f.puts ".sass-cache/"
f.puts ".vagrant/"
f.puts "build/"
f.puts "web/sites/default/settings.php"
f.puts "web/sites/default/files/"
end
end
desc "Add .gitattributes file with basic project specific patterns."
task ".gitattributes" do
open(".gitattributes", "a") do |f|
f.puts "etc export-ignore"
end
end