Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[#1035] Added Hadolint to CI for consumer sites. #1151

Merged
merged 2 commits into from
Jan 22, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -314,6 +314,12 @@ jobs:
name: Build site
command: ./scripts/drevops/build.sh
no_output_timeout: 30m
- run:
name: Lint Dockerfiles with Hadolint
command: |
for file in $(find . -name 'Dockerfile' -o -name '*.dockerfile'); do
echo "Linting ${file}" && cat "${file}" | docker run --rm -i hadolint/hadolint || [ "${DREVOPS_CI_HADOLINT_IGNORE_FAILURE:-0}" -eq 1 ]
done
- run:
name: Lint code with PHPCS
command: docker compose exec -T cli vendor/bin/phpcs || [ "${DREVOPS_CI_PHPCS_IGNORE_FAILURE:-0}" -eq 1 ]
Expand Down
3 changes: 3 additions & 0 deletions .drevops/docs/.utils/.aspell.en.pws
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ DX
Deployer
DevOps
DockerHub
Dockerfile
DrevOps
Drupal
DrupalExtension
Expand All @@ -32,6 +33,7 @@ GitLab
GraphQL
Gruntfile
HTTPS
Hadolint
Hotfix
Integrations
JS
Expand Down Expand Up @@ -116,6 +118,7 @@ hostname
integrations
io
jira
linter
linters
mariadb
md
Expand Down
4 changes: 2 additions & 2 deletions .drevops/docs/.utils/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
FROM squidfunk/mkdocs-material:9.5.4

ENV DOCKERIZE_VERSION v0.7.0
RUN wget https://github.com/jwilder/dockerize/releases/download/$DOCKERIZE_VERSION/dockerize-alpine-linux-amd64-$DOCKERIZE_VERSION.tar.gz \
RUN wget --quiet https://github.com/jwilder/dockerize/releases/download/$DOCKERIZE_VERSION/dockerize-alpine-linux-amd64-$DOCKERIZE_VERSION.tar.gz \
&& tar -C /usr/local/bin -xzvf dockerize-alpine-linux-amd64-$DOCKERIZE_VERSION.tar.gz \
&& rm dockerize-alpine-linux-amd64-$DOCKERIZE_VERSION.tar.gz

RUN pip install mdx_include mkdocs-same-dir mkdocs-replace-markdown mike==1.1.2
RUN pip install --no-cache-dir mdx_include==1.4.2 mkdocs-same-dir==0.1.2 mkdocs-replace-markdown==0.1.0 mike==1.1.2

WORKDIR /app

Expand Down
38 changes: 38 additions & 0 deletions .drevops/docs/content/tools/hadolint.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
# Hadolint

https://github.com/hadolint/hadolint

> A smarter Dockerfile linter that helps you build best practice Docker images.

DrevOps does not install Hadolint. Please follow the [
instructions(https://github.com/hadolint/hadolint#install) to install it on your
system.

## Usage

```shell
hadolint .docker/*.dockerfile
```

## Ignoring

To ignore **all Hadolint rules** within a file, place in the file header:
```Dockerfile
# hadolint global ignore=DL3003,DL3006,SC1035
FROM ubuntu
```

To ignore only the current and the **next line**:
```Dockerfile
FROM ubuntu

# hadolint ignore=DL3003,SC1035
RUN cd /tmp && echo "hello!"
```

## Ignoring fail in CI

This tool runs in CI by default and fails the build if there are any violations.

Set `DREVOPS_CI_HADOLINT_IGNORE_FAILURE` environment variable to `1` to ignore
failures. The tool will still run and report violations, if any.
1 change: 1 addition & 0 deletions .drevops/docs/mkdocs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -199,6 +199,7 @@ nav:
- Drush: tools/drush.md
- Git artifact: tools/git-artifact.md
- PHPCS: tools/phpcs.md
- Hadolint: tools/hadolint.md
- PHPMD: tools/phpmd.md
- PHPStan: tools/phpstan.md
- PHPUnit: tools/phpunit.md
Expand Down