2017 © Pedro Peláez
 

symfony-bundle deploy-bundle

Symfony application deploy bundle

image

sokil/deploy-bundle

Symfony application deploy bundle

  • Tuesday, July 4, 2017
  • by sokil
  • Repository
  • 2 Watchers
  • 3 Stars
  • 85 Installations
  • PHP
  • 0 Dependents
  • 4 Suggesters
  • 1 Forks
  • 24 Open issues
  • 16 Versions
  • 0 % Grown

The README.md

DeployBundle

Task runner for Symfony project, (*1)

Latest Stable Version Total Downloads Build Status Coverage Status, (*2)

Installation

Add Composer dependency:, (*3)

composer.phar require sokil/deploy-bundle

Add bundle to your AppKernel:, (*4)

<?php

class AppKernel extends Kernel
{
    public function registerBundles()
    {
        $bundles = array(
            new Sokil\DeployBundle\DeployBundle(),
        );
    }
}

Configuration

Configure tasks required to run in your app in app/config/config.yml:, (*5)

deploy:
  config:
    git: {}
    composer: {}
    npm: {}
    bower: {}
    grunt: {}
    asseticDump: {}
    assetsInstall: {}
  tasks:
    updateBack: [git, composer]
    updateFront: [npm, bower]
    compileAssets: [grunt, asseticDump, assetsInstall]
    release: [updateBack, updateFront, compileAssets]

Section config declared options of every task, able to run. Section tasks declares bundles of tasks, which run sequentially. Tasks may be run by defining task aliases in cli command:, (*6)

$ ./app/console deploy --git --npm

Also tasks bundles may be defined:, (*7)

$ ./app/console deploy --compileAssets

If no task specified then default task bundle will be run. This task bundle may be defined in configuration, but if it omitted, then default task consists of all tasks in order of config section. Tasks and task bundles both may be specified in cli options, then tasks will be run in order of first occurrence. Task bundle also may contain other bundles., (*8)

To get list of all configured tasks run:, (*9)

$ ./bin/console deploy --env=prod -h
Usage:
  deploy [options]

Options:
      --composer                   Update composer dependencies
      --composer-update            Update dependencies instead of install it
      --migrate                    Migrate datbase
      --npm                        Updating npm dependencies
      --bower                      Updating bower dependencies
      --grunt                      Run grunt tasks in bundles
      --grunt-tasks[=GRUNT-TASKS]  List of bundles with specified grunt tasks, e.g. "bundle1Name:task1Name,task2Name;bundle2Name;"
      --asseticDump                Dump assetic assets
      --assetsInstall              Install bundle assets
      --clearCache                 Clear cache
      --updateFront                Task bundle for tasks "npm","bower"
      --compileAssets              Task bundle for tasks "grunt","asseticDump","assetsInstall","clearCache"
      --release                    Task bundle for tasks "composer","migrate","updateFront","compileAssets"
      --default                    Task bundle for tasks "composer","migrate","npm","bower","grunt","asseticDump","assetsInstall","clearCache"

Tasks

Git

Configuring git task

Add configuration to your ./app/config/config.yml:, (*10)

deploy:
  config:
    git:
        defaultRemote: origin       # Optional. Default: origin. Set default remote for all repos
        defaultBranch: master       # Optional. Default: master. Set default branch for all repos
        repos:                      # List of repos
          core:                     # Alias of repo
            path: /var/www/project  # Path to repo
            remote: origin          # Optional. Default: origin. Set remote for this repo
            branch: master          # Optional. Default: master. Set branch for this repo
            tag: false              # Tag release after pull

Private repositories

If repository is private, password will be asked on pull:, (*11)

Permission denied (publickey).
fatal: Could not read from remote repository.

Please make sure you have the correct access rights
and the repository exists.

For example web server started under www-data user. To prevent asking password, add ssh keys to /home/$USER/.ssh directory, using ssh key generation tool., (*12)

1) Generate keys:, (*13)

