How can I persist a docker image instance between stages of a GitLab pipeline? (2024)

In the last couple weeks I have been setting up my first pipeline using the public shared runners on GitLab.com for a php project in a private repository. The pipeline is pretty simple at this point, defining two stages:

stages: - test - deploy

The test stage runs composer update -o to build the project dependencies, connects to a remote database server, and runs the CodeCeption testing framework to test the build and generate code coverage reports.

The deploy stage runs composer update --no-dev -o to rebuild the project with only the production dependencies and uses rsync to push the files to the production webserver.

This is all working right now, but for each stage it runs the whole process of pulling the docker image, installing dependencies, and extracting the project from git. It seems like it would be a whole lot more efficient to just load the docker image and project once, then run the test and deploy stages one after the other using the same persistent build instance.

I realize that many times you do want to create a fresh instance for each stage, but with my project I feel like this is rather inefficient for time and server resources.

I could configure everything to run in the same stage, which would eliminate the redundant docker image process, but I would lose the pipeline functionality in GitLab where you can see which stages failed, and make later stages dependent on the success of the preceding ones.

How can I persist a docker image instance between stages of a GitLab pipeline? (1)

From my review of the documentation and several related questions, it seems like this might have to do with the the architecture of how this process works, where jobs are independent of each other (and can even be processed by different runners) and are organized into stages on a pipeline.

What I have is certainly workable, (if a little slow) but I thought I would ask the question here in case there was something I was missing that would make this process more efficient while still retaining the CI pipeline functionality.

Can we push Docker image to GitLab?

GitLab CI/CD can be used with Docker to build Docker images. For example, you can create a Docker image of your application and push it to a GitLab's Container Registry.

Do GitLab stages run in parallel?

GitLab provides a method to make clones of a job and run them in parallel for faster execution using the parallel: keyword. While parallel jobs may not help in reducing the consumption of CI minutes, they definitely help increase work productivity.

What is Docker DIND in GitLab?

gitlab/dind is image that should be used to build projects with docker-based workflow. The image runs Docker Engine and includes Docker Compose which allows to use full docker toolkit from build script. docker pull gitlab/dind. © 2022 Docker Inc.

I know this is an old question, but want to provide an answer for anyone that has the same issue.

There's a config option for the Gitlab Runner application itself that controls when the runner will use a local copy of an image or not. If you manage and user your own runners (even if using gitlab.com) you have full control over these options, but if you use the shared runners provided by Gitlab, you cannot.

Here are the three "pull policies" you can use:

  1. Never. The never pull policy will instruct the runner to never pull images from Docker cloud or another repository, and will only use images already pulled to the Docker host. This allows full control over images and versions used by Gitlab.
  2. If Not Present. The if not present policy instructs the runner to first check if the image is available locally, and if so to use it. Otherwise, it will pull the image from it's repository.
  3. Always. The always policy instructs the runner to ignore any local images, and pull from the repository every time the job runs.

For the shared runners on gitlab.com, the pull policy is set to always to serve the needs of most users. The solution to this issue is to register your own runner(s) for your projects (which you can run in AWS EC2, your laptop/workstation, etc.

Here is the information on available configuration options when running your own Gitlab Runner.

Here are specific details on the available Pull Policies, and when to use them (or not to).

Here is how to register a runner to your projects (or to your entire instance if using self-hosted Gitlab).

How can I persist a docker image instance between stages of a GitLab pipeline? (2024)

References

Top Articles
Deputies: Drunk driver nearly struck vehicle on NYS Thruway
8 Underappreciated Towns To Visit In The Finger Lakes
Where To Go After Howling Pit Code Vein
No Limit Telegram Channel
Affidea ExpressCare - Affidea Ireland
Insidious 5 Showtimes Near Cinemark Tinseltown 290 And Xd
Kansas Craigslist Free Stuff
Volstate Portal
AB Solutions Portal | Login
The Shoppes At Zion Directory
RBT Exam: What to Expect
Labor Gigs On Craigslist
Quest Beyondtrustcloud.com
Chastity Brainwash
U Arizona Phonebook
How to Watch the Fifty Shades Trilogy and Rom-Coms
Promiseb Discontinued
How your diet could help combat climate change in 2019 | CNN
Woodmont Place At Palmer Resident Portal
Dtlr Duke St
How To Tighten Lug Nuts Properly (Torque Specs) | TireGrades
Hannah Palmer Listal
Striffler-Hamby Mortuary - Phenix City Obituaries
Play It Again Sports Forsyth Photos
Core Relief Texas
3 Ways to Format a Computer - wikiHow
Stouffville Tribune (Stouffville, ON), March 27, 1947, p. 1
Ryujinx Firmware 15
Guide to Cost-Benefit Analysis of Investment Projects Economic appraisal tool for Cohesion Policy 2014-2020
Wells Fargo Bank Florida Locations
Teenbeautyfitness
Everstart Jump Starter Manual Pdf
Craigslist Albany Ny Garage Sales
Robot or human?
Ippa 番号
Daily Jail Count - Harrison County Sheriff's Office - Mississippi
3400 Grams In Pounds
About :: Town Of Saugerties
Gifford Christmas Craft Show 2022
Wal-Mart 140 Supercenter Products
Pa Legion Baseball
30 Years Of Adonis Eng Sub
Why Are The French So Google Feud Answers
705 Us 74 Bus Rockingham Nc
Best Suv In 2010
Swsnj Warehousing Inc
Tacos Diego Hugoton Ks
DL381 Delta Air Lines Estado de vuelo Hoy y Historial 2024 | Trip.com
Windy Bee Favor
Twizzlers Strawberry - 6 x 70 gram | bol
The Love Life Of Kelsey Asbille: A Comprehensive Guide To Her Relationships
Emmi-Sellers
Latest Posts
Article information

Author: Manual Maggio

Last Updated:

Views: 6400

Rating: 4.9 / 5 (49 voted)

Reviews: 80% of readers found this page helpful

Author information

Name: Manual Maggio

Birthday: 1998-01-20

Address: 359 Kelvin Stream, Lake Eldonview, MT 33517-1242

Phone: +577037762465

Job: Product Hospitality Supervisor

Hobby: Gardening, Web surfing, Video gaming, Amateur radio, Flag Football, Reading, Table tennis

Introduction: My name is Manual Maggio, I am a thankful, tender, adventurous, delightful, fantastic, proud, graceful person who loves writing and wants to share my knowledge and understanding with you.