Development and deployment with composer and kite

13
Development and deployment with composer and kite

Transcript of Development and deployment with composer and kite

Page 1: Development and deployment with composer and kite

Development and deployment with composer

and kite

Page 2: Development and deployment with composer and kite

What’s composer?● Tool for dependency management in PHP applications● Command line app written in PHP● Manages packages on a per-project basis (unlike Apt, Yum etc.)● Strongly inspired by similar projects in other languages like npm or bundler

● Suppose:○ You have a project that depends on a number of libraries.○ Some of those libraries depend on other libraries.

● Composer:○ Enables you to declare the libraries you depend on.○ Finds out which versions of which packages can and need to be installed, and installs them

(meaning it downloads them into your project).

Page 3: Development and deployment with composer and kite

composer: Basic Usage

● Everything related to composer is a kept in a composer.json at project or package root

● Package names:○ vendor/package-name

● Versions:○ Semantic versioning: x.y.z[-stability]

■ x: Major version (potentially breaking changes)■ y: Minor version (new, compatible functionality)■ z: Patch version (bug fixes)

■ stability flag: Flag stating the stability of a pre-release (e.g. 2.0.0-alpha)

○ Branch names, prefixed by dev- (e.g. dev-master)○ Specific revisions (e.g. dev-master#9823928)

{ "name": "netresearch/project", "require": { "typo3/cms": "6.2.*" }, "require-dev": { "phpunit/phpunit": "^4.2" }}

Page 4: Development and deployment with composer and kite

composer: Version constraints● Exact: 1.2.7● Range:

○ >=1.0

○ >=1.0 <2.0 (AND)○ >=1.0 <1.1 || >=1.2

○ 1.0 - 2.0 ≙ >=1.0.0 <2.1 ○ 1.0.0 - 2.1.0 ≙ >=1.0.0 <=2.1.0

● Next significant release (tilde vs. caret):○ ~1.2 ≙ >=1.2 <2.0.0○ ~1.2.3 ≙ >=1.2.3 <1.3.0 ○ ^1.2 ≙ >=1.2.0 <2.0.0○ ^1.2.3 ≙ >=1.2.3 <2.0.0○ ^0.3 ≙ >=0.3.0 <0.4.0 (security behaviour for pre-1.0 versions only)

Page 5: Development and deployment with composer and kite

composer: Example project{

"repositories": [ { "type": "composer", "url": "https://composer.typo3.org" } ],

"name": "netresearch/project",

"description" : "Siamar typo3 root project",

"config": { "platform": { "php": "5.5" } },

"license": "proprietary",

"minimum-stability": "dev",

"prefer-stable": true,

"require": {

"typo3/cms": "~6.2",

"typo3-ter/realurl": "*"

}

}

Page 6: Development and deployment with composer and kite

composer: Example package{

"name": "netresearch/kite",

"description": "Yet another build and deployment tool - inspired by TYPO3.Surf",

"license": "MIT",

"require": {

"symfony/expression-language": "~2.7",

"symfony/console": "~2.7",

"symfony/process": "~2.7",

"php": ">=5.4.0"

},

"autoload": { "psr-4": { "Netresearch\\Kite\\": "src/" } },

"autoload-dev": { "psr-4": { "Netresearch\\Kite\\Test\\": "tests/" } },,

"bin": ["bin/kite"]

}

Page 7: Development and deployment with composer and kite

composer: Common commands● composer init

○ Assistant to create the composer.json for a new project

● composer install [--optimize-autoloader]○ Installs all packages at their state locked in composer.lock○ If composer.lock isn’t present, it does the same as composer update○ Generates autoloader

● composer update○ Installs the latest package versions (matching the required constraints)○ Uninstalls packages that are installed but not required anymore○ Generates autoloader

● composer show [--installed]○ Shows the installed packages and their versions

● composer require "package=1.2.7"○ Adds package to require in composer.json and installs it

Page 8: Development and deployment with composer and kite

composer: The lock file● composer.lock

○ Lists packages & versions○ Replaces composer.json○ Created by composer install (installs your dependencies)○ Updated by composer update (updates your dependencies)○ SHOULD be committed in your VCS and shipped with your releases

● Benefits○ Everyone on a team works with exactly the same dependency versions○ When deploying, all machines run exactly the same dependency versions○ Users will never get dependency versions that you did not test with

● Cons○ Hindering during development: The exact revision of dev packages is locked => rebase and

merge are painful○ => Workaround: Advanced checkout, merge and deployment with kite

Page 9: Development and deployment with composer and kite

What’s kite?● Yet another build automation tool inspired by TYPO3.Surf● Everything in PHP: The tool itself as well as all configuration● ECMA like variable access:

○ Sub tasks can access variables from parent but can set them on their own as well

○ Advanced logic during execution possible by using expressions(utilizing Symfony Expression Language)

● Node based:○ Unlimited number of remote targets possible○ Nodes can be set globally or only for specific (sub) tasks○ Remote tasks operate on all current nodes

● Dry-Run available by design (yet the tasks to include need to be configured)● Originally planned and built as TYPO3 extension but later on ported to

generic composer package - installable globally or per project

Page 10: Development and deployment with composer and kite

kite: Task organization● Tasks

○ Smallest, predefined steps (currently: answer, break, callback, choose, composer, confirm, evaluate, exit, fs, git, include, iterate, output, phar, remoteShell, sub, tar, tryCatch)

● Workflows○ Sets of tasks predefined in classes○ Top level workflows can expose command line arguments and options

● Jobs○ Available as commands on command line○ Set of tasks and/or workflows defined in arrays (in arbitrary depth)○ Configurable command line arguments and options

● Presets○ Configuration presets (including f.i. common jobs)

● Configuration file (typo3conf/Kite.php, app/etc/kite.php, kite.php)○ Defines the jobs; can load and override presets

Page 11: Development and deployment with composer and kite

kite: Common jobs● kite [help command]

○ Gives a list of all available commands (jobs) or shows help for the given one

● kite checkout [--merge] branch○ Goes through all composer packages and checks out the branch there if it’s available

○ After checking out the branch on a package it goes through all packages requiring it and updates the version constraint to that branch

○ When --merge is passed, the currently checked out branch is merged into the branch to checkout

● kite merge [--squash] [--message=”Message”] branch○ Goes through all composer packages and merges the branch into the currently checked out

● kite package-foreach [--git] command○ Runs a command for each composer package (optionally only dev packages)

● kite cc, kite ccr [stage]○ Clears caches locally (cc) or on all nodes of a specific stage

Page 12: Development and deployment with composer and kite

kite: Deployment jobs● kite deploy [stage]

○ Runs the deployment for all nodes on the given or selected stage

● kite rollout [stage]○ Runs the deployment for all nodes for each stage until (including) the given stage

Page 13: Development and deployment with composer and kite

Links- Composer homepage and documentation

http://getcomposer.orghttp://slides.seld.be/ (lists slides for some advanced composer talks)

- Packagisthttp://packagist.org

- Kite on githubhttps://github.com/netresearch/kite

- Kite on packagisthttps://packagist.org/packages/netresearch/kite

- Kite task and workflow referencehttps://github.com/netresearch/kite/blob/master/docs/reference.rst