$ sudo -u www-data ssh-keygen -t rsa
Generating public/private rsa key pair.
Enter file in which to save the key (/home/www-data/.ssh/id_rsa): 
Enter passphrase (empty for no passphrase): 
Enter same passphrase again: 
Your identification has been saved in /home/www-data/.ssh/id_rsa.
Your public key has been saved in /home/www-data/.ssh/id_rsa.pub.
The key fingerprint is:
...

2) Add public key to your repository to fetch changes without password prompt., (*14)

3) Test your connection:, (*15)

$ sudo -H -u www-data git pull origin master

Find out who use this key already:, (*16)

ssh -T git@github.com
ssh -T git@bitbucket.com

Webpack

You can optionally specify path to webpack in pathToWebpack parameter. If omitted , then webpack will be used. In this case webpack must be installed globally., (*17)

deploy:
  config:
    webpack:
      pathToWebpack: assets/node_modules/.bin/webpack # (Optional) Path to webpack
      projects: # list of webpack projects with own webpack.config.js inside
        assets:
          config: "assets/webpack.config.js" # (required) path to config. Context will be set to dirname of config.
          progress: true # (optional) Show build progress
          p: true # (optional) Build for production. For "prod" environment defined automatically
          ...

This will run command, where context value is dirname of config in parameters config:, (*18)

assets/node_modules/.bin/webpack --config assets/webpack.config.js -p --progress --context assets

Npm

deploy:
  config:
    npm:
      dirs: # Optional list of dirs to search package.json and install dependencies
        - "assets"
      bundles: # Optional list of bundles where to search package.json
        SomeBundle: true
        SomeOtherBundle:
           package: ../ # path to project.json, relative to SomeOtherBundle.php file

Bower

deploy:
  config:
    bower:
      bundles:
        SomeBundle: true
        SomeOtherBundle: true

Grunt

Add task configuration to your deploy config:, (*19)

deploy:
  config:
    grunt:
      bundles: # bundles where grunt need to be run
        SomeBundle1: true
        SomeBundle2:
          tasks: [task1, task2, task3]
          gruntfile: ../ # dir with Gruntfile.js, relatively to SomeBundle2.php

      parallel: true # run grunts from all bundles in parallel. Default: false

Grunt may have few tasks, and you can select which tasks to run., (*20)

In config:, (*21)

deploy:
  config:
    grunt:
      bundles:
        SomeBundle:
          tasks:
            - newer:less 
            - newer:jade
        SomeOtherBundle: true
      parallel: true

As CLI parameter:, (*22)

./app/console deploy --grunt --grunt-tasks="SomeBundle=newer:less,newer:jade&SomeOtherBundle"

Migrations

Add dependency:, (*23)

composer.phar require doctrine/migrations
composer.phar require doctrine/doctrine-migrations-bundle

Register bundler in AppKerner:, (*24)

new Doctrine\Bundle\MigrationsBundle\DoctrineMigrationsBundle(),

First, configure migrations in ./app/config/config.yml:, (*25)

doctrine_migrations:
    dir_name: %kernel.root_dir%/migrations
    namespace: Migrations
    table_name: migrations
    name: Application Migrations

Then add task to deploy config in ./app/config/config.yml:, (*26)

deploy:
  config:
    migrate: {}

Install Assets

Then add task to deploy config in ./app/config/config.yml:, (*27)

deploy:
  config:
    assetsInstall: {}

Dump Assetic

Then add task to deploy config in ./app/config/config.yml:, (*28)

deploy:
  config:
    asseticDump: {}

Bundles with Assetic assets must be defined in ./app/config/config.yml:, (*29)

assetic:
  bundles:
    - AcmeBundle

Composer

This task will run composer command:, (*30)

composer.phar install --optimize-autoloader --no-interaction

File composer.phar must be in path, or you can redefine path to composer by param path., (*31)

Add task config to ./app/config/config.yml:, (*32)

deploy:
  config:
    composer:
      scripts: true # set true if you want to execute scripts. Default: true
      update: true # Optional. If passed, update dependencied instead on install
      path: composer.phar # Optiona. Default: composer.phar, specify path to composer

