Successfully reported this slideshow.
We use your LinkedIn profile and activity data to personalize ads and to show you more relevant ads. You can change your ad preferences anytime.

Into The Box 2018 Going live with commandbox and docker

106 views

Published on

Mark Drew

Published in: Technology
  • Be the first to comment

  • Be the first to like this

Into The Box 2018 Going live with commandbox and docker

  1. 1. GOING LIVE WITH COMMANDBOX AND DOCKER! Fun times* in deploying real projects * Your mileage might vary
  2. 2. CMDdevelop • deploy • deliver @markdrew mark@cmdhq.io http://cmdhq.io
  3. 3. WHAT WE ARE COVERING ➤ Background ➤ Workflow ➤ Server Monitoring ➤ Configuration ➤ Caching & Session Storage ➤ Logging ➤ Configuration ➤ Load Balancing and Orchestration ➤ The Hard Stuff
  4. 4. BACKGROUND
  5. 5. BACKGROUND ➤ Owned actual hardware at ISP ➤ Disaster Recovery (DR) ➤ WIDE range of platforms ➤ Range of usage patterns ➤ Lots of assets and data ➤ Issues with getting code to production ➤ 💩 code constipation ➤ 💥 Actual Disaster - ISP needs to move.
  6. 6. Web app Image Conv Meta indexing Image Conv Log
  7. 7. WORKFLOW
  8. 8. TIMETABLE Week1 Mon Tue Wed Thurs Fri Dev Dev Dev Dev Dev Dev QA Infra Week2 Mon Tue Wed Thurs Fri Dev Dev Dev Dev Estimate Train/Est QA Test Test Test Infra Week3 Mon Tue Wed Thurs Fri Dev Dev Dev Dev Dev … QA Test Test Infra Prep Deploy
  9. 9. WORKFLOW - GITFLOW (MODIFIED)! Time master develop feature X feature Y 1 release 2 4 hot-fix 3
  10. 10. ENVIRONMENTS Development Unit Test QA Live
  11. 11. ENVIRONMENTS Development Unit Test QA Live
  12. 12. ENVIRONMENTS Development Development Unit Test Unit Test QA QA Live Live *tomorrow
  13. 13. WHY DOCKER? ➤ Why move from Vagrant to Docker? ➤ How does it help the developer? ➤ How does it help infrastructure team?
  14. 14. WHY COMMANDBOX? ➤ Shiny new toy? ➤ Configuration ➤ Smaller software surface ➤ Ability to script stuff EASIER
  15. 15. CLEAN UP THE CODE ➤ CFLint ➤ Git Hooks ➤ Unit tests * *tomorrow
  16. 16. CLEAN UP THE CODE ➤ A static code analysis tool for CFML ➤ Checks code against a list of rules (which can be customised per project) ➤ Check for variable name lengths etc. ➤ https://github.com/cflint/ CFLint
  17. 17. > java -jar CFLint-1.2.3-all.jar -folder .
  18. 18. @markdrew FOLDER BASED CONFIGURATION { "output" : [ ], "rule" : [ ], "excludes" : [ ], "includes" : [ { "code" : "FUNCTION_HINT_MISSING" } ], "inheritParent" : false, "inheritPlugins" : true, "parameters" : {} } .cflintrc
  19. 19. GIT HOOKS ➤ Run Commandbox (or any!) commands when performing git actions. ➤ Awesome!
  20. 20. @markdrew > box install commandbox-githooks > cd MyProject > git init > box githooks install Title Text
  21. 21. @markdrew ADD IN THE HOOKS { "name":"MyProject", "githooks":{ "preCommit":"!java -jar CFLint-1.2.3-all.jar -folder .” } } box.json
  22. 22. SERVE WITH COMMANDBOX! ➤ server.json ➤ needs SSL ➤ Webroot isn’t the root. ➤ Needed specific Railo version to start using it (thanks Brad!)
  23. 23. { “name":"ClientApp", "app":{ "cfengine":"Railo" }, "web":{ “webroot":"wwwroot/", "SSL":{ "enable":true, "port":1443 }, "http":{ "enable":true, "port":8080 } } } server.json
  24. 24. @markdrew AND CREATE DOCKER #!/usr/bin/env bash echo "Building the APP Docker image" container_name="development-${RANDOM}" image_name="dev" docker build -t ${image_name} . echo "Starting..." docker run -it --name ${container_name} -p 8080:8080 -p 8443:1443 -v "${PWD}:/app" -v "${PWD}/../password-lgk:/usr/share/tomcat7/certs" ${image_name} buildDocker.sh
  25. 25. @markdrew AND CREATE DOCKER FROM ortussolutions/commandbox COPY . /app buildDocker.sh
  26. 26. NOW WITH GITLAB
  27. 27. NOW WITH GITLAB
  28. 28. SERVER MONITORING
  29. 29. MONITORING ➤ It’s 3am, do you know which server crashed? ➤ Where are the logs? Is it VM1(x)? Which instance?
  30. 30. SERVER MONITORING VM1 VM2 VM3 VM4 VM5 VM1
  31. 31. FUSION REACTOR CLOUD
  32. 32. PROMETHEUS
  33. 33. OTHER MONITORS
  34. 34. CONFIGURATION
  35. 35. CONFIGURATION ➤ From Database ➤ Dynamic Datasources ➤ On Request ➤ Per request settings ➤ CFConfig ➤ JVM Settings ➤ Extensions
  36. 36. @markdrew DYNAMIC DATASOURCES component { app = new core.objects.app(); hostName = ListFirst(cgi.http_host , ":"); appConfig = app.getConfig( hostName = hostName ); this.defaultDatasource = appConfig.code; this.datasources[ this.defaultDatasource ] = { class : 'com.microsoft.jdbc.sqlserver.SQLServerDriver', connectionString: 'jdbc:sqlserver://' & appConfig.dbServer & ': 1433;DATABASENAME=' & appConfig.dbName & ';sendStringParametersAsUnicode=true;SelectMethod=direct', username : appConfig.dbUser, password : appConfig.dbPassword, }; } Title Text
  37. 37. @markdrew CFCONFIG > box install commandbox-cfconfig > cfconfig show Title Text
  38. 38. { "applicationListener":"mixed", "applicationMode":"curr2root", "applicationTimeout":"1,0,0,0", "clientCookies":"yes", "clientManagement":"no", "clientTimeout":"90,0,0,0", "loggers":{ "application":{ "appender":"resource", "appenderArguments":{ "path":"{lucee-config}/logs/application.log" }, "layout":"classic" }, "datasource":{ "appender":"resource", "appenderArguments":{
  39. 39. @markdrew CFCONFIG > cfconfig export .CFConfig.json Title Text
  40. 40. @markdrew CFCONFIG SETTINGS { "app":{ "cfengine":"Lucee@5" } "cfconfigfile":".CFConfig.json" } server.json
  41. 41. @markdrew JVM SETTINGS { "app":{ "cfengine":"Lucee@5" }, "jvm":{ "heapSize":1024, "minHeapSize":256 }, "cfconfigfile":".CFConfig.json" } server.json
  42. 42. ENVIRONMENT RESOURCE HOSTS Dev Test QA Live DB dev.domain test.domain qa.domain live.domain Mail mail.dev.domain mail.test.domain mail.qa.domain mail.live.domain Logs logs.dev.domain logs.test.domain logs.qa.domain logs.live.domain Etc etc.dev.domain etc.test.domain etc.qa.domain live.qa.domain
  43. 43. ENVIRONMENT RESOURCE HOSTS Dev Test QA Live DB db db db db Mail mail mail mail mail Logs logs logs logs logs Etc etc etc etc etc
  44. 44. @markdrew /ETC/HOSTS 192.168.2.1 db 192.168.2.1 mail 192.168.2.1 logs 192.168.2.1 etc Hosts
  45. 45. @markdrew ADD HOSTS #!/usr/bin/env bash echo "Building the APP Docker image" container_name="development-${RANDOM}" image_name="dev" docker build -t ${image_name} . echo "Starting..." docker run -it --name ${container_name} -p 8080:8080 -p 8443:1443 -v "${PWD}:/app" --add-host="db:192.168.65.1" --add-host="mail:192.168.65.2" -—add-host=“logs:192.168.65.3" -—add-host=“etc:192.168.65.4” ${image_name} buildDocker.sh
  46. 46. CACHING & SESSION STORAGE
  47. 47. CACHING & SESSIONS ➤ Cache of data ➤ Cache of resources/artefacts ➤ Cache of function results ➤ Session storage
  48. 48. CACHE OF DATA
  49. 49. CACHE OF DATA http://127.0.0.1:51921/lucee/admin/web.cfm?action=services.cache
  50. 50. @markdrew function getConfig() cachedwithin="#CreateTimeSpan(0, 0, 10, 0)#"{ return now(); } Title Text
  51. 51. @markdrew ARTEFACT CACHING docker run —name ourapp -p 8080:8080 -p 8443:8443 -v .CommandBox/artifacts:/root/.CommandBox/artifacts theapp runApp.sh
  52. 52. SESSION STORAGE VM1
  53. 53. @markdrew SETTING UP SESSION STORAGE component { this.sessionCluster = true; this.sessionStorage = "SessionStore"; this.sessionManagement = true; } Application.cfc
  54. 54. LOGGING
  55. 55. LOGGING ISSUES ➤ Logs get lost ➤ Not all things are logged. ➤ Need to setup in Lucee admin ➤ Trap it using ➤ JournalD ➤ ELK = Elasticsearch + Kibana + Logstash (beats)
  56. 56. KIBANA - DASHBOARDS
  57. 57. KIBANA - TIME SERIES
  58. 58. @markdrew <logger appender="resource" appender-arguments="path:{lucee-config}/logs/application.log" layout="classic" name="application"/> <logger appender="console" appender-arguments="streamtype:error" layout="classic" layout-arguments="" level="ERROR" name="exception"/> Title Text
  59. 59. LOAD BALANCING AND ORCHESTRATION
  60. 60. LOAD BALANCING AND ORCHESTRATION ➤ Round Robin load balancing ➤ Kubernetes ➤ Could be using: ➤ Portioner ➤ Docker Compose and Swarm ➤ Elastic Container Service AWS
  61. 61. THE HARD STUFF
  62. 62. DATA CHANGES / WORKFLOW ➤ Some solutions:
 ➤ CFMigrations - Eric Peterson
 ➤ Versioning of database
 ➤ QueryBuilder (Fluent Query Builder for CFML)  - Eric Peterson
 ➤ Currently using hand crafted SQL files (can be run multiple times)
 ➤ First time alters the columns
 ➤ Second time updates data

  63. 63. SCHEDULED TASKS
  64. 64. CANARY DEPLOYMENTS VM1 VM2 VM3 VM4 VM5 VM1
  65. 65. GREEN/BLUE DEPLOYMENTS VM1 VM2 VM3 VM4 VM5
  66. 66. IN SUMMARY ➤ Provide the team with the structure to succeed ➤ Provide the team with the tools to succeed ➤ Configure all the things! Commandbox & CfConfig are your friends ➤ Simplify environment transitions ➤ Monitor all the things! ➤ Log all the things! ➤ Cache all the things! ➤ It’s a process in process
  67. 67. CMDdevelop • deploy • deliver @markdrew mark@cmdhq.io http://cmdhq.io

×