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

Continuous Integration with GitLab

Continuous Integration with GitLab

F9c1a378a1e3926ea1a58cf724140000?s=128

Ivan Nemytchenko

November 23, 2016
Tweet

Transcript

  1. CONTINUOUS INTEGRATION WITH GITLAB IVAN NEMYTCHENKO, DEVELOPER ADVOCATE

  2. MODERN SOFTWARE DEVELOPMENT PROCESS IS SPREAD ACROSS MANY TOOLS

  3. Travis - GitHub - Trello - Slack

  4. Bitbucket - Semaphore - Pivotal Tracker - HipChat

  5. Jenkins - GitLab - Jira

  6. None
  7. None
  8. None
  9. None
  10. None
  11. None
  12. None
  13. None
  14. None
  15. None
  16. None
  17. CATGREP SOPHISTICATED TECHNOLOGIES INC. > file1.txt > file2.txt

  18. REQUIREMENT #1 CONCATENATION RESULT SHOULD CONTAIN "HELLO WORLD"

  19. cat file1.txt file2.txt | grep -q "Hello world"

  20. None
  21. RUN OUR FIRST TEST INSIDE CI

  22. .gitlab-ci.yml

  23. test: script: cat file1.txt file2.txt | grep -q 'Hello world'

  24. None
  25. None
  26. REQUIREMENT #2 PACKAGE CODE BEFORE SENDING IT TO CUSTOMER

  27. test: script: cat file1.txt file2.txt | grep -q 'Hello world'

    package: script: cat file1.txt file2.txt | gzip > package.gz
  28. None
  29. MAKE RESULTS OF YOUR BUILD DOWNLOADABLE

  30. test: script: cat file1.txt file2.txt | grep -q 'Hello world'

    package: script: cat file1.txt file2.txt | gzip > packaged.gz artifacts: paths: - packaged.gz
  31. None
  32. RUN JOBS SEQUENTIALLY

  33. stages: - test - package test: stage: test script: cat

    file1.txt file2.txt | grep -q 'Hello world' package: stage: package script: cat file1.txt file2.txt | gzip > packaged.gz artifacts: paths: - packaged.gz
  34. SPEEDING UP THE BUILD

  35. #1: DUPLICATION

  36. stages: - compile - test - package compile: stage: compile

    script: cat file1.txt file2.txt > compiled.txt artifacts: paths: - compiled.txt test: stage: test script: cat compiled.txt | grep -q 'Hello world' package: stage: package script: cat compiled.txt | gzip > packaged.gz artifacts: paths: - packaged.gz
  37. #2: RUBY 2.1 ????

  38. LEARNING WHAT DOCKER IMAGE TO USE

  39. image: alpine

  40. image: alpine stages: - compile - test - package compile:

    ... test: ...
  41. None
  42. > defined 3 stages > pass files between stages >

    downloadable artifacts > optimized execution time
  43. REQUIREMENT #3 ISO INSTEAD OF GZIP

  44. DEALING WITH COMPLEX SCENARIOS

  45. None
  46. image: alpine stages: - compile - test - package compile:

    ... test: ... pack-gz: stage: package script: cat compiled.txt | gzip > packaged.gz artifacts: paths: - packaged.gz pack-iso: stage: package script: - mkisofs -o ./packaged.iso ./compiled.txt artifacts: paths: - packaged.iso
  47. None
  48. DEALING WITH MISSING SOFTWARE/PACKAGES

  49. INSTALL PACKAGE IN ALPINE LINUX apk add -U cdrkit

  50. script: - apk add -U cdrkit - mkisofs -o ./packaged.iso

    ./compiled.txt
  51. pack-iso: stage: package before_script: - apk add -U cdrkit script:

    - mkisofs -o ./packaged.iso ./compiled.txt artifacts: paths: - packaged.iso
  52. None
  53. None
  54. GITLAB REQUIREMENT #4 PUBLISH A SMALL WEBSITE WITH OUR PACKAGES

  55. HTML + PACKAGES → AMAZON S3

  56. aws s3 cp ./ s3://yourbucket/ --recursive

  57. None
  58. None
  59. FIRST AUTOMATED DEPLOYMENT

  60. > awscli can be installed using pip > pip goes

    together with python
  61. s3: image: python:latest stage: deploy script: - pip install awscli

    - aws s3 cp ./ s3://yourbucket/ --recursive
  62. AWS_ACCESS_KEY_ID and AWS_SECRET_ACCESS_KEY

  63. variables: AWS_ACCESS_KEY_ID: "AKIAIOSFODNN7EXAMPLE" AWS_SECRET_ACCESS_KEY: “wJalrXUtnFEMI/K7MDENG/bPxRfiCYEXAMPLEKEY” s3: image: python:latest stage: deploy

    script: - pip install awscli - aws s3 cp ./ s3://yourbucket/ --recursive
  64. KEEPING SECRET THINGS SECRET

  65. SETTINGS --> VARIABLES

  66. s3: image: python:latest stage: deploy script: - pip install awscli

    - aws s3 cp ./ s3://yourbucket/ --recursive
  67. So far so good:

  68. REQUIREMENT #5 MORE THAN ONE DEVELOPER ON THE PROJECT

  69. s3: image: python:latest stage: deploy script: - pip install awscli

    - aws s3 cp ./ s3://yourbucket/ --recursive only: - master
  70. None
  71. REQUIREMENT #6 WE NEED A SEPARATE PLACE FOR TESTING

  72. GITLAB PAGES

  73. HOST WEBSITES ON GITLAB PAGES > your job should be

    named "pages" > put your files into "public" folder > specify "artifacts" section with this "public" folder
  74. HOST WEBSITES ON GITLAB PAGES > your job should be

    named "pages" > put your files into "public" folder > specify "artifacts" section with this "public" folder HTTP://<USERNAME>.GITLAB.IO/<PROJECTNAME>
  75. pages: stage: deploy image: alpine:latest script: - mkdir -p ./public

    && cp ./*.* ./public/ artifacts: paths: - public except: - master
  76. s3: image: python:latest stage: deploy script: - pip install awscli

    - aws s3 cp ./ s3://yourbucket/ --recursive only: - master pages: image: alpine:latest stage: deploy script: - mkdir -p ./public && cp ./*.* ./public/ artifacts: paths: - public except: - master
  77. None
  78. None
  79. None
  80. INTRODUCING ENVIRONMENTS

  81. s3: environment: production image: python:latest stage: deploy script: - pip

    install awscli - aws s3 cp ./ s3://$S3_BUCKET_NAME/ --recursive only: - master pages: image: alpine:latest environment: staging stage: deploy script: - mkdir -p ./public && cp ./*.* ./public/ artifacts: paths: - public except: - master
  82. None
  83. None
  84. None
  85. REQUIREMENT #7 DO NOT MESS UP PRODUCTION

  86. SWITCHING TO MANUAL DEPLOYMENT

  87. s3: image: python:latest stage: deploy script: - pip install awscli

    - aws s3 cp ./ s3://yourbucket/ --recursive only: - master when: manual
  88. SUMMARY 1. Deployment is just a set of commands 2.

    You need to provide secret keys 3. You specify where which branches should go to 4. GitLab conserves the history of deployments 5. You can enable manual deployment
  89. None
  90. None
  91. None
  92. GO TO GITLAB.COM

  93. @INEM INEM@BK.RU BIT.LY/GITLAB-CI1 BIT.LY/GITLAB-CI2