title: How to conditionally update a CI/CD job image?
body: <p>I just got into the (wonderful) world of CI/CD and have working pipelines. They are not optimal, though. </p>
  
  <p>The application is a dockerized website:</p>
  
  <ul>
  <li>the source needs to be compiled by <code>webpack</code> and end up in <code>dist</code></li>
  <li>this <code>dist</code> directory is copied to a docker container</li>
  <li>which is then remotely built and deployed</li>
  </ul>
  
  <p>My current setup is quite naïve (I added some comments to show why I believe the various elements are needed/useful):</p>
  
  <pre><code># I start with a small image
  image: alpine
  
  # before the job I need to have npm and docker
  # the problem: I need one in one job, and the second one in the other
  # I do not need both on both jobs but do not see how to split them
  before_script:
      - apk add --update npm
      - apk add docker
      - npm install
      - npm install webpack -g
  
  stages:
      - create_dist
      - build_container
      - stop_container
      - deploy_container
  
  # the dist directory is preserved for the other job which will make use of it
  create_dist:
      stage: create_dist
      script: npm run build
      artifacts:
          paths:
          - dist
  
  # the following three jobs are remote and need to be daisy chained
  build_container:
      stage: build_container
      script: docker -H tcp://eu13:51515 build -t widgets-sentinels .
  
  stop_container:
      stage: stop_container
      script: docker -H tcp://eu13:51515 stop widgets-sentinels
      allow_failure: true
  
  deploy_container:
      stage: deploy_container
      script: docker -H tcp://eu13:51515 run --rm -p 8880:8888 --name widgets-sentinels -d widgets-sentinels
  </code></pre>
  
  <p>This setups works bit <code>npm</code> and <code>docker</code> are installed in both jobs. This is not needed and slows down the deployment. <strong>Is there a way to state that such and such packages need to be added for specific jobs (and not globally to all of them)?</strong></p>
  
  <p>To make it clear: this is not a show stopper (and in reality not likely to be an issue at all) but I fear that my approach to such a job automation is incorrect.</p>