Skip to content

Instantly share code, notes, and snippets.

@mickadoo
Created July 23, 2018 15:53
Show Gist options
  • Save mickadoo/f5220e6f854161076af258b03edd3691 to your computer and use it in GitHub Desktop.
Save mickadoo/f5220e6f854161076af258b03edd3691 to your computer and use it in GitHub Desktop.

Overview

compudeploy creates, deploys and updates CiviCRM websites

Requirements

  • The creation command should take a single repository URL
  • The host for the site should be flexible: local host, local vagrant, local docker, remote host, AWS
  • The type of site should be flexible: a profile or a "full site" repository

Commands

Add Server

Adds a server configuration for deployment

compubuild add-server --type=remote --name=testing1 --target=<target>
  • name: The name of the configuration
  • type: What kind of server is it. For example jenkins, remote, aws, local or docker
  • target: Not required for all types, but if a server is remote points to where it is located

Create

Creates a new site

compubuild create --repo=http://bitbucket.org/compucorp/mysite \
  --build-dir=/var/www/mysite \
  --url=mysite.civihr.net \
  --server=testing1 \
  --name=testing1 \
  --git-ref=CGP-my-feature-branch \
  --git-merge-ref=CGP-my-workstream-branch \
  --cms-db=./dumps/drupal-test.sql \
  --civi-db=./dumps/civi-test.sql
  • name: The name of the site
  • server: Which server it should be deployed to
  • url: The URL for the site
  • build-dir: Where on the server the site should be created
  • repo: What repository to use to create the site
  • git-ref: Optional branch of the repository to check out before building
  • git-merge: Optional branch to merge into git-ref before building
  • cms-db: Allows import of a certain database before running upgraders for Drupal. Supports local and remote files
  • civi-db: Allows import of a certain database before running upgraders for CiviCRM. Supports local and remote files

Deploy

Deploys code changes to an existing site

compubuild deploy
  --name=testing1 \
  --git-ref=CGP-my-feature-branch \
  --git-merge-ref=CGP-my-workstream-branch
  --skip-upgraders \
  --cms-db=scp://123.23.234.42/dumps/drupal.mysql \
  --civi-db=scp://123.23.234.42/dumps/civicrm.mysql
  • name: The name of the site
  • git-ref: Optional branch of the repository to check out
  • git-merge: Optional branch to merge into git-ref
  • skip-upgraders: Whether to run the Drupal and CiviCRM upgraders during deployment
  • cms-db: Allows import of a certain database before running upgraders for Drupal. Supports local and remote files
  • civi-db: Allows import of a certain database before running upgraders for CiviCRM. Supports local and remote files

Destroy

Destroy all resources related to a site: db, files, vhosts

compubuild destroy --name=mysite
  • name: The name of the site to destroy

Snapshot

Takes a snapshot of the database

compubuild snapshot --name=mysite --snapshot-name=pre-release
  • name: the name of the site
  • snapshot-name: the name to store the snapshot as, defaults to "default"

Restore

Restores the databases using a snapshot name or defaults to "default" if none provided

compubuild restore --name=mysite --snapshot-name=pre-release
  • name: the name of the site
  • snapshot-name: the name to store the snapshot as, defaults to "default"

Exec

Executes a command on a site and returns the result

compubuild exec --name=mysite --dir=profiles/compuclient --cmd=phpunit4
  • name: The name of the site
  • dir: The directory from where the command should be executed
  • cmd: The command to run

Use Cases

I want to create a local development site for a client site

add-server --type=local --name=local
create --repo=http://bitbucket.org/compucorp/mysite \
  --build-dir=/home/michael/sites/mysite \
  --url=mysite.local \
  --server=local \
  --name=local-mysite

I want to create a local development site using Vagrant

add-server --type=vagrant --name=vagrant1
create --repo=http://bitbucket.org/compucorp/mysite \
  --build-dir=/home/michael/sites/mysite \
  --url=mysite.local \
  --server=vagrant1 \
  --name=local-mysite

I want to create a client site on a testing server

add-server --type=remote --name=testing1 --target=184.112.23.23
create --repo=http://bitbucket.org/compucorp/mysite \
  --build-dir=/var/www/mysite \
  --url=mysite.civihr.net \
  --server=testing1 \
  --name=testing1

