Repository navigation
feat: a docker stack that lints Dockerfiles with hadolint - #66
Merged
Merged
Conversation
A repository's Dockerfile was no stack's business: nothing checked it and nothing kept its base image up to date. The docker stack is detected from a Dockerfile or Containerfile, also with a suffix or named <name>.Dockerfile. Unlike scripts it is kept beside another stack, since no other stack's job reads a Dockerfile. Its CI job calls the new reusable workflow stack-docker.yml, which runs hadolint 2.15.1 on every Dockerfile at the stack's root. Errors and warnings fail the job and information-level rules are printed; a .hadolint.yaml beside the files is used as it is. Dependabot watches the base images, and those of a compose file when there is one. stack_options.docker takes `files`, to name the Dockerfiles, and `build`, to build each image as well without pushing it. The build is off unless asked for: it may need a context, arguments or secrets a lint does not. On GitLab the lint runs in the hadolint image, which Renovate is told to leave alone like the other managed images; `build` is not written there, and repokeeper says so. Detection: a Dockerfile at the root does not make the root the project, so a monorepo with one is still looked into, and the Dockerfile stays a stack at the root. A repository that is only an image keeps its scripts as a stack.
# Conflicts: # .github/workflows/workflow-tests.yml # test/workflows.test.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What
A twelfth stack,
docker: a repository's Dockerfiles are linted in CI and their base images kept up to date.DockerfileorContainerfile, also with a suffix (Dockerfile.dev) or named<name>.Dockerfile. NotDockerfile.dockerignore, and not a compose file alone..hadolint.yamlbeside the files is used as it is. This is the line the script stack draws for PSScriptAnalyzer.dockerecosystem, anddocker-composewhen there is a compose file.stack_options.docker.filesnames the Dockerfiles;build: truealso runsdocker buildon each, with the stack's folder as context, pushing nothing.hadolint/hadolint:v2.15.1-debian, which Renovate is told to leave alone like the other managed images.buildis not written there andchecksays so.Decisions to check
initin a Node.js project with a Dockerfile now writesstacks: [node, docker]. Existing repositories are not touched:updatereads the stacks from.repokeeper.yml.web/,api/and a root Dockerfile is still looked into; the result isstacks: [node, go, docker]with docker at the root. Before this change the root held no stack there, so the folders were found; without this rule the new stack would have hidden them.[script, docker]): there is no project for the scripts to belong to.The standard version does not move: nothing changes for a repository that has no
dockerin its stacks.Tested
test/stacks-docker.test.ts, 10), the reusable workflow and its two jobs inworkflow-tests(test/workflows.test.ts), the GitLab pipeline from the fixture (test/platforms-gitlab-stacks.test.ts). 454 tests in all,typecheck,lint,build,npm run standard.checksums.sha256): the fixture is clean; a file with an information-level finding only exits 0 with--failure-threshold warningand 1 without it; a file with warnings exits 1; a.hadolint.yamlthat fails on errors only is obeyed. The first fixture I wrote failed on DL3066, which is how decision 3 came about.npm pack, the tarball installed in an empty project andinitrun in a new repository withpackage.json,Dockerfile,Dockerfile.dev,compose.yamland a shell script:stacks: [node, docker], theci.ymlabove, and Dependabot entries fornpm,docker,docker-composeandgithub-actions.workflow-testscallsstack-docker.ymlonfixtures/dockertwice, once as the fixture resolves (lint) and once withbuild: "true". See thedockeranddocker-buildchecks of this pull request.Not tested
hadolintwith the same flags that were run locally.docker buildlocally: there is no Docker on this machine. Thedocker-buildcheck of this pull request is that run.With #65
Independent of #64 and #65, but not without overlap with #65. Whichever of the two is merged second has to be brought up to date with
main, for two reasons:.github/workflows/workflow-tests.yml(the list of paths and the end of the file) and oftest/workflows.test.ts(theREUSABLElist and the tests before "cancels superseded"), so git will report conflicts there. Both sides are kept.#65gives every stack a line inCODEQL_LANGUAGES, so the docker stack needsdocker: nullthere (CodeQL has no Dockerfile language).typecheckfails without it, so it cannot be missed.