How to use pre-build image in GitLab CI

Hello, im kinda new to GitLab CI and i have a question. We have a js project and it needs some dependecies (installing in “npm ci” and “npm build” stages), that dependecies kinda constant and we use them in other projects. So i want to create image with this dependencies and use it as a base for every work building image. Problem is, i need to check “package.json” and rebuild my base image if dependencies have been changed. Is it possible to achive it in one .yml script? Thanks a lot for help!


I think that the easiest way to do what you need is as follows:

  1. Configure your GitLab CU Runner to use the Shell executor.
  2. Create a shell script on the Runner machine, which will do whatever you need.
  3. Call that script from your gitlab-ci.yml.
1 Like

So, its not possible with docker-runner, yes?

I don’t know, maybe it’s possible. I just don’t have enough experience with the Docker executor.

I also don’t understand what’s it advantage over Shell executor for regular software projects.

@badman02, maybe you should check and create image build and push job only when package.json file was changed?

1 Like

Oh, thanks a lot, you’ve made my day! )

1 Like