From 0c77515c56fbc01ce31031e74ba5b9bda454f00f Mon Sep 17 00:00:00 2001 From: Bruno Paz Date: Wed, 2 Oct 2019 21:50:00 +0100 Subject: [PATCH] feat: first commit --- .editorconfig | 25 +++++++++++++ .github/workflows/ci.yml | 81 ++++++++++++++++++++++++++++++++++++++++ .hadolint.yml | 5 +++ .pre-commit-config.yaml | 12 ++++++ .yamllint | 8 ++++ Dockerfile | 5 +++ LICENSE | 22 +++++++++++ Makefile | 25 +++++++++++++ README.md | 51 +++++++++++++++++++++++++ action.yml | 15 ++++++++ structure-tests.yaml | 8 ++++ testdata/Dockerfile | 3 ++ 12 files changed, 260 insertions(+) create mode 100644 .editorconfig create mode 100644 .github/workflows/ci.yml create mode 100644 .hadolint.yml create mode 100644 .pre-commit-config.yaml create mode 100644 .yamllint create mode 100644 Dockerfile create mode 100644 LICENSE create mode 100644 Makefile create mode 100644 README.md create mode 100644 action.yml create mode 100644 structure-tests.yaml create mode 100644 testdata/Dockerfile diff --git a/.editorconfig b/.editorconfig new file mode 100644 index 0000000..ed13cc7 --- /dev/null +++ b/.editorconfig @@ -0,0 +1,25 @@ +root = true + +[*] +charset = utf-8 +end_of_line = lf +trim_trailing_whitespace = true +insert_final_newline = true +max_line_length = 80 + +[*.md] +indent_style = space +indent_size = 4 +trim_trailing_whitespace = false + +[Makefile] +indent_style = tab +indent_size = 4 + +[{Dockerfile,Dockerfile.template.erb,Dockerfile.sample}] +indent_style = space +indent_size = 4 + +[*.{yml,yaml}] +indent_style = space +indent_size = 2 diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml new file mode 100644 index 0000000..d459a3b --- /dev/null +++ b/.github/workflows/ci.yml @@ -0,0 +1,81 @@ +name: "CI" +on: + push: + branches: + - master + pull_request: + +env: + TEST_IMAGE_NAME: hadolint-action:${{github.sha}} + +jobs: + lint: + runs-on: ubuntu-latest + container: pipelinecomponents/hadolint:latest + steps: + - uses: actions/checkout@v1 + - name: Run hadolint + run: hadolint Dockerfile + + build: + runs-on: ubuntu-latest + needs: ['lint'] + steps: + - uses: actions/checkout@v1 + - name: Build Docker image + run: docker build -t $TEST_IMAGE_NAME . + + - name: Save Docker image artifact + run: docker save -o action.tar $TEST_IMAGE_NAME + + - name: Upload image artifact + uses: actions/upload-artifact@master + with: + name: action-image + path: action.tar + + test: + name: Unit Tests + runs-on: ubuntu-latest + needs: build + steps: + - uses: actions/checkout@v1 + + - name: Pull Image artifact + uses: actions/download-artifact@master + with: + name: action-image + + - name: Load image into docker context + run: docker load -i action-image/action.tar + + - name: Get Image Name + id: image_name + run: echo "##[set-output name=image;]$(echo $TEST_IMAGE_NAME)" + + - name: Run Structure tests + uses: brpaz/structure-tests-action@master + with: + image: ${{ steps.image_name.outputs.image }} + + integration: + name: Integration Tests + runs-on: ubuntu-latest + needs: test + steps: + - uses: actions/checkout@v1 + - uses: ./ + with: + dockerfile: testdata/Dockerfile + + release: + if: github.event_name == 'push' && github.ref == 'refs/heads/master' + name: Release + runs-on: ubuntu-latest + needs: integraiton + steps: + - uses: actions/checkout@v1 + - name: Semantic Release + uses: brpaz/action-semantic-release@master + env: + GITHUB_TOKEN: ${{secrets.GITHUB_TOKEN}} diff --git a/.hadolint.yml b/.hadolint.yml new file mode 100644 index 0000000..784711c --- /dev/null +++ b/.hadolint.yml @@ -0,0 +1,5 @@ +# Hadolint configuration file + +# configure ignore rules +# see https://github.com/hadolint/hadolint#rules for a list of available rules. +ignored: [] diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml new file mode 100644 index 0000000..1529807 --- /dev/null +++ b/.pre-commit-config.yaml @@ -0,0 +1,12 @@ +- repo: local + hooks: + - id: lint-dockerfile + name: Lint Dockerfile + entry: make lint-dockerfile + language: system + files: \.yml$ + - id: lint-yaml + name: Lint YAML + entry: make lint-yaml + language: system + files: \.yml$ diff --git a/.yamllint b/.yamllint new file mode 100644 index 0000000..39a5255 --- /dev/null +++ b/.yamllint @@ -0,0 +1,8 @@ +extends: default + +rules: + # 80 chars should be enough, but don't fail if a line is longer + line-length: + max: 80 + level: warning + document-start: disable diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..b2439e1 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,5 @@ +FROM hadolint/hadolint:v1.17.2 + +COPY LICENSE README.md / + +CMD ["hadolint"] diff --git a/LICENSE b/LICENSE new file mode 100644 index 0000000..c2c623c --- /dev/null +++ b/LICENSE @@ -0,0 +1,22 @@ + +The MIT License (MIT) + +Copyright (c) Bruno Paz + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in +all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +THE SOFTWARE. diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..32cdadb --- /dev/null +++ b/Makefile @@ -0,0 +1,25 @@ + +IMAGE_NAME:=hadolint-action + +lint-dockerfile: ## Runs hadoint against application dockerfile + @docker run --rm -v "$(PWD):/data" -w "/data" hadolint/hadolint hadolint Dockerfile + +lint-yaml: ## Lints yaml configurations + @docker run --rm -v "$(PWD):/yaml" sdesbure/yamllint yamllint . + +build: ## Builds the docker image + @docker build . -t $(IMAGE_NAME) + +test: build ## Runs a test in the image + @docker run -i --rm \ + -v /var/run/docker.sock:/var/run/docker.sock \ + -v ${PWD}:/test zemanlx/container-structure-test:v1.8.0-alpine \ + test \ + --image $(IMAGE_NAME) \ + --config test/structure-tests.yaml + +help: + @grep -E '(^[a-zA-Z_-]+:.*?##.*$$)|(^##)' $(MAKEFILE_LIST) | awk 'BEGIN {FS = ":.*?## "}; {printf "\033[32m%-30s\033[0m %s\n", $$1, $$2}' | sed -e 's/\[32m##/[33m/' + +.DEFAULT_GOAL := help +.PHONY: lint build test help diff --git a/README.md b/README.md new file mode 100644 index 0000000..6011fb0 --- /dev/null +++ b/README.md @@ -0,0 +1,51 @@ +# hadolint-action Action + +> Action that runs [Hadolint](https://github.com/hadolint/hadolint) Dockerfile linting tool. + +[![GitHub Action](https://img.shields.io/badge/GitHub-Action-blue?style=for-the-badge)](https://github.com/features/actions) +[![License](https://img.shields.io/badge/License-MIT-yellow.svg?style=for-the-badge)](LICENSE) +[![Commitizen friendly](https://img.shields.io/badge/commitizen-friendly-brightgreen.svg?style=for-the-badge)](http://commitizen.github.io/cz-cli/) +[![semantic-release](https://img.shields.io/badge/%20%20%F0%9F%93%A6%F0%9F%9A%80-semantic--release-e10079.svg?style=for-the-badge)](https://github.com/semantic-release/semantic-release?style=for-the-badge) + +[![GitHub Actions](https://github.com/brpaz/hadolint-action/workflows/CI/badge.svg?style=for-the-badge)](https://github.com/brpaz/hadolint-action/actions) + +## Usage + +```yml +steps: + uses: brpaz/hadolint-action@master +``` + +## Inputs + +**`dockerfile`** + +The path to the Dockerfile to be tested. By default it will look for a Dockerfile in the current directory. + +## 🤝 Contributing + +Contributions are what make the open source community such an amazing place to be learn, inspire, and create. Any contributions you make are **greatly appreciated**. + +1. Fork the Project +2. Create your Feature Branch (`git checkout -b feature/AmazingFeature`) +3. Commit your Changes (`git commit -m 'Add some AmazingFeature'`) +4. Push to the Branch (`git push origin feature/AmazingFeature`) +5. Open a Pull Request + +## Useful Resources + +* [Building actions - GitHub Help](https://help.github.com/en/articles/building-actions) +* [actions/toolkit: The GitHub ToolKit for developing GitHub Actions.](https://github.com/actions/toolkit) + +## Author + +👤 **Bruno Paz** + +* Website: [https://github.com/brpaz](https://github.com/brpaz) +* Github: [@brpaz](https://github.com/brpaz) + +## 📝 License + +Copyright © 2019 [Bruno Paz](https://github.com/brpaz). + +This project is [MIT](LICENSE) licensed. diff --git a/action.yml b/action.yml new file mode 100644 index 0000000..37eac64 --- /dev/null +++ b/action.yml @@ -0,0 +1,15 @@ +name: 'Hadolint' +description: 'Action that runs Hadolint Dockerfile linting tool' +author: 'Bruno Paz' +inputs: + dockerfile: + description: 'The path to the Dockerfile to lint' + default: 'Dockerfile' +runs: + using: 'docker' + image: 'Dockerfile' + args: + - ${{ inputs.dockerfile }} +branding: + icon: 'layers' + color: 'purple' diff --git a/structure-tests.yaml b/structure-tests.yaml new file mode 100644 index 0000000..8f79cc6 --- /dev/null +++ b/structure-tests.yaml @@ -0,0 +1,8 @@ +schemaVersion: 2.0.0 + +commandTests: + - name: "Check hadolint is installed" + command: hadolint + args: ['-v'] + expectedOutput: ["Haskell Dockerfile Linter"] + exitCode: 0 diff --git a/testdata/Dockerfile b/testdata/Dockerfile new file mode 100644 index 0000000..fca6156 --- /dev/null +++ b/testdata/Dockerfile @@ -0,0 +1,3 @@ +FROM alpine:3.10 + +RUN echo "Hello"