mirror of
https://github.com/tofuutils/pre-commit-opentofu.git
synced 2025-10-15 17:38:54 +02:00
chore: Add hadolint check for Dockerfiles (#322)
Co-authored-by: Balazs Hamorszky <balihb@gmail.com>
This commit is contained in:
parent
321fb16693
commit
47229003ff
6 changed files with 46 additions and 18 deletions
4
.github/CONTRIBUTING.md
vendored
4
.github/CONTRIBUTING.md
vendored
|
|
@ -72,8 +72,8 @@ sudo apt install -y datamash
|
||||||
### Run via Docker
|
### Run via Docker
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
# Build `pre-commit` image
|
# Build `pre-commit-terraform` image
|
||||||
docker build -t pre-commit --build-arg INSTALL_ALL=true .
|
docker build -t pre-commit-terraform --build-arg INSTALL_ALL=true .
|
||||||
# Build test image
|
# Build test image
|
||||||
docker build -t pre-commit-tests tests/
|
docker build -t pre-commit-tests tests/
|
||||||
# Run
|
# Run
|
||||||
|
|
|
||||||
17
.github/workflows/pre-commit.yaml
vendored
17
.github/workflows/pre-commit.yaml
vendored
|
|
@ -25,19 +25,32 @@ jobs:
|
||||||
- name: Install shellcheck
|
- name: Install shellcheck
|
||||||
run: |
|
run: |
|
||||||
sudo apt update && sudo apt install shellcheck
|
sudo apt update && sudo apt install shellcheck
|
||||||
|
|
||||||
|
- name: Install hadolint
|
||||||
|
run: |
|
||||||
|
curl -L "$(curl -s https://api.github.com/repos/hadolint/hadolint/releases/latest | grep -o -E -m 1 "https://.+?/hadolint-Linux-x86_64")" > hadolint \
|
||||||
|
&& chmod +x hadolint && sudo mv hadolint /usr/bin/
|
||||||
# Need to success pre-commit fix push
|
# Need to success pre-commit fix push
|
||||||
- uses: actions/checkout@v2
|
- uses: actions/checkout@v2
|
||||||
with:
|
with:
|
||||||
fetch-depth: 0
|
fetch-depth: 0
|
||||||
ref: ${{ github.event.pull_request.head.sha }}
|
ref: ${{ github.event.pull_request.head.sha }}
|
||||||
|
# Skip terraform_tflint which interferes to commit pre-commit auto-fixes
|
||||||
- uses: actions/setup-python@v2
|
- uses: actions/setup-python@v2
|
||||||
with:
|
with:
|
||||||
python-version: '3.9'
|
python-version: '3.9'
|
||||||
- name: Execute pre-commit
|
- name: Execute pre-commit
|
||||||
uses: pre-commit/action@v2.0.0
|
uses: pre-commit/action@v2.0.0
|
||||||
env:
|
env:
|
||||||
SKIP: no-commit-to-branch
|
SKIP: no-commit-to-branch,hadolint
|
||||||
with:
|
with:
|
||||||
token: ${{ secrets.GITHUB_TOKEN }}
|
token: ${{ secrets.GITHUB_TOKEN }}
|
||||||
extra_args: --color=always --show-diff-on-failure --files ${{ steps.file_changes.outputs.files }}
|
extra_args: --color=always --show-diff-on-failure --files ${{ steps.file_changes.outputs.files }}
|
||||||
|
# Run only skipped checks
|
||||||
|
- name: Execute pre-commit check that have no auto-fixes
|
||||||
|
if: always()
|
||||||
|
uses: pre-commit/action@v2.0.0
|
||||||
|
env:
|
||||||
|
SKIP: check-added-large-files,check-merge-conflict,check-vcs-permalinks,forbid-new-submodules,no-commit-to-branch,end-of-file-fixer,trailing-whitespace,check-yaml,check-merge-conflict,check-executables-have-shebangs,check-case-conflict,mixed-line-ending,detect-aws-credentials,detect-private-key,shfmt,shellcheck
|
||||||
|
with:
|
||||||
|
extra_args: --color=always --show-diff-on-failure --files ${{ steps.file_changes.outputs.files }}
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,6 @@
|
||||||
repos:
|
repos:
|
||||||
- repo: https://github.com/pre-commit/pre-commit-hooks
|
- repo: https://github.com/pre-commit/pre-commit-hooks
|
||||||
rev: v4.0.1
|
rev: v4.1.0
|
||||||
hooks:
|
hooks:
|
||||||
# Git style
|
# Git style
|
||||||
- id: check-added-large-files
|
- id: check-added-large-files
|
||||||
|
|
@ -34,3 +34,18 @@ repos:
|
||||||
- id: shfmt
|
- id: shfmt
|
||||||
args: ['-l', '-i', '2', '-ci', '-sr', '-w']
|
args: ['-l', '-i', '2', '-ci', '-sr', '-w']
|
||||||
- id: shellcheck
|
- id: shellcheck
|
||||||
|
|
||||||
|
# Dockerfile linter
|
||||||
|
- repo: https://github.com/hadolint/hadolint
|
||||||
|
rev: v2.8.0
|
||||||
|
hooks:
|
||||||
|
- id: hadolint
|
||||||
|
args: [
|
||||||
|
'--ignore', 'DL3027', # Do not use apt
|
||||||
|
'--ignore', 'DL3007', # Using latest
|
||||||
|
'--ignore', 'DL4006', # Not related to alpine
|
||||||
|
'--ignore', 'SC1091', # Useless check
|
||||||
|
'--ignore', 'SC2015', # Useless check
|
||||||
|
'--ignore', 'SC3037', # Not related to alpine
|
||||||
|
'--ignore', 'DL3013', # Pin versions in pip
|
||||||
|
]
|
||||||
|
|
|
||||||
20
Dockerfile
20
Dockerfile
|
|
@ -1,14 +1,14 @@
|
||||||
ARG TAG=3.9.7-alpine3.14
|
ARG TAG=3.10.1-alpine3.15
|
||||||
FROM python:${TAG} as builder
|
FROM python:${TAG} as builder
|
||||||
|
|
||||||
WORKDIR /bin_dir
|
WORKDIR /bin_dir
|
||||||
|
|
||||||
RUN apk add --no-cache \
|
RUN apk add --no-cache \
|
||||||
# Builder deps
|
# Builder deps
|
||||||
curl \
|
curl=~7 \
|
||||||
unzip && \
|
unzip=~6 && \
|
||||||
# Upgrade pip for be able get latest Checkov
|
# Upgrade pip for be able get latest Checkov
|
||||||
python3 -m pip install --upgrade pip
|
python3 -m pip install --no-cache-dir --upgrade pip
|
||||||
|
|
||||||
ARG PRE_COMMIT_VERSION=${PRE_COMMIT_VERSION:-latest}
|
ARG PRE_COMMIT_VERSION=${PRE_COMMIT_VERSION:-latest}
|
||||||
ARG TERRAFORM_VERSION=${TERRAFORM_VERSION:-latest}
|
ARG TERRAFORM_VERSION=${TERRAFORM_VERSION:-latest}
|
||||||
|
|
@ -57,7 +57,7 @@ RUN if [ "$INSTALL_ALL" != "false" ]; then \
|
||||||
RUN . /.env && \
|
RUN . /.env && \
|
||||||
if [ "$CHECKOV_VERSION" != "false" ]; then \
|
if [ "$CHECKOV_VERSION" != "false" ]; then \
|
||||||
( \
|
( \
|
||||||
apk add --no-cache gcc libffi-dev musl-dev; \
|
apk add --no-cache gcc=~10 libffi-dev=~3 musl-dev=~1; \
|
||||||
[ "$CHECKOV_VERSION" = "latest" ] && pip3 install --no-cache-dir checkov \
|
[ "$CHECKOV_VERSION" = "latest" ] && pip3 install --no-cache-dir checkov \
|
||||||
|| pip3 install --no-cache-dir checkov==${CHECKOV_VERSION}; \
|
|| pip3 install --no-cache-dir checkov==${CHECKOV_VERSION}; \
|
||||||
apk del gcc libffi-dev musl-dev \
|
apk del gcc libffi-dev musl-dev \
|
||||||
|
|
@ -146,9 +146,9 @@ FROM python:${TAG}
|
||||||
|
|
||||||
RUN apk add --no-cache \
|
RUN apk add --no-cache \
|
||||||
# pre-commit deps
|
# pre-commit deps
|
||||||
git \
|
git=~2 \
|
||||||
# All hooks deps
|
# All hooks deps
|
||||||
bash
|
bash=~5
|
||||||
|
|
||||||
# Copy tools
|
# Copy tools
|
||||||
COPY --from=builder \
|
COPY --from=builder \
|
||||||
|
|
@ -159,16 +159,16 @@ COPY --from=builder \
|
||||||
/usr/local/bin/checkov* \
|
/usr/local/bin/checkov* \
|
||||||
/usr/bin/
|
/usr/bin/
|
||||||
# Copy pre-commit packages
|
# Copy pre-commit packages
|
||||||
COPY --from=builder /usr/local/lib/python3.9/site-packages/ /usr/local/lib/python3.9/site-packages/
|
COPY --from=builder /usr/local/lib/python3.10/site-packages/ /usr/local/lib/python3.10/site-packages/
|
||||||
# Copy terrascan policies
|
# Copy terrascan policies
|
||||||
COPY --from=builder /root/ /root/
|
COPY --from=builder /root/ /root/
|
||||||
|
|
||||||
# Install hooks extra deps
|
# Install hooks extra deps
|
||||||
RUN if [ "$(grep -o '^terraform-docs SKIPPED$' /usr/bin/tools_versions_info)" = "" ]; then \
|
RUN if [ "$(grep -o '^terraform-docs SKIPPED$' /usr/bin/tools_versions_info)" = "" ]; then \
|
||||||
apk add --no-cache perl \
|
apk add --no-cache perl=~5 \
|
||||||
; fi && \
|
; fi && \
|
||||||
if [ "$(grep -o '^infracost SKIPPED$' /usr/bin/tools_versions_info)" = "" ]; then \
|
if [ "$(grep -o '^infracost SKIPPED$' /usr/bin/tools_versions_info)" = "" ]; then \
|
||||||
apk add --no-cache jq \
|
apk add --no-cache jq=~1 \
|
||||||
; fi
|
; fi
|
||||||
|
|
||||||
ENV PRE_COMMIT_COLOR=${PRE_COMMIT_COLOR:-always}
|
ENV PRE_COMMIT_COLOR=${PRE_COMMIT_COLOR:-always}
|
||||||
|
|
|
||||||
|
|
@ -73,8 +73,8 @@ function infracost_breakdown_ {
|
||||||
}; then
|
}; then
|
||||||
check="${check:1:-1}"
|
check="${check:1:-1}"
|
||||||
fi
|
fi
|
||||||
# shellcheck disable=SC2207 # Can't find working `read` command
|
|
||||||
operations=($(echo "$check" | grep -oE '[!<>=]{1,2}'))
|
mapfile -t operations < <(echo "$check" | grep -oE '[!<>=]{1,2}')
|
||||||
# Get the very last operator, that is used in comparison inside `jq` query.
|
# Get the very last operator, that is used in comparison inside `jq` query.
|
||||||
# From the example below we need to pick the `>` which is in between `add` and `1000`,
|
# From the example below we need to pick the `>` which is in between `add` and `1000`,
|
||||||
# but not the `!=`, which goes earlier in the `jq` expression
|
# but not the `!=`, which goes earlier in the `jq` expression
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,4 @@
|
||||||
FROM pre-commit
|
FROM pre-commit-terraform:latest
|
||||||
|
|
||||||
RUN apt update && \
|
RUN apt update && \
|
||||||
apt install -y \
|
apt install -y \
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue