简体   繁体   中英

Custom Gitlab CI docker image for job

I have application in Django. Requirements consist of many libraries. After linting stage in Gitlab CI I would like to run some tests I wrote. To be able to run Postgres and Django I have to install requirements, it take some time.

Is there some easy way how to cache that image with all installed requirements or I have to install it all again every time I want to run that tests? It is impractical according to me.

I could have job before test where I would build my custom image based on requirements and image I build last time, as cache image. I could keep custom image in personal registry and use it in next job with tests.

linting --> build_job_image --> tests --> staging --> production

It looks like better way than install it every time, but still not the best idea.

I am new with DevOps so I am trying to find the best way, don't know what is the best practice.

I am using python:3.7-alpine image for this job.

I solved this issue with gitlab cache :

  1. Specify directory that should be cached (directory with python packages).
  2. Job will try to pull cache (It is basically just zip file) and unzip it.
  3. Install all necessary packages that are in requirements.txt (If you do not add more new packages to requirements.txt, everything is already in cache).
  4. At the end of job, job will zip the cache directory and push it.

During next run everything is much faster, because more of requirements packages are already installed.

Second option mentioned by Zeitounator is also a way.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM