我需要在 Docker 镜像中设置一系列 Gitlab 钩子,以便在 pre-commit 时触发。我有一个 Docker 文件和一个 pre-commit-config.yaml 文件,其中除了一个无法正常工作的钩子外,其余都可以成功构建。
---
repos:
- repo: local
hooks:
- id: check-merge-conflict
name: Check for merge conflicts
description: Check for files that contain merge conflict strings.
entry: check-merge-conflict
language: python
types: [text]
- id: epp-validate
additional_dependencies: ['puppet']
description: Validate syntax of Puppet EPP templates
entry: /puppet-pre-commit-hooks/epp-validate
files: \.epp$
language: ruby
name: Validate EPP templates
- id: erb-validate
description: Validate syntax of Ruby ERB templates
entry: /puppet-pre-commit-hooks/erb-validate
files: \.erb$
language: ruby
name: Validate ERB templates
- id: puppet-lint
additional_dependencies: ['puppet-lint']
description: Check Puppet manifests for stylistic problems
entry: /puppet-pre-commit-hooks/puppet-lint
files: \.pp$
language: ruby
name: puppet-lint
args:
- --fail-on-warnings
- id: puppet-validate
additional_dependencies: ['puppet']
description: Validate syntax of Puppet manifests
entry: /puppet-pre-commit-hooks/puppet-validate
files: \.pp$
language: ruby
name: Validate Puppet manifests
- id: r10k-validate
additional_dependencies: ['r10k']
description: Validate syntax of Puppetfile using r10k
entry: /puppet-pre-commit-hooks/r10k-validate
files: ^Puppetfile$
language: ruby
name: Validate r10k Puppetfile
- id: ruby-validate
additional_dependencies: ['ruby']
description: Validate syntax of ruby code
entry: /puppet-pre-commit-hooks/ruby-validate
files: \.rb$
language: ruby
name: Validate ruby syntax
由于使用环境无法访问互联网,我不得不将钩子设置为本地钩子。为了解决这个问题,我克隆了一些具有适当钩子的存储库。
除了检查合并冲突钩子之外,它可以成功构建。在docker容器中,此钩子的python代码位于/pre-commit-hooks/pre_commit_hooks/check_merge_commit.py。
我尝试修改条目:值为 '''/pre-commit-hooks/pre_commit_hooks/check_merge_commit pre_commit_hooks/check-merge-commit check_merge_commit'''
但是这些都没有起作用。
Docker文件
FROM ruby:2.5.0
SHELL ["/bin/bash", "-o", "pipefail", "-c"]
RUN source ~/.profile
RUN curl https://pre-commit.com/install-local.py | python -
COPY pre-commit/.pre-commit-config.yaml .
RUN git clone https://github.com/pre-commit/pre-commit-hooks.git
RUN git clone https://github.com/chriskuehl/puppet-pre-commit-hooks.git
RUN git clone https://github.com/adrienverge/yamllint.git
WORKDIR /jumanjihouse
RUN git clone https://github.com/jumanjihouse/pre-commit-hooks.git
RUN rm -rf /jumanjihouse/pre-commit-hooks/.git* /yamllint/.git* /puppet-pre-commit-hooks/.git* /pre-commit-hooks/.git* /usr/local/lib/ruby/gems/2.5.0/gems/*/.git*
WORKDIR /
RUN git init
RUN /root/bin/pre-commit run -a
有人知道我漏掉了什么或者错了吗?
这个钩子来自于 Github
pre-commit install-hooks
吗?这样你就可以在空气隔离的情况下使用该镜像,而无需在运行时安装任何东西。 - anthony sottilepre-commit install-hooks
,并使用任何正常配置 -- 在运行时它不会使用网络。 - anthony sottileRUN /root/bin/pre-commit install-hooks
应该可以工作,对吗?如果这是基础知识的话,对不起,但我对编写管道还是很新的。 - MmmmDonutslocal
或手动克隆) - anthony sottile