Commit e2bf559c authored by Yas Naoi's avatar Yas Naoi
Browse files

Issue #3264010 by yas: Refactor .tugboat/config.yml for live previews on cloud module at d.o

parent 63188582
Loading
Loading
Loading
Loading
+72 −38
Original line number Diff line number Diff line
@@ -4,46 +4,63 @@ services:
    default: true
    http: false
    # depends: mysql
    depends: memcached
    commands:
      update: |
        set -eux
        # Avoid an error: "Allowed memory size of 134217728 bytes exhausted"
        export PHP_INI='/usr/local/etc/php/conf.d/my-php.ini'
        echo 'memory_limit = -1' >> "${PHP_INI}"
        # Set up the max execution time.
        echo 'max_execution_time = 600' >> "${PHP_INI}"
        # Check out a branch using the unique Tugboat ID for this repository, to
        # ensure we don't clobber an existing branch.
        git checkout -b $TUGBOAT_REPO_ID
        git checkout -b "${TUGBOAT_REPO_ID}"
        # Composer is hungry. You need a Tugboat project with a pretty sizeable
        # chunk of memory.
        export COMPOSER_MEMORY_LIMIT=-1
        # This is an environment variable we added in the Dockerfile that
        # provides the path to Drupal composer root (not the web root).
        cd $DRUPAL_COMPOSER_ROOT
        cd "${DRUPAL_COMPOSER_ROOT}"
        # We configure the Drupal project to use the checkout of the module as a
        # Composer package repository.
        composer config repositories.tugboat vcs $TUGBOAT_ROOT
        # Require Admin Toolbar
        composer config repositories.tugboat vcs "${TUGBOAT_ROOT}"
        # Install Admin Toolbar.
        composer require drupal/admin_toolbar
        # Install Memcached.
        composer require drupal/memcache
        # Allow "minimum-stability": "dev" and "prefer-stable": true
        composer config minimum-stability dev
        composer config prefer-stable true
        # Now we can require drupal/cloud, specifing the branch name we created
        # above that uses the $TUGBOAT_REPO_ID environment variable.
        composer require drupal/cloud:dev-$TUGBOAT_REPO_ID
        # Set the $PATH for vendor/bin/drush
        export PATH=$PATH:./vendor/bin
        # above that uses the "${TUGBOAT_REPO_ID}" environment variable.
        composer require "drupal/cloud:dev-${TUGBOAT_REPO_ID}"
        # Set up a drush command.
        ln -s "$(pwd)/vendor/bin/drush" /usr/local/bin/
        # Install Drupal on the site.
        # Use --db-url=mysql://tugboat:tugboat@mysql:3306/tugboat for mysql connection.
        drush \
          --yes \
        drush -y \
          --db-url=sqlite://sites/default/files/db.sqlite \
          --site-name="Live preview for ${TUGBOAT_PREVIEW_NAME}" \
          --account-pass=admin \
          site:install standard
        # Set up the files directory permissions.
        mkdir -p $DRUPAL_DOCROOT/sites/default/files
        chgrp -R www-data $DRUPAL_DOCROOT/sites/default/files
        chmod 2775 $DRUPAL_DOCROOT/sites/default/files
        chmod -R g+w $DRUPAL_DOCROOT/sites/default/files
        # Avoid an error: "Allowed memory size of 134217728 bytes exhausted"
        echo 'memory_limit = -1' >> /usr/local/etc/php/conf.d/my-php.ini
          --site-name="Cloud Orchestrator live preview for '${TUGBOAT_PREVIEW_NAME}'" \
          --account-pass='admin' \
          si standard
        # Set up a files directory.
        export FILES_DIR='sites/default/files'
        mkdir -p "${DRUPAL_DOCROOT}/${FILES_DIR}"
        chgrp -R www-data "${DRUPAL_DOCROOT}/${FILES_DIR}"
        chmod 2775 "${DRUPAL_DOCROOT}/${FILES_DIR}"
        chmod -R g+w "${DRUPAL_DOCROOT}/${FILES_DIR}"
        # Set a private directory.
        export PRIVATE_DIR="${FILES_DIR}/private"
        mkdir -p "${PRIVATE_DIR}"
        chgrp -R www-data "${PRIVATE_DIR}"
        chmod 2775 "${PRIVATE_DIR}"
        chmod -R g+w "${PRIVATE_DIR}"
        # Set up $settings['file_private_path'] in settings.php
        export SETTINGS_FILE="${DRUPAL_DOCROOT}/sites/default/settings.php"
        echo "\$settings['file_private_path'] = '${PRIVATE_DIR}';" >> "${SETTINGS_FILE}"
        # Set up $settings['trusted_host_patterns'] in settings.php
        echo "\$settings['trusted_host_patterns'] = ['^.+\.tugboat\.qa$'];" >> "${SETTINGS_FILE}"
        # Enable the Cloud family modules.
        drush -y en cloud cloud_dashboard
        drush -y en aws_cloud gapps
