Github + TravisCI + Pantheon – Usando flujos de trabajo exitosos – Qué vamos a hacer?



Github + TravisCI + Pantheon – Usando flujos de trabajo exitosos – Qué vamos a hacer?

0 0


github-pantheon-travisci

Contains slides for github+pantheon+travisci integration session.

On Github kporras07 / github-pantheon-travisci

Github + TravisCI + Pantheon

Usando flujos de trabajo exitosos

Kporras07 / @kporras07

Kevin Jesús Porras Zumbado

  • Drupal Backend Developer - Manatí

Qué vamos a hacer?

Github

  • Repositorio Principal
  • Gestión de Issues
  • Pull Requests

TravisCI

  • Integración continua
  • Build del sitio en cada push a una rama
  • Build del sitio en cada Pull Request (integrar con Pantheon multidev)
  • Si es push a master, hacer push a pantheon
  • Notificar de los builds a un canal de Slack

Pantheon

  • Workflow dev-test-live
  • Multidev

Qué necesitamos?

Github

  • Tu Cuenta de Github

TravisCI

  • Cuenta de Travis CI (linkeada a tu cuenta de Github)
  • Cliente de Travis CI (Instrucciones)

Pantheon

  • Tu Cuenta de Pantheon
  • Una cuenta de Pantheon adicional con acceso al sitio (no olvidar e-mail/password)
  • Par de llaves pública/privada para la cuenta adicional de Pantheon. Subir la pública.
  • Un sitio de Pantheon

