From 3fe3cff66df0c2cba50586ed1a53915349b121d2 Mon Sep 17 00:00:00 2001 From: Christopher Gervais Date: Sun, 13 Mar 2016 02:27:45 +0000 Subject: [PATCH] Split from updates server. --- .gitignore | 9 +++++++++ .travis.yml | 17 +++++++++++++++++ Makefile | 15 +++++++++++++++ README.md | 20 ++++++++++++++++++++ Vagrantfile | 24 ++++++++++++++++++++++++ behat.composer.json | 9 +++++++++ behat.yml | 19 +++++++++++++++++++ mk/behat.mk | 44 ++++++++++++++++++++++++++++++++++++++++++++ mk/bootstrap.sh | 19 +++++++++++++++++++ mk/composer.mk | 13 +++++++++++++ mk/deps.mk | 18 ++++++++++++++++++ mk/drupal.mk | 36 ++++++++++++++++++++++++++++++++++++ mk/drush.mk | 32 ++++++++++++++++++++++++++++++++ mk/help.mk | 12 ++++++++++++ mk/selenium.mk | 15 +++++++++++++++ mk/test.mk | 9 +++++++++ mk/utils.mk | 40 ++++++++++++++++++++++++++++++++++++++++ 17 files changed, 351 insertions(+) create mode 100644 .gitignore create mode 100644 .travis.yml create mode 100644 Makefile create mode 100644 README.md create mode 100644 Vagrantfile create mode 100644 behat.composer.json create mode 100644 behat.yml create mode 100644 mk/behat.mk create mode 100755 mk/bootstrap.sh create mode 100644 mk/composer.mk create mode 100644 mk/deps.mk create mode 100644 mk/drupal.mk create mode 100644 mk/drush.mk create mode 100644 mk/help.mk create mode 100644 mk/selenium.mk create mode 100644 mk/test.mk create mode 100644 mk/utils.mk diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..0c62993 --- /dev/null +++ b/.gitignore @@ -0,0 +1,9 @@ +.vagrant/* +ansible/roles/* +*.swp +vendor/* +bin/* +selenium-server.jar +composer.phar +behat_params.sh +.local diff --git a/.travis.yml b/.travis.yml new file mode 100644 index 0000000..1fa0544 --- /dev/null +++ b/.travis.yml @@ -0,0 +1,17 @@ +--- +language: php + +dist: trusty + +sudo: false + +install: + - .mk/bootstrap.sh + +before_script: + - . ~/.bashrc + # Debugging + - curl http://localhost:8888/ + +script: + - make test-on-travis diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..0ad2364 --- /dev/null +++ b/Makefile @@ -0,0 +1,15 @@ +MK_DIR ?= . +SHELL := /bin/bash +project_root ?= /vagrant +BIN_DIR = $(MK_DIR)/.local/bin +SRC_DIR = $(MK_DIR)/.local/src + +up: + @vagrant up +rebuild: + @vagrant destroy -f && vagrant up +make: + @vagrant ssh -c"cd /var/www/html/d8 && sudo drush -y make /vagrant/dev.build.yml" + +include $(MK_DIR)/mk/*.mk + diff --git a/README.md b/README.md new file mode 100644 index 0000000..f80feda --- /dev/null +++ b/README.md @@ -0,0 +1,20 @@ +MAKE SERVER [![Build status](https://travis-ci.org/ergonlogic/make-server.svg)](https://travis-ci.org/ergonlogic/make-server) +=========== + +Drush Make is certainly quite useful for building Drupal code-bases. A little-known capability is to load project version data from a source other than the official http://updates.drupal.org. This install profile is intended to make it easy to run your own updates service. + +Development +----------- + +We use a simple Vagrant-based VM that installs Drush and a Drupal site. It +symlinks this project as an install profile, so that simply editing the code in +this directory is sufficient to see the changes. + + $ git clone https://github.com/ergonlogic/make-server.git + $ cd make-server + $ vagrant up + +If you want to install Drush from sources, instead of the .phar: + + $ DRUSH_DEV=true vagrant up + diff --git a/Vagrantfile b/Vagrantfile new file mode 100644 index 0000000..5626e7e --- /dev/null +++ b/Vagrantfile @@ -0,0 +1,24 @@ +# -*- mode: ruby -*- +# vi: set ft=ruby : +Vagrant.configure(2) do |config| + config.vm.define 'make-server' do |d| + d.vm.box = "ubuntu/trusty64" + d.vm.provider "virtualbox" do |v| + v.memory = 1024 + v.cpus = 2 + end + + d.vm.hostname = 'make.local' + d.vm.network 'private_network', ip: '10.57.57.57' + config.vm.network "forwarded_port", guest: 8888, host: 8888 + + if Vagrant.has_plugin?("vagrant-cachier") + config.cache.scope = :box + end + + d.vm.provision "shell", + path: ".mk/bootstrap.sh", + privileged: false, + keep_color: true + end +end diff --git a/behat.composer.json b/behat.composer.json new file mode 100644 index 0000000..8abb0ec --- /dev/null +++ b/behat.composer.json @@ -0,0 +1,9 @@ +{ + "require": { + "drupal/drupal-extension": "~3.0", + "guzzlehttp/guzzle" : "~6.0" + }, + "config": { + "bin-dir": "bin/" + } +} diff --git a/behat.yml b/behat.yml new file mode 100644 index 0000000..45c1ffb --- /dev/null +++ b/behat.yml @@ -0,0 +1,19 @@ +default: + suites: + default: + contexts: + - FeatureContext + - Drupal\DrupalExtension\Context\DrupalContext + - Drupal\DrupalExtension\Context\MinkContext + - Drupal\DrupalExtension\Context\MessageContext + - Drupal\DrupalExtension\Context\DrushContext + extensions: + Behat\MinkExtension: + goutte: ~ + selenium2: ~ + Drupal\DrupalExtension: + blackbox: ~ + gherkin: + filters: + tags: ~@wip + diff --git a/mk/behat.mk b/mk/behat.mk new file mode 100644 index 0000000..88e664f --- /dev/null +++ b/mk/behat.mk @@ -0,0 +1,44 @@ +behat = $(bin_dir)/behat +behat_src = $(src_dir)/behat +bde_dir = $(drush_dir)/drush-bde-env +bde_exists = $(shell if [[ -d $(bde_dir) ]]; then echo 1; fi) + +_help-behat: + @echo "make behat" + @echo " Install Behat." + +drush-bde-env: drush +ifneq '$(bde_exists)' '1' + @echo Cloning Drush Behat config extension + @git clone https://github.com/pfrenssen/drush-bde-env.git $(bde_dir) + @$(drush) cc drush +endif + +behat-config: behat drush-bde-env $(root) + @echo Generating project-specific Behat config + @cd $(root) && $(drush) beg --subcontexts=profiles/$(profile)/modules --site-root=$(root) --skip-path-check --base-url=$(uri) $(project_root)/behat_params.sh + +deps-behat: aptitude-update composer + @echo Installing Behat dependencies + @sudo DEBIAN_FRONTEND=noninteractive apt-get -y -qq install php5-curl + +clean-behat: + @rm -rf $(behat_src) + @rm -f $(behat) + +$(behat_src)/composer.json: $(mk_dir)/behat.composer.json + @mkdir -p $(behat_src) + @cp $(mk_dir)/behat.composer.json $(behat_src)/composer.json + +$(behat_src)/composer.lock: $(behat_src)/composer.json + @cd $(behat_src) && \ + rm -f composer.lock && \ + $(composer) install + +$(behat_src)/bin/behat: $(behat_src)/composer.lock + +$(behat): $(behat_src)/bin/behat + @cd $(bin_dir) && \ + ln -sf ../src/behat/bin/behat behat + +behat: $(behat) diff --git a/mk/bootstrap.sh b/mk/bootstrap.sh new file mode 100755 index 0000000..232ea0e --- /dev/null +++ b/mk/bootstrap.sh @@ -0,0 +1,19 @@ +#!/bin/bash + +# Set different project roots depending on Vagrant or TravisCI environments. +if [ -z ${TRAVIS_BUILD_DIR+x} ]; then + cd /vagrant + make deps +else + export project_root=$TRAVIS_BUILD_DIR +fi + +make init +source ~/.bashrc + +make drush + +make drupal + +make behat + diff --git a/mk/composer.mk b/mk/composer.mk new file mode 100644 index 0000000..b7fc70e --- /dev/null +++ b/mk/composer.mk @@ -0,0 +1,13 @@ +composer = $(bin_dir)/composer +version = 1.0.0-beta1 + +_help-composer: + @echo "make composer" + @echo " Install composer." + @echo "make composer version=" + @echo " Install the specified version of Composer. Defaults to $(version)" + +composer: init + @curl -sSL -z $(composer) -o $(composer) https://getcomposer.org/download/$(version)/composer.phar + @chmod a+x $(composer) + @$(composer) --version diff --git a/mk/deps.mk b/mk/deps.mk new file mode 100644 index 0000000..8f6aa5a --- /dev/null +++ b/mk/deps.mk @@ -0,0 +1,18 @@ +deps_hooks = $(shell grep "^deps-[^:]*" $(mk_dir)/mk -rho) + +deps: aptitude-update mysql-server $(deps_hooks) + +list-deps: + @echo The following dependency hooks are defined: + @echo $(deps_hooks) + +mysql-server: vagrant aptitude-update + @echo Installing MySQL server + @echo 'mysql-server mysql-server/root_password password' | sudo debconf-set-selections + @echo 'mysql-server mysql-server/root_password_again password' | sudo debconf-set-selections + @sudo DEBIAN_FRONTEND=noninteractive apt-get -y -qq install mysql-server + +aptitude-update: vagrant + @echo Updating apt + @sudo DEBIAN_FRONTEND=noninteractive apt-get update -qq + diff --git a/mk/drupal.mk b/mk/drupal.mk new file mode 100644 index 0000000..81ffc84 --- /dev/null +++ b/mk/drupal.mk @@ -0,0 +1,36 @@ +makefile = dev.build.yml +root = ~/drupal +root_exists = $(shell if [[ -d $(root) ]]; then echo 1; fi) +site_exists = $(shell if [[ -f $(root)/sites/default/settings.php ]]; then echo 1; fi) +profile = make_server +port = 8888 +uri = http://localhost:$(port) + +help-drupal: + @echo "make drupal" + @echo " Build a Drupal codebase, install a site and start a web server." + @echo "make kill-server" + @echo " Stop the server running started during site install." + +rebuild-platform: $(root) +$(root): $(project_root)/$(makefile) + +build-platform: vm +ifneq '$(root_exists)' '1' + @$(drush) -y make $(project_root)/$(makefile) $(root) + @ln -s $(project_root) $(root)/profiles/$(profile) +endif + +drupal: kill-server build-platform +ifneq '$(site_exists)' '1' + @cd $(root) && $(drush) -y site-install $(profile) --db-url=mysql://root@localhost/site0 --account-pass=pwd +endif + @echo " ~/.drush/local.alias.drushrc.php + @echo " \$$aliases['local'] = array('root' => '$(root)','uri' => '$(uri)');" >> ~/.drush/local.alias.drushrc.php + @echo "Starting PHP server." + @cd $(root) && php -S 0.0.0.0:$(port) &> ~/runserver.log & + +kill-server: + @echo "Stopping PHP server." + @ps aux|grep [p]hp > /dev/null || pkill -f php + @sleep 3 diff --git a/mk/drush.mk b/mk/drush.mk new file mode 100644 index 0000000..ed5b0eb --- /dev/null +++ b/mk/drush.mk @@ -0,0 +1,32 @@ +DRUSH_DIR ?= $(mk_dir)/.local/drush +DRUSH_SRC ?= $(src_dir)/drush +DRUSH_BIN ?= $(bin_dir)/drush +DRUSH_RELEASE ?= 8.0.5 +DRUSH_PHAR ?= $(DRUSH_SRC)/drush-$(DRUSH_RELEASE).phar +drush ?= $(DRUSH_BIN) --include=$(DRUSH_DIR) + +_help-drush: + @echo "make drush" + @echo " Install Drush." + +clean-drush: + @rm -f $(DRUSH_BIN) + @rm -f $(DRUSH_SRC) + +deps-drush: aptitude-update mysql-server + @echo Installing Drush dependencies + @sudo DEBIAN_FRONTEND=noninteractive apt-get -y -qq install git php5-mysql php5-cli php5-gd + +$(DRUSH_PHAR): init + @echo Downloading the $(DRUSH_RELEASE) release of Drush. + mkdir -p $(DRUSH_SRC) + curl -Ss "https://github.com/drush-ops/drush/releases/download/$(DRUSH_RELEASE)/drush.phar" -z $(DRUSH_PHAR) -o $(DRUSH_PHAR) + +$(DRUSH_BIN): $(DRUSH_SRC)/drush-$(DRUSH_RELEASE).phar + @echo Installing the $(DRUSH_RELEASE) release of Drush. + @cd $(bin_dir) && \ + ln -sf ../src/drush-$(DRUSH_RELEASE).phar drush + @chmod a+x $(DRUSH_BIN) + @$(drush) --version + +drush: $(DRUSH_BIN) diff --git a/mk/help.mk b/mk/help.mk new file mode 100644 index 0000000..86b91bf --- /dev/null +++ b/mk/help.mk @@ -0,0 +1,12 @@ +help_hooks = $(shell grep "^help-[^:]*" $(mk_dir)/mk -rho) +help_hooks_hidden = $(shell grep "^_help-[^:]*" $(mk_dir)/mk -rho) + +help: $(help_hooks) +all-help: $(help_hooks) $(help_hooks_hidden) + +list-help: + @echo "The following help hooks are defined:" + @echo $(help_hooks) + @echo "The following hidden help hooks are defined (displayed with 'all-help'):" + @echo $(help_hooks_hidden) + diff --git a/mk/selenium.mk b/mk/selenium.mk new file mode 100644 index 0000000..2f99cb7 --- /dev/null +++ b/mk/selenium.mk @@ -0,0 +1,15 @@ +selenium = $(bin_dir)/selenium-server.jar +selenium_version = 2.52 +selenium_release = $(selenium-version).0 + +_help-selenium: + @echo "make selenium" + @echo " Install Selenium." + +deps-selenium: vagrant aptitude-update + @echo Installing Selenium dependencies + @sudo DEBIAN_FRONTEND=noninteractive apt-get -y -qq install openjdk-7-jre-headless + +selenium: vm + @curl -sSL -z $(selenium) -o $(selenium) http://selenium-release.storage.googleapis.com/$(selenium-version)/selenium-server-standalone-$(selenium-release).jar + diff --git a/mk/test.mk b/mk/test.mk new file mode 100644 index 0000000..4752ac6 --- /dev/null +++ b/mk/test.mk @@ -0,0 +1,9 @@ +help-test: + @echo "make test" + @echo " Run tests." + +test: behat-config + @source behat_params.sh && bin/behat +wip: behat-config + @source behat_params.sh && bin/behat --tags=wip + diff --git a/mk/utils.mk b/mk/utils.mk new file mode 100644 index 0000000..40262d4 --- /dev/null +++ b/mk/utils.mk @@ -0,0 +1,40 @@ +user = $(shell whoami) +utils = screen htop strace tree +bashrc = export PATH="$(BIN_DIR):$$PATH" + +init: $(BIN_DIR) $(SRC_DIR) + @grep -q -F '$(bashrc)' ~/.bashrc || echo '$(bashrc)' >> ~/.bashrc + +$(BIN_DIR): + @mkdir -p $(BIN_DIR) + +$(SRC_DIR): + @mkdir -p $(SRC_DIR) + +fix-time: + @sudo ntpdate -s time.nist.gov + +deps-utils: vagrant + @echo Installing some utilities + @sudo DEBIAN_FRONTEND=noninteractive apt-get -y -qq install $(utils) + +clean: + @rm -rf $(BIN_DIR) + @rm -rf $(SRC_DIR) + +vm: +ifneq ($(user), vagrant) +ifneq ($(user), travis) + @echo Current user is \'$(user)\'. + @echo This command \(make $@\) must be built in a \'vagrant\' or \'travis\' vm. + @exit 1 +endif +endif + +vagrant: +ifneq ($(user), vagrant) + @echo Current user is \'$(user)\'. + @echo This command \(make $@\) must be built in a \'vagrant\' vm. + @exit 1 +endif +