@@ -57,32 +74,49 @@ services:
        drush -y en geocoder
        drush -y en simple_oauth
        # Enable the themes.
        drush -y theme:enable bootstrap_cloud
        drush -y theme:enable claro
        drush -y config:set system.theme default bootstrap_cloud
        drush -y config:set system.theme admin claro
        drush -y then bootstrap_cloud
        drush -y then claro
        drush -y cset system.theme default bootstrap_cloud
        drush -y cset system.theme admin claro
        # Install Memcached libraries.
        apt-get install -y libmemcached-dev
        git clone https://github.com/php-memcached-dev/php-memcached /usr/src/php/ext/memcached
        cd /usr/src/php/ext/memcached
        docker-php-ext-configure memcached
        docker-php-ext-install memcached
        # Install APCU libraries.
        git clone https://github.com/krakjoe/apcu /usr/src/php/ext/apcu
        cd /usr/src/php/ext/apcu
        docker-php-ext-configure apcu
        docker-php-ext-install apcu
        # Install OpCache
        docker-php-ext-install -j "$(nproc)" opcache
        # Setup Memcache module
        drush en -y memcache memcache_admin
        tee -a "${SETTINGS_FILE}" > /dev/null <<EOF
        \$settings['memcache']['servers'] = ['memcached:11211' => 'default'];
        \$settings['memcache']['bins'] = ['default' => 'default'];
        \$settings['memcache']['key_prefix'] = '';
        \$settings['cache']['default'] = 'cache.backend.memcache';
        EOF
        # Setup crontab.
        { echo '*/5 * * * * www-data cd /var/www/cloud_orchestrator && /usr/local/bin/drush cron > /dev/null 2>&1'; } >> /etc/crontab
        { echo '*/5 * * * * www-data cd /var/www/html/web && for MODULE in '\''aws_cloud'\'' '\''k8s'\'' '\''openstack'\'' '\''vmware'\'' '\''terraform'\''; do export QUEUE=$(drush queue-list | grep "$''{MODULE}" | awk '\''{print $1}'\''); if [ "$''{QUEUE}" ]; then drush queue-run "$''{QUEUE}" --time-limit=120 > /dev/null 2>&1; fi done'; } >> /etc/crontab
      build: |
        set -eux
        # Delete and re-check out this branch in case this is built from a Base Preview.
        git branch -D $TUGBOAT_REPO_ID && git checkout -b $TUGBOAT_REPO_ID || true
        git checkout 5.x && git branch -D "${TUGBOAT_REPO_ID}" && git checkout -b "${TUGBOAT_REPO_ID}" || true
        export COMPOSER_MEMORY_LIMIT=-1
        cd $DRUPAL_COMPOSER_ROOT
        cd "${DRUPAL_COMPOSER_ROOT}"
        composer install --optimize-autoloader
        # Update installed modules.
        composer update aws/aws-sdk-php
        composer update drupal/admin_toolbar
        composer update drupal/bootstrap_cloud
        composer update drupal/cloud
        composer update drupal/entity_export_csv
        composer update drupal/geocoder
        composer update drupal/simple_oauth
        composer update google/apiclient
        composer update geocoder-php/nominatim-provider
        composer update maclof/kubernetes-client
        # Set the $PATH for vendor/bin/drush
        export PATH=$PATH:./vendor/bin
        composer update "drupal/cloud:dev-${TUGBOAT_REPO_ID}" --with-all-dependencies
        composer update drupal/memcache
        # Update databases and clear cache.
        drush -y updb
        drush cache:rebuild
        drush cr
  # mysql:
  #   image: tugboatqa/mariadb
  memcached:
    image: tugboatqa/memcached
+2 −1
Original line number Diff line number Diff line
@@ -128,7 +128,8 @@ class CloudConfigPluginManager extends CloudPluginManager implements CloudConfig
    // Load the plugin variant since we know the cloud_context.
    $this->plugin = $this->loadPluginVariant();
    if (empty($this->plugin)) {
      // DO NOT translate the message.  See also: https://www.drupal.org/docs/develop/coding-standards/php-exceptions.
      // DO NOT translate the message.
      // @see https://www.drupal.org/docs/develop/coding-standards/php-exceptions
      throw new CloudConfigPluginException("Cannot load cloud service provider plugin for '{$this->cloudContext}'");
    }
  }