I want to do manual testing of a PR for a client site

add-server --type=remote --name=testing1 --target=184.112.23.23
create --repo=http://bitbucket.org/compucorp/mysite \
  --build-dir=/var/www/mysite \
  --url=mysite.civihr.net \
  --server=testing1 \
  --git-ref=CGP-my-new-branch \
  --name=pr221 

I want to run automated tests for a PR for a client site

add-server --type=remote --name=testing1 --target=184.112.23.23
create --repo=http://bitbucket.org/compucorp/mysite \
  --build-dir=/var/www/mysite \
  --url=mysite.civihr.net \
  --server=testing1 \
  --git-ref=CGP-my-new-branch \
  --name=pr221 
exec --dir=/var/www/mysite/profiles/compuclient phpunit4

I want to deploy a site permanently to AWS

add-server --type=aws --name=aws1
create --repo=http://bitbucket.org/compucorp/mysite \
  --build-dir=/var/www/mysite \
  --url=mysite.civihr.net \
  --server=aws1

I want to deploy a site permanently to a remote host

add-server --type=remote --name=mysite --target=184.112.23.23
create --repo=http://bitbucket.org/compucorp/mysite \
  --build-dir=/var/www/mysite \
  --url=mysite.civihr.net \
  --server=mysite 

I want to upgrade an existing remote site

add-server --type=remote --name=mysite --target=184.112.23.23
create --repo=http://bitbucket.org/compucorp/mysite \
  --build-dir=/var/www/mysite \
  --url=mysite.civihr.net \
  --server=mysite 
  --name=mysite
deploy --name=mysite --git-ref=1.1.0

I want to make a backup before release, try release and restore site if it fails

add-server --type=remote --name=mysite --target=184.112.23.23
create --repo=http://bitbucket.org/compucorp/mysite \
  --build-dir=/var/www/mysite \
  --url=mysite.civihr.net \
  --name=mysite \
  --server=mysite \
  --git-ref=1.0.0
snapshot --name=mysite --name=pre-relase
deploy --name=mysite --git-ref=1.1.0 #returns failure
restore --name=mysite --name=pre-release
deploy --name=mysite --git-ref=1.0.0

I want to deploy a branch to a test site, using a dump of the database

add-server --type=remote --name=mysite --target=184.112.23.23
create --repo=http://bitbucket.org/compucorp/mysite \
  --build-dir=/var/www/mysite \
  --url=mysite.civihr.net \
  --server=testing1 \
  --git-ref=CGP-my-new-branch \
  --name=pr221 \
  --cms-db=./../dumps/brochure_drupal.mysql \
  --civi-db=./../dumps/brochure_civicrm.mysql

I want to deploy a branch to a test site, using the latest anonymized version of the database

add-server --type=remote --name=dev1 --type=aws
create --repo=http://bitbucket.org/compucorp/mysite \
  --build-dir=/var/www/mysite \
  --server=testing1 \
  --git-ref=CGP-my-new-branch \
  --name=pr221 \
  --cms-db=scp://123.23.234.42/dumps/drupal.mysql \
  --civi-db=scp://123.23.234.42/dumps/civicrm.mysql

I want to clean up an old site to save memory

add-server --type=remote --name=mysite --target=184.112.23.23
create --repo=http://bitbucket.org/compucorp/mysite \
  --build-dir=/var/www/mysite \
  --url=mysite.civihr.net \
  --server=testing1 \
  --git-ref=CGP-my-new-branch \
  --name=pr221 
destroy pr221

Milestones

  • [] create brochure-site from master in Vagrant
  • [] create brochure-site from master in Docker-
  • [] create profile site from compuclient master in Vagrant
  • [] create brochure-site and use imported db dumps
  • [] create brochure-site based of different branch
  • [] create brochure-site with different branch and merge staging
  • [] create profile site in remote host
@steliosmilidonis
Copy link

1.For Creating a new site. Usually we need the anonymized db here if its a development server, or just the ability to create databases. In any case you need to provide with database credentials, perhaps information that needs to be provides in the "add server" step for the root mysql user and the user and databases that will be created under the create new site stage.

2.For Snapshots as i understand it you will be backups of directory and db saving them with a date or name stamp so you can restore right?

3.Should we be supplying git credentials or should they exist on the server?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment