GuillaumeA
GuillaumeA

Reputation: 3545

Git clone repo in Dockerfile lags

I'm trying to clone a private repo hosted by bitbucket to a docker container. My Dockerfile is as follow

RUN git clone git@deploy:<blabla>.git /src/<blabla>
WORKDIR /src/<blabla>
RUN cd /src/<blabla>
RUN git pull --all --tags
RUN git checkout v1.1.2
RUN pip install .

The problem I have: I am said that the tag v1.1.2 does not exist. To confirm that, I change the Dockerfile with

RUN git clone git@deploy:<blabla>.git /src/<blabla>
WORKDIR /src/<blabla>
RUN cd /src/<blabla>
RUN git pull --all --tags
RUN git branch
RUN git tag
RUN git checkout v1.1.2
RUN pip install .

where I can see that the last created branch and the last tag are now cloned indeed. The workaround I found is to make a double pull

RUN git clone git@deploy:<blabla>.git /src/<blabla>
WORKDIR /src/<blabla>
RUN cd /src/<blabla>
RUN git pull --all --tags
RUN git pull --all --tags
RUN git checkout v1.1.2
RUN pip install .

and now everything works great.

Upvotes: 0

Views: 2173

Answers (1)

Boynux
Boynux

Reputation: 6222

Try this:

RUN git clone -b 'v1.1.2' --single-branch --depth 1 git@deploy:<blabla>.git /src/<blabla> \
   && cd /src/<blabla> \
   && pip install .

WORKDIR /src/<blabla>

Git clone can directly fetch the tag, and adding --single-branch and --depth avoid to clone the whole repository history to the container.

It's a bit more compact and avoids extra layers. You can still break it into multiple lines of you want.

Upvotes: 1

Related Questions