# CI/CD Integration

How to run LayerLint in your pipeline.

## GitHub Actions

Basic (composite action — checksum-verified binary install):
```yaml
name: Lint
on: [push, pull_request]

jobs:
  lint:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v4
      - uses: vviveksharma/layerLint@main
        with:
          dockerfile: ./Dockerfile
          fail-on-severity: high
```

Scan every Dockerfile in the repo:
```yaml
- uses: vviveksharma/layerLint@main
  with:
    scan-all: true
    fail-on-severity: high
```

Manual install (both `layerLint_*` and `layerlint_*` asset names are supported):
```yaml
- name: Install LayerLint
  run: |
    set -euo pipefail
    REPO=vviveksharma/layerLint
    TAG=$(curl -fsSL "https://api.github.com/repos/${REPO}/releases/latest" | sed -n 's/.*"tag_name"[[:space:]]*:[[:space:]]*"\([^"]*\)".*/\1/p' | head -n 1)
    VERSION="${TAG#v}"
    BASE="https://github.com/${REPO}/releases/download/${TAG}"
    curl -fsSL "${BASE}/checksums.txt" -o checksums.txt
    # GitHub URLs are case-sensitive: use the exact name listed in checksums.txt.
    ASSET=$(awk -v want="layerlint_${VERSION}_linux_x86_64.tar.gz" 'tolower($2) == want { print $2; exit }' checksums.txt)
    if [ -z "$ASSET" ]; then
      echo "No Linux x86_64 archive found in checksums.txt" >&2
      exit 1
    fi
    curl -fsSL "${BASE}/${ASSET}" | tar xz
    sudo mv layerlint /usr/local/bin/
```

Multiple Dockerfiles:
```yaml
jobs:
  lint:
    runs-on: ubuntu-latest
    strategy:
      matrix:
        dockerfile: [Dockerfile, Dockerfile.prod, services/api/Dockerfile]
    steps:
      - uses: actions/checkout@v4
      - uses: vviveksharma/layerLint@main
        with:
          dockerfile: ${{ matrix.dockerfile }}
```

## GitLab CI

```yaml
lint:dockerfile:
  image: alpine:latest
  before_script:
    - apk add --no-cache curl
    - curl -sSL https://raw.githubusercontent.com/vviveksharma/layerLint/main/install.sh | sh
  script:
    - layerlint scan --dockerfile Dockerfile
  only:
    - merge_requests
    - main
```

## CircleCI

```yaml
version: 2.1
jobs:
  lint:
    docker:
      - image: cimg/base:stable
    steps:
      - checkout
      - run:
          name: Install LayerLint
          command: curl -sSL https://raw.githubusercontent.com/vviveksharma/layerLint/main/install.sh | sh
      - run:
          name: Lint Dockerfile
          command: layerlint scan --dockerfile Dockerfile

workflows:
  build:
    jobs:
      - lint
```

## Jenkins

```groovy
pipeline {
    agent any
    stages {
        stage('Lint') {
            steps:
                sh 'curl -sSL https://raw.githubusercontent.com/vviveksharma/layerLint/main/install.sh | sh'
                sh 'layerlint scan --dockerfile Dockerfile'
            }
        }
    }
}
```

## Azure Pipelines

```yaml
trigger:
  - main

pool:
  vmImage: ubuntu-latest

steps:
  - script: |
      curl -sSL https://raw.githubusercontent.com/vviveksharma/layerLint/main/install.sh | sh
      layerlint scan --dockerfile Dockerfile
    displayName: 'Lint Dockerfile'
```

## Travis CI

```yaml
language: minimal

before_install:
  - curl -sSL https://raw.githubusercontent.com/vviveksharma/layerLint/main/install.sh | sh

script:
  - layerlint scan --dockerfile Dockerfile
```

## Bitbucket Pipelines

```yaml
pipelines:
  default:
    - step:
        name: Lint Dockerfile
        script:
          - curl -sSL https://raw.githubusercontent.com/vviveksharma/layerLint/main/install.sh | sh
          - layerlint scan --dockerfile Dockerfile
```

## Exit Codes

| Code | Meaning |
|------|---------|
| 0 | Clean (no findings at/above `--fail-on-severity`) |
| 1 | Findings at/above threshold |
| 2 | Usage, parse, or runtime error |

## Fail on High Severity

Most platforms — just check the exit code.

For more control, use JSON output and parse it:

```bash
layerlint scan --dockerfile Dockerfile --format json --output report.json
# Parse report.json and fail based on severity
```

## Pre-commit Hook

```yaml
# .pre-commit-config.yaml
repos:
  - repo: https://github.com/vviveksharma/layerLint
    rev: v1.0.1   # pin a release tag
    hooks:
      - id: layerlint
```

## Caching

Most CI systems cache between runs. Cache the LayerLint binary:

**GitHub Actions**:
```yaml
- uses: actions/cache@v3
  with:
    path: ~/.local/bin/layerlint
    key: layerlint-${{ runner.os }}
```

**GitLab CI**:
```yaml
cache:
  paths:
    - layerlint
```

Saves a few seconds per run.
