We have a huge git repository (1+GB) with lots of history.
In a workflow with lots of jobs, it took 2+ mins on each job to do the checkout. It can lead to a lot of added time.
Here’s what you can do to only have to use “checkout” once:
Define a job that will checkout your repository and persist it in a workspace:
persist-checkout-to-workspace:
docker:
- image: python
steps:
- checkout
- run: rm -rf .git
- persist_to_workspace:
root: /root
paths:
- project
Define a fast-checkout anchor:
fast-checkout: &fast-checkout
attach_workspace:
at: /root
You can now use the instant fast-checkout step in any job following persist-checkout-to-workspace in your workflow:
sample-job:
docker:
- image: node
steps:
- *fast-checkout
- [...]
workflows:
version: 2
some-workflow:
jobs:
- persist-checkout-to-workspace
- sample-job:
requires:
- persist-checkout-to-workspace
2 Likes
halfer
April 14, 2018, 6:39pm
2
That looks excellent. I’d also say that a checkout
probably does a full clone
, when you probably only need a shallow clone
, i.e. with a --depth=1
. That would be very fast too.
I don’t think you can customize the checkout
step, so you are stuck to the full clone.
halfer
April 14, 2018, 10:08pm
4
Correct, but it’s optional in Circle 2.0. So you can just swap it out for an ordinary run
step containing the Git command you want.
And what about all the other stuff done in the checkout
step?
halfer
April 14, 2018, 10:25pm
6
Ooh, I didn’t know it did anything else. What else does it do?
You can look at what it does at any of your build, expand the checkout
step.
halfer
April 14, 2018, 10:48pm
8
The advice to remove the optional checkout
step and swap it to a custom Git command has been given by a Circle employee here before, so it may be worth a try?
Anyway, best of luck with whatever you decide!
You can try to cache the .git source, so it will only fetch new updates
- restore_cache:
keys:
- repo-source-{{ .Branch }}-{{ .Revision }}
- repo-source-{{ .Branch }}-
- repo-source-
- checkout
- save_cache:
key: repo-source-{{ .Branch }}-{{ .Revision }}
paths:
- ".git"
system
Closed
July 19, 2018, 10:05am
10
This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.