none
How to re-use a Docker image from a stage? RRS feed

  • Question

  • CONTEXT

    I need to build multiple docker images, which requires a specific order. To execute such order, I've created 2 stages, the first one, which is responsible for building all base images, and the second, which need those base images to build specific images.

    stages:
    - stage: base
      displayName: Base Images
      jobs:
      - job: Docker
        pool:
          vmImage: 'ubuntu-16.04'
        timeoutInMinutes: 120
        steps:
        - task: UsePythonVersion@0
          inputs:
            versionSpec: '3.6'
            architecture: 'x64'
        - script: python build.py
          env:
            DOCKER_PASSWORD: $(DOCKER_PASSWORD)
        strategy:
          matrix:        
            Ubuntu GCC 4.9 x86_64:
              GCC_VERSIONS: "4.9"
            Ubuntu GCC 4.9 x86:
              GCC_VERSIONS: "4.9"
              DOCKER_ARCHS: "x86"
            Ubuntu GCC 5 x86_64:
              GCC_VERSIONS: "5"
            Ubuntu GCC 5 x86:
              GCC_VERSIONS: "5"
              DOCKER_ARCHS: "x86"
            Ubuntu GCC 5.2 x86_64:
              GCC_VERSIONS: "5.2"
            Ubuntu GCC 5.3 x86_64:
              GCC_VERSIONS: "5.3"
            Ubuntu GCC 6 x86_64:
              GCC_VERSIONS: "6"
            Ubuntu GCC 6 x86:
              GCC_VERSIONS: "6"
              DOCKER_ARCHS: "x86"
         
    - stage: specilized
      displayName: Specilized Images
      jobs:
      - job: Docker
        pool:
          vmImage: 'ubuntu-16.04'
        timeoutInMinutes: 120
        steps:
        - task: UsePythonVersion@0
          inputs:
            versionSpec: '3.6'
            architecture: 'x64'
        - script: python build.py
          env:
            DOCKER_PASSWORD: $(DOCKER_PASSWORD)
        strategy:
          matrix:                
            Jenkins Slave GCC 4.9 x86_64:
              GCC_VERSIONS: "4.9"
              DOCKER_ARCHS: "x86_64"
              DOCKER_DISTRO: "jnlp-slave"
            Jenkins Slave GCC 4.9 x86:
              GCC_VERSIONS: "4.9"
              DOCKER_ARCHS: "x86"
              DOCKER_DISTRO: "jnlp-slave"
            Jenkins Slave GCC 5 x86_64:
              GCC_VERSIONS: "5"
              DOCKER_ARCHS: "x86_64"
              DOCKER_DISTRO: "jnlp-slave"
            Jenkins Slave GCC 5 x86:
              GCC_VERSIONS: "5"
              DOCKER_ARCHS: "x86"
              DOCKER_DISTRO: "jnlp-slave"
            Jenkins Slave GCC 6 x86_64:
              GCC_VERSIONS: "6"
              DOCKER_ARCHS: "x86_64"
              DOCKER_DISTRO: "jnlp-slave"
            Jenkins Slave GCC 6 x86:
              GCC_VERSIONS: "6"
              DOCKER_ARCHS: "x86"
              DOCKER_DISTRO: "jnlp-slave"
    

    The script python build.py calls docker client to build a docker image. The first stage provides all base images which should be used by the second stage. Also, all those images should be uploaded, but only when on master branch (condition checked by build.py).

    PROBLEM

    The second stage does not use the images generated from the first stage, it downloads the latest version available on Hub Docker.

    QUESTION

    How could I use those images generated on first stage instead of downloading?

    Monday, May 13, 2019 3:25 PM

Answers

All replies