Skip to content

Commit

Permalink
Merge pull request #18 from maschmann/process_improvements
Browse files Browse the repository at this point in the history
Process improvements
  • Loading branch information
maschmann committed May 24, 2015
2 parents d173dd8 + ecc95a1 commit 97c16d3
Show file tree
Hide file tree
Showing 6 changed files with 110 additions and 35 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
ansible.cfg
10 changes: 9 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,14 @@
# Changelog

## v0.3

* working travis-ci tests
* datetime release dirs by default
* configurable migrations and schema update
* README update

## v0.2

* fixed merge errors
* fixed deployment issues with config if already exists in project
* fixed issue with missing SYMFONY_ENV while composer install
Expand All @@ -10,4 +18,4 @@
## v0.1

* structural refactoring (creating files, directories, ...)
* added cleanup-script to remove old releases
* added cleanup-script to remove old releases
109 changes: 82 additions & 27 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,36 +1,71 @@
Symfony2
========
# Symfony2

Ansible role to easily deploy Symfony2 applications. It will clone a git repository, download and run composer install, and run assetic:dump when finished. The resulting directory structure is similar to what capifony creates:
Ansible role to easily deploy Symfony2 applications.
It will clone a git repository, a specific branch or a tag, download and run composer install, and run assetic:dump when finished.
The resulting directory structure is similar to what capifony creates:

```
project
composer.phar
releases
release
shared
web/uploads
app/config
app/logs
web
uploads
app
config
logs
current -> symlink to latest deployed release
```

Requirements
------------
It will also keep the ```releases``` directory clean and deletes all but your configured amount of releases.
You're also able to switch on/off whether ansible should execute doctrine migrations, or mongodb schema update, etc.

None
## Requirements

Installed version of Ansible.

Installation
------------
## Installation

### Ansible galaxy

```
$ ansible-galaxy install servergrove.symfony2
```

### Usage

Including an example of how to use your role (for instance, with variables passed in as parameters) is always nice for users too:

```yaml
---
- hosts: servers
roles:
- ansible-symfony2

vars:
symfony2_project_root: /test_app
symfony2_project_name: travis-test
symfony2_project_composer_path: /test_app/shared
symfony2_project_repo: https://github.com/symfony/symfony-standard.git
symfony2_project_branch: "2.6"
symfony2_project_php_path: php
symfony2_project_env: prod
symfony2_project_console_opts: '--no-debug'
symfony2_project_composer_opts: '--no-dev --optimize-autoloader'
symfony2_project_keep_releases: 5
symfony2_project_clean_versioning: true
```
## Role Variables
Role Variables
--------------
### Possible variables
These are the possible role variables - you only need to have a small set defined, there are defaults.
```yaml
---
- vars:
symfony2_project_root: Path where application will be deployed on server.
symfony2_project_name: Name of project.
Expand All @@ -44,30 +79,50 @@ Role Variables
symfony2_project_composer_opts: '--no-dev --optimize-autoloader'
symfony2_project_keep_releases: 5
symfony2_project_clean_versioning: true
symfony2_fire_schema_update: false # Runs doctrine:mongodb:schema:update
symfony2_fire_migrations: false # Runs doctrine migrations script
```
Dependencies
------------
### Role variable defaults
As you can see, the release number default is the current date/time with seconds to allow for easy multiple releases per day. But you can always overwrite with ```--extra-vars=""``` option.

```yaml
---
- vars
symfony2_project_release: <datetime> # internally replaced with YmdHis
symfony2_project_branch: master
symfony2_project_php_path: /usr/bin/php
symfony2_project_keep_releases: 5
symfony2_project_clean_versioning: true
symfony2_project_console_opts: ''
symfony2_project_composer_opts: '--no-dev --optimize-autoloader'
symfony2_fire_schema_update: false
symfony2_fire_migrations: false
```

## Dependencies

None

Example Playbook
-------------------------
## Testing

