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

A smooth migration to Docker focusing on build pipelines

PaulRbr
October 06, 2017

A smooth migration to Docker focusing on build pipelines

PaulRbr

October 06, 2017
Tweet

More Decks by PaulRbr

Other Decks in Programming

Transcript

  1. Paul Bonaud ⌨ + ⚙ + ▶ Infra & Ops

    Engineer ⏸ So ware Developer Maxime Visonneau ⌨ + + Infrastructure Engineer
  2. Dockerfile FROM ruby:2.4-jessie RUN apt-get update RUN apt-get -y install

    libpq-dev ghostscript WORKDIR /opt/app COPY Gemfile Gemfile.lock /opt/app RUN bundle install VOLUME /opt/app CMD [ "make", "run" ]
  3. Dockerfile FROM ruby:2.4-jessie RUN apt-get update RUN apt-get -y install

    libpq-dev ghostscript WORKDIR /opt/app COPY Gemfile Gemfile.lock /opt/app RUN bundle install VOLUME /opt/app CMD [ "make", "run" ]
  4. Dockerfile FROM ruby:2.4-jessie RUN apt-get update && \ apt-get -y

    install libpq-dev ghostscript && \ rm -rf /var/lib/apt/lists/* WORKDIR /opt/app COPY Gemfile Gemfile.lock /opt/app RUN bundle install VOLUME /opt/app CMD [ "make", "run" ]
  5. Dockerfile FROM ruby:2.4-jessie RUN apt-get update && \ apt-get -y

    install libpq-dev ghostscript && \ rm -rf /var/lib/apt/lists/* WORKDIR /opt/app COPY Gemfile Gemfile.lock /opt/app RUN bundle install VOLUME /opt/app CMD [ "make", "run" ]
  6. Dockerfile FROM ruby:2.4-jessie RUN apt-get update && \ apt-get -y

    install libpq-dev ghostscript && \ rm -rf /var/lib/apt/lists/* WORKDIR /opt/app COPY Gemfile Gemfile.lock /opt/app RUN bundle install VOLUME /opt/app CMD [ "make", "run" ]
  7. Dockerfile FROM ruby:2.4-jessie RUN apt-get update && \ apt-get -y

    install libpq-dev ghostscript && \ rm -rf /var/lib/apt/lists/* WORKDIR /opt/app COPY Gemfile Gemfile.lock /opt/app RUN bundle install VOLUME /opt/app CMD [ "make", "run" ]
  8. .gitlab-ci.yml variables: IMAGE: ${CI_REGISTRY_IMAGE}:${CI_COMMIT_SHA} LATEST_IMAGE: ${CI_REGISTRY}/${CI_PROJECT_PATH}:latest build:docker: stage: build tags:

    [ privileged ] image: "docker:latest" before_script: - docker login -u gitlab-ci-token -p ${CI_JOB_TOKEN} ${CI_REGISTRY} script: - docker pull ${LATEST_IMAGE} || true - docker build --cache-from ${LATEST_IMAGE} -t ${IMAGE} -t ${LATEST_IMAGE} . - docker push ${IMAGE} - docker push ${LATEST_IMAGE}
  9. .gitlab-ci.yml variables: IMAGE: ${CI_REGISTRY_IMAGE}:${CI_COMMIT_SHA} LATEST_IMAGE: ${CI_REGISTRY}/${CI_PROJECT_PATH}:latest build:docker: stage: build tags:

    [ privileged ] image: "docker:latest" before_script: - docker login -u gitlab-ci-token -p ${CI_JOB_TOKEN} ${CI_REGISTRY} script: - docker pull ${LATEST_IMAGE} || true - docker build --cache-from ${LATEST_IMAGE} -t ${IMAGE} -t ${LATEST_IMAGE} . - docker push ${IMAGE} - docker push ${LATEST_IMAGE}
  10. .gitlab-ci.yml variables: IMAGE: ${CI_REGISTRY_IMAGE}:${CI_COMMIT_SHA} LATEST_IMAGE: ${CI_REGISTRY}/${CI_PROJECT_PATH}:latest build:docker: stage: build tags:

    [ privileged ] image: "docker:latest" before_script: - docker login -u gitlab-ci-token -p ${CI_JOB_TOKEN} ${CI_REGISTRY} script: - docker pull ${LATEST_IMAGE} || true - docker build --cache-from ${LATEST_IMAGE} -t ${IMAGE} -t ${LATEST_IMAGE} . - docker push ${IMAGE} - docker push ${LATEST_IMAGE}
  11. .gitlab-ci.yml variables: IMAGE: ${CI_REGISTRY_IMAGE}:${CI_COMMIT_SHA} LATEST_IMAGE: ${CI_REGISTRY}/${CI_PROJECT_PATH}:latest build:docker: stage: build tags:

    [ privileged ] image: "docker:latest" before_script: - docker login -u gitlab-ci-token -p ${CI_JOB_TOKEN} ${CI_REGISTRY} script: - docker pull ${LATEST_IMAGE} || true - docker build --cache-from ${LATEST_IMAGE} -t ${IMAGE} -t ${LATEST_IMAGE} . - docker push ${IMAGE} - docker push ${LATEST_IMAGE}
  12. .gitlab-ci.yml variables: IMAGE: ${CI_REGISTRY_IMAGE}:${CI_COMMIT_SHA} # (...) image: ${IMAGE} test: stage:

    test script: - make test package: stage: package script: - make package > release.tar.gz artifacts: paths: [ release.tar.gz ]
  13. .gitlab-ci.yml variables: IMAGE: ${CI_REGISTRY_IMAGE}:${CI_COMMIT_SHA} # (...) deploy:integration: stage: deploy image:

    ${CI_REGISTRY}/infra/ansible:latest variables: ENV: integration script: - make deploy file=release.tar.gz env=${ENV}
  14. .gitlab-ci.yml variables: IMAGE: ${CI_REGISTRY_IMAGE}:${CI_COMMIT_SHA} # (...) deploy:integration: &deploy stage: deploy

    image: ${CI_REGISTRY}/infra/ansible:latest variables: ENV: integration script: - make deploy file=release.tar.gz env=${ENV} deploy:production: <<: *deploy when: manual variables: ENV: production
  15. Dockerfile FROM ruby:2.4-jessie RUN apt-get update RUN apt-get -y install

    libpq-dev ghostscript WORKDIR /opt/app COPY Gemfile Gemfile.lock /opt/app RUN bundle install VOLUME /opt/app CMD [ "make", "run" ]
  16. Dockerfile FROM ruby:2.4-stretch RUN apt-get update RUN apt-get -y install

    libpq-dev ghostscript WORKDIR /opt/app COPY Gemfile Gemfile.lock /opt/app RUN bundle install VOLUME /opt/app CMD [ "make", "run" ]
  17. .gitlab-ci.yml variables: IMAGE: ${CI_REGISTRY_IMAGE}:${OS}_${CI_COMMIT_SHA} # (...) image: ${IMAGE} test:jessie: &test

    stage: test variables: OS: jessie script: - make test test:stretch: <<: *test variables: OS: stretch
  18. .gitlab-ci.yml variables: IMAGE: ${CI_REGISTRY_IMAGE}:${OS}_${CI_COMMIT_SHA} # (...) image: ${IMAGE} package:jessie: &package

    stage: package variables: OS: jessie script: - make package > release-${OS}.tar.gz artifacts: paths: [ release-${OS}.tar.gz ] package:stretch: <<: *package variables: OS: stretch
  19. .gitlab-ci.yml variables: IMAGE: ${CI_REGISTRY_IMAGE}:${OS}_${CI_COMMIT_SHA} # (...) deploy:integration: &deploy stage: deploy

    image: ${CI_REGISTRY}/infra/ansible:latest variables: OS: stretch ENV: integration script: - make deploy file=release-${OS}.tar.gz env=${ENV} deploy:production: <<: *deploy when: manual variables: OS: jessie ENV: production
  20. Di erent Executors / Multiple OSes Shell Docker VirtualBox Parallels

    SSH Kubernetes Linux Windows Mac OS X FreeBSD
  21. Di erent Executors / Multiple OSes Shell Docker VirtualBox Parallels

    SSH Kubernetes Linux Windows Mac OS X FreeBSD
  22. --- classes: - docker - gitlab::ci gitlab::ci::runners: "%{::fqdn}_docker": executor: docker

    docker-image: docker:latest docker-volumes: "/var/run/docker.sock:/var/run/docker.sock" docker-privileged: true
  23. AWS

  24. terraform.tf resource "aws_instance" "gitlab_runner" { count = 10 ami =

    "ami-6b2cd712" instance_type = "m4.large" [..] }
  25. AWS

  26. terraform.tf resource "aws_autoscaling_group" "gitlab_runner" { desired_capacity = 10 min_size =

    4 max_size = 24 launch_configuration = "${aws_launch_configuration.runner.name}" [..] }
  27. gitlab::ci::runners: 'aws_spot_docker_machine': executor: docker+machine limit: 24 machine-IdleCount: 4 machine-IdleTime: 600

    machine-OffPeakPeriods: - "* * 0-8,18-23 * * mon-fri *" - "* * * * * sat,sun *" machine-OffPeakIdleCount: 0 machine-OffPeakIdleTime: 600 machine-MaxBuilds: 30 machine-MachineDriver: amazonec2 machine-MachineOptions: - amazonec2-instance-type=m4.large - amazonec2-request-spot-instance=true - amazonec2-spot-price=0.10 [..]
  28. gitlab::ci::runners: 'aws_spot_docker_machine': executor: docker+machine limit: 24 machine-IdleCount: 4 machine-IdleTime: 600

    machine-OffPeakPeriods: - "* * 0-8,18-23 * * mon-fri *" - "* * * * * sat,sun *" machine-OffPeakIdleCount: 0 machine-OffPeakIdleTime: 600 machine-MaxBuilds: 30 machine-MachineDriver: amazonec2 machine-MachineOptions: - amazonec2-instance-type=m4.large - amazonec2-request-spot-instance=true - amazonec2-spot-price=0.10 [..]
  29. gitlab::ci::runners: 'aws_spot_docker_machine': executor: docker+machine limit: 24 machine-IdleCount: 4 machine-IdleTime: 600

    machine-OffPeakPeriods: - "* * 0-8,18-23 * * mon-fri *" - "* * * * * sat,sun *" machine-OffPeakIdleCount: 0 machine-OffPeakIdleTime: 600 machine-MaxBuilds: 30 machine-MachineDriver: amazonec2 machine-MachineOptions: - amazonec2-instance-type=m4.large - amazonec2-request-spot-instance=true - amazonec2-spot-price=0.10 [..]
  30. gitlab::ci::runners: 'aws_spot_docker_machine': executor: docker+machine limit: 24 machine-IdleCount: 4 machine-IdleTime: 600

    machine-OffPeakPeriods: - "* * 0-8,18-23 * * mon-fri *" - "* * * * * sat,sun *" machine-OffPeakIdleCount: 0 machine-OffPeakIdleTime: 600 machine-MaxBuilds: 30 machine-MachineDriver: amazonec2 machine-MachineOptions: - amazonec2-instance-type=m4.large - amazonec2-request-spot-instance=true - amazonec2-spot-price=0.10 [..]
  31. gitlab::ci::runners: 'aws_spot_docker_machine': executor: docker+machine limit: 24 machine-IdleCount: 4 machine-IdleTime: 600

    machine-OffPeakPeriods: - "* * 0-8,18-23 * * mon-fri *" - "* * * * * sat,sun *" machine-OffPeakIdleCount: 0 machine-OffPeakIdleTime: 600 machine-MaxBuilds: 30 machine-MachineDriver: amazonec2 machine-MachineOptions: - amazonec2-instance-type=m4.large - amazonec2-request-spot-instance=true - amazonec2-spot-price=0.10 [..]
  32. gitlab::ci::runners: 'aws_spot_docker_machine': executor: docker+machine limit: 24 machine-IdleCount: 4 machine-IdleTime: 600

    machine-OffPeakPeriods: - "* * 0-8,18-23 * * mon-fri *" - "* * * * * sat,sun *" machine-OffPeakIdleCount: 0 machine-OffPeakIdleTime: 600 machine-MaxBuilds: 30 machine-MachineDriver: amazonec2 machine-MachineOptions: - amazonec2-instance-type=m4.large - amazonec2-request-spot-instance=true - amazonec2-spot-price=0.10 [..]
  33. gitlab::ci::runners: 'aws_spot_docker_machine': executor: docker+machine limit: 24 machine-IdleCount: 4 machine-IdleTime: 600

    machine-OffPeakPeriods: - "* * 0-8,18-23 * * mon-fri *" - "* * * * * sat,sun *" machine-OffPeakIdleCount: 0 machine-OffPeakIdleTime: 600 machine-MaxBuilds: 30 machine-MachineDriver: amazonec2 machine-MachineOptions: - amazonec2-instance-type=m4.large - amazonec2-request-spot-instance=true - amazonec2-spot-price=0.10 [..]
  34. --- apiVersion: v1 kind: ConfigMap metadata: name: gitlab-runner namespace: gitlab-ci

    data: config.toml: | [[runners]] name = "k8s_runner" url = "https://gitlab.example.com/" executor = "kubernetes" [runners.kubernetes] cpu_limit = "1" memory_limit = "256Mi" [..]
  35. ~$ kubectl -n gitlab-ci get po NAME READY STATUS RESTARTS

    AGE runner-315e4d80-0qj79g 2/2 Running 0 3m runner-315e4d80-9kdkee 2/2 Running 0 2m runner-315e4d80-kdfdfe 2/2 Running 0 1m runner-315e4d80-ldorpk 2/2 Running 0 1m runner-315e4d80-pleofi 2/2 Running 0 20s