Could i spin up one environment for multiple jobs, Environment Inheritance for jobs


#1

my point is i have multiple jobs: build(install docker, docker-compose. and build the app generally), test(test the app), deploy(deploy it)
the problem is when i installed the docker, compose … in build job, why do i need to install them again on test job, otherwise i got command not found is it possible to spin up one environment for all jobs as jobs are phases of ci/cd then need to be supported having one environment and not every time run the same commands in every job


#2

How long, in seconds, do each of these phases take?

  • install docker
  • install docker-compose
  • build the app generally

#3

This is how it looks like my config

      - image: circleci/cci-demo-docker-primary:0.0.2
        environment:
          HOME: /root
          PROJECT_NAME: xxxxxxxxxx
          CLOUDSDK_COMPUTE_ZONE: us-central1-a
          DOCKER_IMAGE: xxxxxxxxxx
          NAMESPACE: xxxxxxxxxx
          COMPOSE_PROJECT_NAME: xxxxxxxxxx


    steps:
      - checkout

      - run:
          name: Install Docker client
          command: |
            set -x
            VER="17.03.0-ce"
            curl -L -o /tmp/docker-$VER.tgz https://get.docker.com/builds/Linux/x86_64/docker-$VER.tgz
            tar -xz -C /tmp -f /tmp/docker-$VER.tgz
            mv /tmp/docker/* /usr/bin

      - run:
          name: Install Docker Compose
          command: |
            set -x
            curl -L https://github.com/docker/compose/releases/download/1.11.2/docker-compose-`uname -s`-`uname -m` > /usr/local/bin/docker-compose
            chmod +x /usr/local/bin/docker-compose

      - setup_remote_docker:
          reusable: true

      - run:
          name: build image
          command: |
            set -x
            docker-compose -f docker-compose.ci.yml build && docker-compose -f docker-compose.ci.yml pull

  test:
    working_directory: /opt/app
    docker:
      # using custom image, see .circleci/images/primary/Dockerfile
      - image: circleci/cci-demo-docker-primary:0.0.2
        environment:
          HOME: /root
          PROJECT_NAME: xxxxxxxxxx
          CLOUDSDK_COMPUTE_ZONE: xxxxxxxxxx
          DOCKER_IMAGE: fxxxxxxxxx
          NAMESPACE: xxxxxxxxxx
          COMPOSE_PROJECT_NAME: xxxxxxxxxx


    steps:
      - checkout

      - run:
          name: Install Docker client
          command: |
            set -x
            VER="17.03.0-ce"
            curl -L -o /tmp/docker-$VER.tgz https://get.docker.com/builds/Linux/x86_64/docker-$VER.tgz
            tar -xz -C /tmp -f /tmp/docker-$VER.tgz
            mv /tmp/docker/* /usr/bin

      - run:
          name: Install Docker Compose
          command: |
            set -x
            curl -L https://github.com/docker/compose/releases/download/1.11.2/docker-compose-`uname -s`-`uname -m` > /usr/local/bin/docker-compose
            chmod +x /usr/local/bin/docker-compose

      - setup_remote_docker:
          reusable: true

      - run:
          name: Run tests
          command: |
            set -x
            docker-compose -f docker-compose.ci.yml run app pytest

i dont want to install docker client and docker compose or terraform … every time on every job


#4

I asked the above question because it might be quicker to install software items for every job. Your alternative is to create a custom image - you can set that up so it has everything installed for you, but you still have to pull it from a registry. Have a look at the timings to see which is faster.

If you use a small base image, that makes things faster. Of course, if your DC image is 150M and not 550M, it will be much faster to pull.


#5

Thanks @halfer i will try that


#6