I am new to docker. I would like to create an image which will run as part of my project build to check commited files.
My requirement is, Docker file should have these statements
<git files>
(as command line arg)I would like to create an image for this process.
I should get the git commited files list from current local repo and pass those files to my application to scan those files.
While building my image I just need to copy my application but while running the container I need to run git diff
to find changed files and pass that to my application as arguments.
Is it possible to run git diff
by docker container?
UPDATE:
I tried to execute git diff
on current repo from docker but it is saying not a git repository.
I am running my docker images as part of continuous integration in gitlab yml file.
Please help me to achieve this requirement?
Yes, you can. Let me recommend some things about that.
git clone
cloning only needed folders, not the whole repo.So, your Dockerfile could be, for example for debian/ubuntu:
FROM <your linux distribution>
ARG GIT_USER
ARG GIT_TOKEN
ARG GIT_COMMIT
ARG SW_VERSION
RUN apt-get update
RUN apt-get -y install git
RUN git clone -n https://${GIT_USER}:${GIT_TOKEN}@github.com/<your git>/your_git.git --depth 1 && cd <your_git> && git checkout ${GIT_COMMIT} <dir_you_want_to_checkout>
COPY myapp/ /app
CMD /app/entry.pl /<your_git>/<dir_you_want_to_checkout>/...
Then, you can build as you know with:
docker build -t --build-arg GIT_USER=<your_user> --build-arg GIT_TOKEN=d0e4467c63... --build-arg GIT_COMMIT=a14dc9f454... <your_image_name> .
Good luck.
If you want a minimal docker image where you can use a git command I can recommend using gitlab/gitlab-runner:alpine
from here as your image.
At the time of writing this image comes at 40Mb, which is close to the smallest I can picture that has git available. This will skip you some time in installing git
using a package manager.
The image itself seem to be frequently maintained by the gitlab folks.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With