Clear cache

deploy:
  config:
    clearCache: {}

Sync

Task userd to sync data to production servers. Add configuration:, (*33)

deploy:
  config:
    parallel: 3
    rules:
      web:
        src: '.'
        dest:
          - user@www1.server.com://var/www/some
          - user@www2.server.com://var/www/some
        delete: true
        verbose: true
        exclude:
          - /var
          - /app/conf/nginx/
          - /.idea
          - /app/config/parameters.yml
        include:
          - /app/conf/nginx/*.conf.sample

Parameter rules define rules to sync files from source to destination. May be configured any number of rules. Every rule consists of parameter src (defaults to "."), parameter dest which may be string or array of hosts. Other rule parameters same to rsync options. See man page of rsync to find description of this options., (*34)

Writing own tasks

First, create task class which extends Sokil\DeployBundle\Task\AbstractTask. Then add Symfony's service definition:, (*35)

acme.deploy.my_task:
  class: Acme\Deploy\Task\MyTask
  abstract: true
  public: false
  tags:
    - {name: "deploy.task", alias: "myTask"}

This service must contain tag with name deploy.task and alias, which will be used as CLI command's option name and configuration section name., (*36)

Then, you may add it to bundle's configuration in app/config/config.yml to deploy section in proper place of order, if you want it to be run automatically:, (*37)

deploy:
  config:
    git: {}
    grunt: {}
    myTask: {}

Now, your task will be calld third after git and grunt by calling deploy command without arguments:, (*38)

$ ./app/console deploy --env=prod

You also may call your task directly from console:, (*39)

$ ./app/console deploy --myTask

The Versions

19/03 2017

0.6.11

0.6.11.0

Symfony application deploy bundle

  Sources   Download

MIT

The Requires

  • php ^5.5 || ^7.0

 

The Development Requires

by Dmytro Sokil

14/02 2017

0.6.10

0.6.10.0

Symfony application deploy bundle

  Sources   Download

MIT

The Requires

  • php ^5.6 || ^7.0

 

The Development Requires

by Dmytro Sokil

10/11 2016

0.6.9

0.6.9.0

Symfony application deploy bundle

  Sources   Download

MIT

The Requires

  • php ^5.6 || ^7.0

 

The Development Requires

by Dmytro Sokil

10/11 2016

0.6.8

0.6.8.0

Symfony application deploy bundle

  Sources   Download

MIT

The Requires

  • php ^5.6 || ^7.0

 

The Development Requires

by Dmytro Sokil

08/11 2016

0.6.7

0.6.7.0

Symfony application deploy bundle

  Sources   Download

MIT

The Requires

  • php ^5.6 || ^7.0

 

The Development Requires

by Dmytro Sokil

06/10 2016

0.6.6

0.6.6.0

Symfony application deploy bundle

  Sources   Download

MIT

The Requires

  • php ^5.6 || ^7.0

 

The Development Requires

by Dmytro Sokil

05/10 2016

0.6.5

0.6.5.0

Symfony application deploy bundle

  Sources   Download

MIT

The Requires

 

The Development Requires

by Dmytro Sokil

11/09 2016

0.6.4

0.6.4.0

Symfony application deploy bundle

  Sources   Download

MIT

The Requires

 

The Development Requires

by Dmytro Sokil

11/09 2016

0.6.3

0.6.3.0

Symfony application deploy bundle

  Sources   Download

MIT

The Requires

 

The Development Requires

by Dmytro Sokil

04/09 2016

0.5

0.5.0.0

Symfony application deploy bundle

  Sources   Download

MIT

The Requires

 

The Development Requires

by Dmytro Sokil

02/09 2016

0.4.4

0.4.4.0

Symfony application deploy bundle

  Sources   Download

MIT

The Requires

 

The Development Requires

by Dmytro Sokil

15/08 2016

0.4.3

0.4.3.0

Symfony application deploy bundle

  Sources   Download

MIT

The Requires

 

The Development Requires

by Dmytro Sokil