Including an example of how to use your role (for instance, with variables passed in as parameters) is always nice for users too:
The deployment contains a basic test, executed by travis. If you want to locally test the role, have a look into ```.travis.yml``` for the exceution statements and (maybe) remove the ```geerlingguy.php ``` from ```tests/test.yml``` if you have a local php executable (needed for composer install and symfony console scripts).

```yaml
- hosts: servers
roles:
- { role: servergrove.symfony2, symfony2_project_root: /var/www/vhosts/example.com/, symfony2_project_name: demo, symfony2_project_branch: master, symfony2_project_release: 1 }
The test setup looks like this:

```
servergrove.symfony2
tests
inventory # hosts information
test.yml # playbook
.travis.yml # travis config
```

License
-------
## License

MIT
[MIT](LICENSE) license

Author Information
------------------
### Author Information

Contributions are welcome: https://github.com/servergrove/ansible-symfony2
8 changes: 6 additions & 2 deletions defaults/main.yml
Original file line number Diff line number Diff line change
@@ -1,8 +1,12 @@
---
# defaults file for symfony2

symfony2_project_release: 1
symfony2_project_release: ~
symfony2_project_branch: master
symfony2_project_php_path: php
symfony2_project_keep_releases: 5
symfony2_project_clean_versioning: true
symfony2_project_clean_versioning: true
symfony2_project_console_opts: ''
symfony2_project_composer_opts: '--no-dev --optimize-autoloader'
symfony2_fire_schema_update: false
symfony2_fire_migrations: false
10 changes: 9 additions & 1 deletion tasks/main.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
---
# tasks file for symfony2
- set_fact: symfony2_project_release={{ lookup('pipe', 'date +%Y%m%d%H%M%S') }}
when: symfony2_project_release == None

- name: Create/prepare directories for release and shared data.
file: state=directory path={{item.path}}
with_items:
Expand Down Expand Up @@ -61,7 +64,12 @@
shell: cd {{symfony2_project_root}}/releases/{{symfony2_project_release}} && {{symfony2_project_php_path}} app/console assetic:dump --env={{symfony2_project_env}} {{symfony2_project_console_opts}}

- name: Run migrations.
shell: cd {{symfony2_project_root}}/releases/{{symfony2_project_release}} && if $(grep doctrine-migrations-bundle composer.json); then {{symfony2_project_php_path}} app/console doctrine:migrations:migrate -n; fi
shell: cd {{symfony2_project_root}}/releases/{{symfony2_project_release}}_{{symfony2_project_branch}} && if $(grep doctrine-migrations-bundle composer.json); then {{symfony2_project_php_path}} app/console doctrine:migrations:migrate -n; fi
when: symfony2_fire_migrations == true

- name: Run mongodb schema update.
shell: cd {{symfony2_project_root}}/releases/{{symfony2_project_release}}_{{symfony2_project_branch}} && if $(grep mongodb-odm composer.json); then {{symfony2_project_php_path}} app/console doctrine:mongodb:schema:update --no-interaction; fi
when: symfony2_fire_schema_update == true

- name: Create symlink.
file: state=link src={{symfony2_project_root}}/releases/{{symfony2_project_release}} path={{symfony2_project_root}}/current
Expand Down
7 changes: 3 additions & 4 deletions tests/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,14 @@
- ansible-symfony2

vars:
symfony2_project_root: ~/test_app
symfony2_project_root: /test_app
symfony2_project_name: travis-test
symfony2_project_composer_path: ~/test_app/shared
symfony2_project_composer_path: /test_app/shared
symfony2_project_repo: https://github.com/symfony/symfony-standard.git
symfony2_project_release: 1
symfony2_project_branch: "2.6"
symfony2_project_php_path: php
symfony2_project_env: prod
symfony2_project_console_opts: '--no-debug'
symfony2_project_composer_opts: '--no-dev --optimize-autoloader'
symfony2_project_keep_releases: 5
symfony2_project_clean_versioning: true
symfony2_project_clean_versioning: true

0 comments on commit 97c16d3

Please sign in to comment.