From 5a3cddb9d160addf2544f0e4cd2c1f26029616f6 Mon Sep 17 00:00:00 2001 From: Neil Carpenter Date: Wed, 2 Dec 2020 14:42:20 -0500 Subject: [PATCH] Initial commit --- .github/actions/action.yml | 35 ++++++++++++++++++++++++ README.md | 26 +++++++++++++++++- sample/.github/workflows/kube-linter.yml | 20 ++++++++++++++ sample/yaml/deploy.yaml | 21 ++++++++++++++ 4 files changed, 101 insertions(+), 1 deletion(-) create mode 100755 .github/actions/action.yml mode change 100644 => 100755 README.md create mode 100755 sample/.github/workflows/kube-linter.yml create mode 100755 sample/yaml/deploy.yaml diff --git a/.github/actions/action.yml b/.github/actions/action.yml new file mode 100755 index 0000000..fc0212a --- /dev/null +++ b/.github/actions/action.yml @@ -0,0 +1,35 @@ +name: 'kube-linter' +description: 'Scan directory with kube-linter' +inputs: + directory: + description: 'Directory to scan ' + required: true + config: + description: 'Path to config file' + required: false +outputs: + lint-txt: + description: 'Output from linting' + value: ${{ steps.lint.outputs.lint-txt }} +runs: + using: "composite" + steps: + - name: Download latest kube-linter + run: | + LOCATION=$(curl -s https://api.github.com/repos/stackrox/kube-linter/releases/latest \ + | grep "tag_name" \ + | awk '{print "https://github.com/stackrox/kube-linter/releases/download/" substr($2, 2, length($2)-3) "/kube-linter-linux.tar.gz"}') + curl -s -L -o kube-linter-linux.tar.gz $LOCATION + tar -xf kube-linter-linux.tar.gz -C "${GITHUB_WORKSPACE}/" + shell: bash + - id: lint + run: | + cd "${GITHUB_WORKSPACE}" + if [ -z ${{ inputs.config }} ]; then + export CONFIG="" + else + export CONFIG="--config ${{ inputs.config }}" + fi + ./kube-linter $CONFIG lint ${{ inputs.directory }} + shell: bash + diff --git a/README.md b/README.md old mode 100644 new mode 100755 index c67146e..ee6a9ef --- a/README.md +++ b/README.md @@ -1 +1,25 @@ -# kube-linter-action \ No newline at end of file +# kube-linter-action + +# kube-linter-action GitHub action + +This is a GitHub action for scanning Kubernetes deployment files with [kube-linter](https://github.com/stackrox/kube-linter). This includes both the action itself (.github/actions) and sample GitHub workflow (.github/workflows) and a test YAML. + +Quick deployment: + +1. Create a new GitHub repo. +2. Push all files from the `sample` directory into the repo. +3. The `kube-linter.yml` workflow will run as an action every time there's a new push to this repo. + +The action takes two parameters. + +``` + - name: Scan repo + id: kube-lint-repo + uses: stackrox/kube-linter-action@v0.0.1 + with: + directory: yamls + config: .kube-linter/config.yaml +``` + +* `directory` is mandatory -- this is the directory of deployment files to scan. +* `config` is optional -- this is the path to a [configuration file](https://github.com/stackrox/kube-linter/blob/main/config.yaml.example) if you wish to use a non-default configuration. \ No newline at end of file diff --git a/sample/.github/workflows/kube-linter.yml b/sample/.github/workflows/kube-linter.yml new file mode 100755 index 0000000..060a6f6 --- /dev/null +++ b/sample/.github/workflows/kube-linter.yml @@ -0,0 +1,20 @@ +name: Check Kubernetes YAMLs + +on: + push: + branches: [ main ] + pull_request: + branches: [ main ] + +jobs: + scan: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v2 + - name: Scan repo + id: kube-lint-repo + uses: stackrox/kube-linter-action@v0.0.1 + with: + directory: yamls + config: .kube-linter/config.yaml + diff --git a/sample/yaml/deploy.yaml b/sample/yaml/deploy.yaml new file mode 100755 index 0000000..3649247 --- /dev/null +++ b/sample/yaml/deploy.yaml @@ -0,0 +1,21 @@ +apiVersion: apps/v1 +kind: Deployment +metadata: + name: nginx-deployment + labels: + app: nginx +spec: + replicas: 3 + selector: + matchLabels: + app: nginx + template: + metadata: + labels: + app: nginx + spec: + containers: + - name: nginx + image: nginx:1.14.2 + ports: + - containerPort: 80 \ No newline at end of file