Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

docs: add github workflow and docker examples #59

Merged
merged 6 commits into from
Jul 31, 2023
Merged
Show file tree
Hide file tree
Changes from 3 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
14 changes: 14 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
# build stage
eyarz marked this conversation as resolved.
Show resolved Hide resolved
FROM golang:1.20-alpine AS builder

# install kubectl-validate
RUN go install sigs.k8s.io/kubectl-validate@latest

# final stage (SIZE 98MB)
FROM scratch

# copy the binary from the builder stage
COPY --from=builder /go/bin/kubectl-validate /kubectl-validate

# set the entrypoint
ENTRYPOINT ["/kubectl-validate"]
eyarz marked this conversation as resolved.
Show resolved Hide resolved
49 changes: 48 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,54 @@ Example output:

# Usage in CI Systems

> 🚧 COMING SOON 🚧
> 🚧 COMING SOON: native docker image & GitHub action 🚧

## GitHub Actions workflows

Here is an example of a simaple GitHub Actions workflow that uses `kubectl-validate` to validate Kubernetes manifests.
This workflow will run on every pull request to the `main` branch and will fail if any of the manifests in the dir `k8s-manifest/` are invalid.

```yaml
name: kubectl-validate
on:
pull_request:
branches:
- main

jobs:
k8sManifestsValidation:
runs-on: ubuntu-latest
steps:
- name: Checkout repo content
uses: actions/checkout@v3

- name: Setup go
uses: actions/setup-go@v4
with:
go-version: '1.20'
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this is inferred from go.mod if missing, we could get rid of this. just FYI.


- name: Install kubectl-validate
run: go install sigs.k8s.io/kubectl-validate@latest

- name: Run kubectl-validate
run: kubectl-validate ./k8s-manifest/ --version 1.23 | grep OK
eyarz marked this conversation as resolved.
Show resolved Hide resolved
```

## Docker

This project doesn't have a native docker image (yet), but you can use the following Dockerfile to build one.
eyarz marked this conversation as resolved.
Show resolved Hide resolved

First, you will need to build it from the Dockerfile:

```sh
docker build -t kubectl-validate .
```

And then you can run it and mount the directory (`k8s-manifest`) with your manifests:

```sh
docker run --volume k8s-manifest:/usr/local/k8s-manifest -it kubectl-validate --version 1.23 /usr/local/k8s-manifest/*.yaml
eyarz marked this conversation as resolved.
Show resolved Hide resolved
```

## Community, discussion, contribution, and support

Expand Down