Preparando el Repositorio

  • Clonar repo de Pantheon
  • Agregar archivo .travis.yml
  • Commit de este archivo
  • Crear repo vacío de Github
  • Agregar el remote de github
  • Push a Pantheon y a Github
  • Habilitar Travis CI para el repo de Github (https://travis-ci.org/profile/{username})

Encriptar variables con Travis CLI

travis encrypt SOMEVAR=secretvalue

.travis.yml

Project Setup


# Define project language. See http://docs.travis-ci.com/user/languages/
language: php

# Runtime version.
php:
  - 5.4

# Deployment key (ssh private key encoded in base64). Security Warning here!
source_key: "LS0tLS1CRUdJTiBSU0EgUFJJVkFURSBLRVktLS0tLQ0KTUlJSkpBSUJBQUtDQWdBTVpzb2hHN1FzbjVDRWJydkFjVVpRYVZWbkNwUUxuYmY3dndOeUsxejhvOEE4Z2VGZA0KcG9MWGhMUm5RMkxBSk91NVp0TmMycTlWY3pWTTNWUWtoUzNZ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PT0NCi0tLS0tRU5EIFJTQSBQUklWQVRFIEtFWS0tLS0t"

# Define environment variables
env:
  global:
    - PNAME='ci-demo'
    - PSITE=$(cat /dev/urandom | tr -cd 'a-z0-9' | head -c 4)
    - PSITE="ci$TRAVIS_BUILD_NUMBER-$PSITE"
    - PUUID='445bb8f4-2088-4b79-9f2a-f436a18e683c'
    - PSOURCE='dev'
# Travis encoded pantheon email
    - secure: "RyO2KV7404nXZCoEPgld9Mr1TBLPOBC0itjyqrF0EcoU1hC8641A0s/OU+emVGvBskdA+b5HZUprF561C060AgOVftiYxzMYTOTT/YDbdTCuIpRKx3arKMRUc9T+1NKEvMFAyAx56l7jX5bobFp3W1KMHhLny/8UJ+osJ5CBRoy0DTYSS85whBMhJb0AHIXTf2umVbpZ8qxn4CfALxV6eohGKilGc19JDVqdvP6qFHsHErNYeRnE2Jp8Oo/viVUWWxePMRf/n/RlyUjwr7Od17dSwDI7cAValRAQ43zFYPsFiNMUBlWKubKqM9laG6n2vZ1ZhmRb4DV8iRXfinzpQRDsDJ7sRGiZ4jnRNBVTpdpGfVPGX23M7b1hR/c67R3oLr+CFsJmMnR3rOWK4a/tb7dcTMzE++f8Myf0SyZrhlddHTjqQKqNLZa5jVQsO+j6dWRWtmpDgXX1/85ScwiETf6/iyaoYB61ghGm7I7uloxC8JBE2GtUN/QxUzY4uaBd1xRRocGty/m6VE98FqW0QrWBgBdj2kuaV/uyzV37UxdaIJj5sG1vMCHpt+iGSdRQGSjetkkgr8jeS8xvV+dyqqlHmbxikFTJVIdBugErj39WqZLhkwUIp48xwABz2QHO5HmJ1TMmc5bQFSt9Uxj/GN4iG5CtYBKWztGRZdi5ZLQ="
# Travis encoded pantheon password
    - secure: "nphbuP7Cjz3VIdtNwAoeasy4Aw5pGyXYPt0dnXigjFYTeub9a8Ok7cA+uFmN/Ep1yibefvJ48uTXyf84WzSl11gGlGHho4R1QV1zYqu6vpoRsMu67VhALBe03DWdBWDKC+2thSdYXcVH4YqmMAqchOHCCvBtssXzUecTm4ghdjPezbg2sXaTyxSZduT5bGkq70e75mmVVF50UUsrZj5LboXCOTkDaxyVVTycJnMFbCJNBmIzmnLR1lti+C7eGbaxPsZhAYgLGWHeyT9UGs3AhLTu1QiYV6hevHx5/m0pIrZEuJPXClW9EHpGI7aaoVdExyD6Qv0pLqATCbV+BIF7PlycEt3CuecnnCCkwE6IRtFGBeIPdxa/o4QRWiPVsQ9cRPSXW8McBbVCBtcIWtMeJyjprRJWaxokYEyzO5/LqB2pINyWX42SWoHPOa2dEWy2iNImaMmOu8u1/aX6u254Z3p0OycsPWMEGuiZruqAzsBTGXlP/JnanNZwOMZ4iJp6lHdv7q6fzfdgIvkq/NvmYn/ETI37zUhm/a6kiM/Pmo5sIjc5CFFHZIwjXl5K4Zbl3hua5DgKpYuryUcsHMrBvouAl31CHgWozfOuFlrcRQBYQ2A+JvhChLck7qDWLCU9k0IfjDU/CW2Y71FeZXrCbFekYf+C1ijp8gnJ5g0uG2g="
    - PHOST='https://$PSITE-$PNAME.pantheon.io'
                        

.travis.yml

Before Install


before_install:
  - sudo apt-get update > /dev/null

  - composer self-update
                        

.travis.yml

Install

install:
  # Avoid hanging due to ssh requiring host key check.
  - echo "StrictHostKeyChecking no" > ~/.ssh/config
  # install php packages required for running a web server from drush on php 5.3
  - sudo apt-get install -y --force-yes php5-cgi php5-mysql

  # install drush globally
  - composer global require drush/drush:7.*

  # add composer's global bin directory to the path
  # see: https://github.com/drush-ops/drush#install---composer
  - export PATH="$HOME/.composer/vendor/bin:$PATH"
  # Install terminus.
  - sudo curl https://github.com/pantheon-systems/cli/releases/download/0.5.5/terminus.phar -L -o /usr/local/bin/terminus && sudo chmod +x /usr/local/bin/terminus
  - echo "sendmail_path='true'" >> `php --ini | grep "Loaded Configuration" | awk '{print $4}'`
                        

.travis.yml

Before Script

  # stand up drupal
  - cd $TRAVIS_BUILD_DIR
  - composer install
  - npm install && npm update
  - cd sites/all/themes/manati
  # run npm install on theme. TODO: Integrate with site npm config.
  - npm install && npm update
  - drush site-install manati -y --db-url=mysql://root@localhost/cidemo --db-su='root' --db-su-pw='' --site-name='CI-Demo'
  - drush updb -y && drush fra -y
  - drush cc all
  # Run behat tests
  - cd $TRAVIS_BUILD_DIR
  - drush runserver --server=builtin 8082 --strict=0 &
  - sleep 10
                        

.travis.yml

Script


script:
  - cd $TRAVIS_BUILD_DIR
  - grunt
                        

.travis.yml

After Script

after_script:
  - drush status
                        

.travis.yml

After Success

after_success:
  # Authenticate with Pantheon via Terminus.
  - terminus auth login $PEMAIL --password=$PPASS
  # On PR create an Pantheon env.
  - if [ $TRAVIS_BRANCH = 'master' ] && [ $TRAVIS_PULL_REQUEST != 'false' ] ; then git remote add pantheon ssh://codeserver.dev.$PUUID@codeserver.dev.$PUUID.drush.in:2222/~/repository.git && git checkout -b $PSITE && git push --force pantheon $PSITE && terminus site create-env --site=$PNAME --env=$PSITE --from-env=$PSOURCE && terminus sites aliases && drush cc drush && cd $HOME && drush @pantheon.$PNAME.$PSITE updb -y --strict=0 && drush @pantheon.$PNAME.$PSITE fra -y --strict=0 && terminus site clear-caches --site=$PNAME --env=$PSITE ; fi
  # On commits to github master; push them to pantheon master.
  - if [ $TRAVIS_BRANCH = 'master' ] && [ $TRAVIS_PULL_REQUEST = 'false' ] ; then git remote add pantheon ssh://codeserver.dev.$PUUID@codeserver.dev.$PUUID.drush.in:2222/~/repository.git && git push pantheon $TRAVIS_BRANCH && terminus sites aliases && drush cc drush && cd $HOME && drush @pantheon.$PNAME.$TRAVIS_BRANCH updb -y --strict=0 && drush @pantheon.$PNAME.$TRAVIS_BRANCH fra -y --strict=0 ; fi
                        

.travis.yml

Notifications

notifications:
#  email: false
  slack:
    rooms:
      - secure: "krMbpPDhjEkP7G8VPb2CHuxpDbu3gnP8GjJpZl6FWz74vAi1M+oZ3RNKVUANQ/9A/pX1BmnhcKnCPBOzrBuDdPO8xDuVQ9rTmSYu8ZYXDy2UHHD/r0awaORc8TyZ3JeSFmGYCKTZBbTOl2sijuVQe3s1MO+XvPKJHZE40KHEEK1ytjJ8b5bWXlvzGYhsuqW6nRKir/19lyb5yEPnWMaEAxwjacLyeZn2LxNUFYdzcAMJuVoiU/9zNUuHLrBk2P/+/cXNH3yhR6VESB2deSF3k/mlPN4rlMK/IMazx+XF13SB0qsx/30CMlcZSsVk1n2myxisCWsV0ITBjiWQDJcPsgdR0EgFhkXsBKWXuHO8dhRoT1UsmHVXLrL9D0ite3PF50fCOtDVYiHMuWm9tFGKo2xzKqcuhcHjkCY68Co9fmTP4uEgMIf2uGrmJhVWrsmcDCVwWtMbwLu5n5TcX2U1a4rhYUnAvmAwiHoX+pmb00b3XbaM6Kl45/Uz40PhZRZ19+MhvGkx4FdMcR33h+TcaqnXY6YYuPSHAn4Cx9c72xn5rTsJ1EWWcKJBtv2kIxTfss0k7tB+UQHXvSJyQfmIyWrTsZ10PG97td2p1+IS1VzZmeIbqyCqDiUjBLSXmILE4ps9WNmCMXv/UWCGBFG+5oZTedIOh/AmEybA041l1AY="


                        

Referencias

Muchas Gracias

kevin@estudiomanati.com

https://twitter.com/kporras07

https://github.com/kporras07

Slides disponibles en: http://kporras07.tk/github-pantheon-travisci/

Github + TravisCI + Pantheon Usando flujos de trabajo exitosos Kporras07 / @kporras07