Tec*_*hie 6 git gitlab docker dockerfile
我是Docker的新手。我想创建一个映像,该映像将作为项目构建的一部分运行以检查提交的文件。
我的要求是,Docker文件应具有以下语句
<git files>
(作为命令行arg)我想为此过程创建一个图像。
我应该从当前本地存储库中获取git commits文件列表,并将这些文件传递给我的应用程序以扫描这些文件。
在构建映像时,我只需要复制我的应用程序,但是在运行容器时,我需要运行git diff
以查找更改的文件并将其作为参数传递给我的应用程序。
是否可以git diff
通过docker容器运行?
更新:
我试图git diff
在docker的当前存储库上执行,但是它说的不是git存储库。我正在将Docker映像作为gitlab yml文件中持续集成的一部分运行。
请帮我达到这个要求?
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>/...
Run Code Online (Sandbox Code Playgroud)
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> .
Run Code Online (Sandbox Code Playgroud)
Good luck.
小智 1
如果您已将 git 安装到镜像中,则可以在 docker 容器中运行 git 命令。安装取决于您的基础镜像操作系统,以下是基于 centos 7 的 dockerfile 示例
FROM centos:7
RUN yum clean all && yum install -y git
Run Code Online (Sandbox Code Playgroud)
归档时间: |
|
查看次数: |
4471 次 |
最近记录: |