Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
62 changes: 62 additions & 0 deletions .github/workflows/docker.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
name: Docker Image

# Builds and publishes a multi-arch container image to GHCR when a version
# tag (v*) is pushed, mirroring the PyPI release trigger in release.yml.
#
# The image is tagged with:
# - the version (e.g. v0.1.0)
# - latest
#
# Usage:
# git tag v0.1.0 && git push origin v0.1.0

on:
push:
tags: ["v*"]
workflow_dispatch:

permissions:
contents: read
packages: write

jobs:
docker:
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v4

- name: Docker meta
id: meta
uses: docker/metadata-action@v5
with:
images: ghcr.io/${{ github.repository }}
tags: |
type=semver,pattern={{raw}}
type=semver,pattern=v{{major}}.{{minor}}
type=raw,value=latest,enable=${{ startsWith(github.ref, 'refs/tags/v') }}

- name: Set up QEMU
uses: docker/setup-qemu-action@v3

- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3

- name: Login to GHCR
uses: docker/login-action@v3
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}

- name: Build and push
uses: docker/build-push-action@v6
with:
context: .
file: ./Dockerfile
platforms: linux/amd64,linux/arm64
push: true
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
cache-from: type=gha
cache-to: type=gha,mode=max
33 changes: 33 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
# syntax=docker/dockerfile:1
#
# Official container image for cachelint.
#
# docker run --rm -v "$PWD":/work ghcr.io/0xabcd01/cachelint Dockerfile
#
# The tool is pure standard-library Python, so a slim base is enough.
FROM python:3.12-slim AS builder

# Build a wheel so the final stage stays small and dependency-free.
COPY src /src/src
COPY pyproject.toml README.md /src/
RUN pip install --no-cache-dir --upgrade build \
&& python -m build --wheel --outdir /dist /src

FROM python:3.12-slim

# Non-root user for CI safety.
RUN groupadd --system --gid 1001 cachelint \
&& useradd --system --uid 1001 --gid cachelint \
--create-home --home-dir /home/cachelint cachelint

# Install the prebuilt wheel from the builder stage.
COPY --from=builder /dist/*.whl /tmp/
RUN pip install --no-cache-dir /tmp/*.whl \
&& rm -f /tmp/*.whl

# Run as the non-root user from now on.
USER cachelint
WORKDIR /work

ENTRYPOINT ["cachelint"]
CMD ["--help"]
23 changes: 23 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
[![CI](https://github.com/0xABCD01/cachelint/actions/workflows/ci.yml/badge.svg)](https://github.com/0xABCD01/cachelint/actions/workflows/ci.yml)
[![Release](https://img.shields.io/github/v/release/0xABCD01/cachelint?label=release)](https://github.com/0xABCD01/cachelint/releases)
[![Python](https://img.shields.io/badge/python-3.8%2B-3776ab)](pyproject.toml)
[![Container](https://ghcr-badge.egpl.dev/0xabcd01/cachelint/tags?label=ghcr)](https://github.com/0xABCD01/cachelint/pkgs/container/cachelint)
[![License: MIT](https://img.shields.io/badge/license-MIT-blue.svg)](LICENSE)
<br>
[![Rules](https://img.shields.io/badge/cache_rules-10-orange.svg)](#-rules)
Expand Down Expand Up @@ -105,6 +106,20 @@ pip install "cachelint @ git+https://github.com/0xABCD01/cachelint.git"

The release workflow publishes to PyPI on a version tag. The first trusted-publisher publish needs a one-time setup on the PyPI project page, so until that lands the install path above is the supported one.

### Container image

A multi-arch (`linux/amd64`, `linux/arm64`) image is published to GHCR on every
release tag:

```bash
docker run --rm -v "$PWD":/work ghcr.io/0xabcd01/cachelint:v0.1.0 Dockerfile
# or pin by digest for locked-down environments:
# ghcr.io/0xabcd01/cachelint@sha256:...
```

The image runs as a non-root user. Mount your checkout at `/work` and pass the
Dockerfile path (relative to `/work`) as the argument.

## 🚀 Usage

```bash
Expand All @@ -129,6 +144,14 @@ Exit codes: `0` clean, `1` findings at or above `--fail-on` (default `high`),
- run: cachelint Dockerfile # fails the job on a HIGH finding
```

Or use the container image directly (no Python install):

```yaml
- uses: docker://ghcr.io/0xabcd01/cachelint:v0.1.0
with:
args: Dockerfile --fail-on high
```

Upload findings to the GitHub Security tab:

```yaml
Expand Down