Webhook icon
Schedule icon
WorkingDirectory icon
Commands icon
Docker icon
Script icon
If icon
Create icon
SlackIncomingWebhook icon
Log icon

Gate Pull Request Merges on hadolint Dockerfile Violations

Lint opened pull request Dockerfiles with hadolint, grade findings by severity, and escalate with a GitHub issue and a Slack alert.

Categories
Infrastructure

How it works

  1. pull_request_opened (io.kestra.plugin.core.trigger.Webhook, keyed with HADOLINT_WEBHOOK_KEY) accepts the CI notification for an opened pull request and maps repository.full_name and pull_request.number from the payload onto the flow inputs, so the issue lands in the right repository without a second configuration. nightly_policy_sweep (io.kestra.plugin.core.trigger.Schedule, cron 0 3 * * *) ships with disabled: true, a rehearsal net that stays dark until an operator switches it on.
  2. lint_workspace (io.kestra.plugin.core.flow.WorkingDirectory) opens one shared directory so the report the linter writes and the parser that grades it read the same file, a scratch directory outside a WorkingDirectory is purged between tasks and would break that hand-off.
  3. run_hadolint (io.kestra.plugin.scripts.shell.Commands on the io.kestra.plugin.scripts.runner.docker.Docker runner, image hadolint/hadolint:latest-alpine, the tag that ships a shell while the default tag is built FROM scratch) writes the Dockerfile under review with a heredoc, checks that the linter binary is actually present, then runs hadolint --format json Dockerfile > hadolint-report.json || true. The || true absorbs hadolint's nonzero exit on findings so only the parsed verdict below can fail the gate, while a container missing the binary exits nonzero and lands in the errors alert instead of reading as a clean lint.
  4. parse_report (io.kestra.plugin.scripts.python.Script on python:3.12-slim) reads the JSON report, prefers the level each finding carries and falls back to a per-rule severity table, counts style, info, warning, and error findings, and grades the totals against the fail_on_level input. An unreadable or missing report becomes SCAN_ERROR, so a broken linter never reads as a passing Dockerfile.
  5. gate_on_severity (io.kestra.plugin.core.flow.If) branches when verdict is anything but PASS. Failing runs open open_dockerfile_issue (io.kestra.plugin.github.issues.Create) with the counts and rule codes, then alert_slack (io.kestra.plugin.slack.notifications.SlackIncomingWebhook) posts the summary; clean runs record log_clean so the execution history doubles as merge evidence.
  6. The errors block posts to Slack when the container or the parser itself breaks, because a dead gate looks exactly like a passing one.

What you get

  • A gateable verdict, verdict, error_count, warning_count, rule_codes, and report_uri are flow outputs the merge pipeline can branch on.
  • A GitHub issue that names the pull request, the repository, the per-severity counts, and every rule code that fired, labeled for the platform backlog.
  • A Slack message with the verdict and the counts, so nobody opens the execution just to learn why CI went red.
  • The raw hadolint JSON kept in internal storage as lint evidence next to the pull request.

Who it's for

  • Platform teams that own base images and want Dockerfile standards enforced before merge instead of in a post-merge sweep.
  • Security engineers who treat an unpinned package, a root final user, or a floating tag as a policy violation rather than a style opinion.
  • CI maintainers who want the linter version pinned in a flow file instead of scattered across pipeline scripts.

Why orchestrate this with Kestra

A lint script bolted onto a pipeline runs only where someone remembered to call it, hides its tool version in an image tag nobody reviews, and drops its findings into a log nobody reads. Kestra wraps the same hadolint run in a keyed webhook plus a disabled nightly schedule, pins the linter image in a versioned file, turns the parsed result into a branch that files an issue and pings Slack, and keeps execution history with the raw report attached, so the gate itself is auditable and can be retargeted at another repository through inputs alone.

Prerequisites

  • A worker with Docker access, both the linter and the parser run in containers.
  • A GitHub token that can open issues in github_repository (classic PAT scope repo, or fine-grained Issues: write).
  • A Slack incoming webhook for the gate alert and for the failure alert.
  • A CI job that POSTs to the webhook when a pull request touches a Dockerfile.

Secrets

  • HADOLINT_WEBHOOK_KEY: key segment guarding the webhook URL, anyone holding it can start the gate.
  • GITHUB_TOKEN: token used by open_dockerfile_issue to open the failure issue.
  • SLACK_WEBHOOK_URL: Slack incoming webhook URL used by alert_slack and by the errors block.

Quick start

  1. Add the three secrets to the Kestra namespace and point github_repository at a repository where issues are welcome.
  2. Run the flow once with the default inputs. The bundled Dockerfile carries a latest tag, a MAINTAINER line, an unpinned apt-get install, a root final user, and an ADD of a plain file, so expect verdict: FAIL, an issue in github_repository, and a message in Slack.
  3. Fix the heredoc Dockerfile down to a pinned, non-root build (pin the apt packages, swap ADD for COPY, drop MAINTAINER) and re-run, expecting verdict: PASS and the log_clean branch.
  4. Point your CI webhook at /api/v1/{tenant}/executions/webhook/{namespace}/hadolint-dockerfile-policy-gate/{HADOLINT_WEBHOOK_KEY} and POST {"repository": {"full_name": "your-org/container-images"}, "pull_request": {"number": 412}} to watch both inputs flow through into the issue.
  5. Enable nightly_policy_sweep if you also want a nightly rehearsal of the gate against the bundled Dockerfile.

How to extend

  • Replace the heredoc with io.kestra.plugin.git.Clone so the gate lints the real checkout from the pull request branch instead of the bundled fixture.
  • Fan out over every Dockerfile in the repository with io.kestra.plugin.core.flow.Loop, one hadolint run per file, then merge the counts before gate_on_severity.
  • Tighten FALLBACK_LEVEL inside parse_report, or raise fail_on_level to error, so only the worst findings block a merge.
  • Land the findings in a warehouse table with a JDBC query task to trend violations per team, release over release.

Links

See How

New to Kestra?

Use blueprints to kickstart your first workflows.