Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Practical deployments for average projects

Practical deployments for average projects

It makes a lot of sense to have a fully automated continuous integration system for your large SaaS product. But what about your average web project? Does this sort of infrastructure make sense for your company website or even your friend's blog? After all, FTP works fine, right? Well you might be surprised to learn how many awesome tools are available for even the smallest projects. In this talk I'll outline some practical approaches to automating your “average project” deployments. This includes how to actually copy your files to your deployment server, run your tests, install Composer dependencies, complete database migrations and more.

Jonathan Reinink

March 14, 2015
Tweet

More Decks by Jonathan Reinink

Other Decks in Technology

Transcript

  1. Jonathan Reinink
    Canadian web developer.

    View full-size slide

  2. Plates
    A native PHP template system.

    View full-size slide

  3. Glide
    On-demand image manipulation library

    View full-size slide

  4. Deployments
    Moving your apps from dev to production.

    View full-size slide

  5. Average Projects
    What do they look like?

    View full-size slide

  6. Deployment
    Mistakes

    View full-size slide

  7. Developed directly on the production server
    Manually uploaded files over FTP
    I’ve included my vendor directory in my repo
    Migrated my DB directly from PhpMyAdmin
    SSH’d into production server to do a
    `git pull` or `composer install`
    I didn’t deploy as often as I should
    Other team members couldn’t deploy

    View full-size slide

  8. Edit files in nano on the server.
    Continuous deployment achieved.
    —Jeff Carouth


    View full-size slide

  9. Life is too short to deploy
    manually over FTP
    —Joel Clermont


    View full-size slide

  10. (continuous)
    Deployments

    View full-size slide

  11. Increased
    Productivity
    Allowed me to focus on my work.

    View full-size slide

  12. Less Errors
    Computers are better at repetitive tasks.

    View full-size slide

  13. Why not?
    I'm a programmer. That stuff for DevOps.
    Tools like Jenkins and Capistrano look way too confusing.
    My projects are too small to bother.
    The tooling is too expensive.
    I’m only one dev, is it really worth the effort?

    View full-size slide

  14. Key Tasks
    We need to move some code.
    We need to install our dependencies.
    We need to migrate our database.
    We need to compile/minify assets.
    We need to flush our cache/run optimizations.

    View full-size slide

  15. Bonus Tasks
    Run tests to verify that they pass.
    Check coding standards.
    Automated code analysis.

    View full-size slide

  16. Wish List
    More than one developer can deploy.
    Configuration must be minimal.
    All configuration online in one place.
    It has to be affordable.
    Deployment should happen automatically.

    View full-size slide

  17. Approaches
    PaaS Products
    Deployment Services
    CI Services
    Task Runners

    View full-size slide

  18. PaaS
    Products
    Hosting with built-in deployment tools.

    View full-size slide

  19. # You need a composer.json file
    echo "{}" > composer.json
    !
    # Create a new Heroku app
    heroku create mynewapp
    !
    # Any you domains
    heroku domains:add mynewapp.com
    heroku domains:add
    www.mynewapp.com
    !
    # Push your code to master
    git push heroku master

    View full-size slide

  20. {
    "require": {
    "php": "~5.6.0",
    "ext-gd": "*",
    },
    "scripts": {
    "post-install-cmd": [
    "php artisan clear-compiled",
    "php artisan optimize"
    ],
    "compile": [
    "php artisan migrate --force"
    ]
    }
    }

    View full-size slide

  21. Pushing to [email protected]:myrepo.git
    Warning: Permanently added 'heroku.com,50.19.85.156' (RSA) to t
    Fetching repository, done.
    -----> Fetching custom git buildpack... done
    -----> PHP app detected
    -----> No runtime required in composer.json, defaulting to PHP
    -----> Installing system packages...
    - PHP 5.6.6
    - Apache 2.4.10
    - Nginx 1.6.0
    -----> Installing PHP extensions...
    - exif (composer.lock; bundled)
    - gd (composer.lock; bundled)
    - mbstring (composer.lock; bundled)
    - zend-opcache (automatic; bundled)
    -----> Installing dependencies...
    Composer version 1.0-dev (833ce984264204e7d6576ab082660105c7d8f
    Loading composer repositories with package information
    Installing dependencies from lock file

    View full-size slide

  22. # Add your Fortrabbit remote address to Git
    git remote add fortrabbit [email protected]...
    !
    # Make a commit
    git commit -am 'Made a change! [trigger:composer]'
    !
    # Push your code to master
    git push fortrabbit master

    View full-size slide

  23. composer:
    method: install
    mode: always
    !
    post-deploy:
    script: artisan
    args:
    - migrate
    fortrabbit.yml

    View full-size slide

  24. Deployment
    Services
    Less management for a small cost.

    View full-size slide

  25. Continuous
    Integration
    Services

    View full-size slide

  26. Task
    Runners
    Remote server automation.

    View full-size slide

  27. No connections have been set, please create one: (production)production
    No host is set for [production/0], please provide one:mynewapp.com
    No username is set for [production/0], please provide one:jonathan
    No password or SSH key is set for [production/0],[key/password]password
    No password is set for [production/0], please provide one:
    production/0 | Ignite (Creates Rocketeer's configuration)
    What is your application's name ? (rocketeer)mynewapp
    The Rocketeer configuration was created at rocketeer/.rocketeer
    # Install with Composer
    composer require --dev anahkiasen/rocketeer
    !
    # Run configuration setup
    php vendor/bin/rocketeer ignite

    View full-size slide

  28. /.rocketeer
    config.php
    hooks.php
    paths.php
    remote.php
    scm.php
    stages.php
    strategies.php

    View full-size slide

  29. // The SCM used (supported: "git", "svn")
    'scm' => 'git',
    !
    // The address to your repository
    'repository' => ‘https://jonathan@bitbucket...',
    !
    // The repository credentials
    'username' => '',
    'password' => '',
    !
    // The branch to deploy
    'branch' => 'master',
    scm.php

    View full-size slide

  30. // The root directory where
    // your applications will be deployed
    'root_directory' => ‘/var/www/mynewapp/',
    remote.php

    View full-size slide

  31. // Tasks to execute after the
    // core Rocketeer Tasks
    'after' => [
    'deploy' => [
    'sudo service php-fpm reload',
    'php artisan migrate --force',
    ],
    ],
    hooks.php

    View full-size slide

  32. # Run the deployment
    php vendor/bin/rocketeer deploy
    No password or SSH key is set for [production/0], [key/password]password
    No password is set for [production/0], please provide one:
    No username is set for [repository], please provide one:jonathan
    No password is set for [repository], please provide one:
    | Deploy (Deploys the website)
    |-- Primer (Run local checks to ensure deploy can proceed)
    |-- CreateRelease (Creates a new release on the server)
    |---- Deploy/Clone (Clones a fresh instance of the repository by SCM)
    |===> Cloning repository in "/srv/users/rocketeer/apps/rocketeer/releases/20150312135546"
    $ git clone "https://reinink:[email protected]/reinink/rocketeer.git" "/srv/users/rocketeer/ap
    [[email protected]] (production) Cloning into '/srv/users/rocketeer/apps/rocketeer/rel
    |===> Initializing submodules if any
    $ cd /srv/users/rocketeer/apps/rocketeer/releases/20150312135546
    $ git submodule update --init --recursive
    |-- Dependencies (Installs or update the dependencies on server)
    |---- Dependencies/Polyglot (Runs all of the above package managers if necessary)
    |------ Dependencies/Composer (Installs dependencies with Composer)
    $ cd /srv/users/rocketeer/apps/rocketeer/releases/20150312135546
    $ /usr/bin/composer5.6-sp install --no-interaction --no-dev --prefer-dist
    [[email protected]] (production) Loading composer repositories with package informatio
    [[email protected]] (production) Installing dependencies from lock file

    View full-size slide

  33. That’s all folks!
    Give continuous deployment a try!

    View full-size slide

  34. Thanks!
    Follow me on Twitter at @reinink.
    Rate this talk https://joind.in/13068.

    View full-size slide