Skip to content

Commit 7de56e8

Browse files
committed
some initial Readme
Signed-off-by: Khash Sajadi <[email protected]>
1 parent bfff135 commit 7de56e8

File tree

1 file changed

+49
-0
lines changed

1 file changed

+49
-0
lines changed

README.md

+49
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
# Copper
2+
3+
Copper is a simple tool for validate your configuration files. This is specifically useful with Kubernetes configuration files to enforce best practices, apply policies and compliance requirements.
4+
5+
NOTE: This is Copper v2.0 which is a rewrite of Copper v1.0 (and not an in-place upgrade). Copper v2.0 uses Javascript as it's scripting language instead of Copper v1.0's custom DSL. At the moment, we don't offer any upgrades for old Copper v1 scripts to Copper v2.
6+
7+
## Installation
8+
9+
Head to the releases section of this repository and download the latest version of Copper. You can update Copper using `copper update` command at any time. By default, you will be running the `stable` releases. To change the channel, you can use the `--channel` argument in `copper update`.
10+
11+
## Usage
12+
13+
```bash
14+
copper validate --in samples/sample.yml --validator samples/no_latest.js
15+
```
16+
17+
This will run `no_latest.js` script to validate `sample.yml` (both available in this repository).
18+
19+
Copper supports YAML configuration files. By default, it loads the entire input YAML file into the `$$` variable that's available to your scripts. Each section of your YAML file is one item in the `$$` array.
20+
21+
Here is an example on how to stop using `latest` as the image tag.
22+
23+
```javascript
24+
$$.forEach(function($){
25+
if ($.kind === 'Deployment') {
26+
$.spec.template.spec.containers.forEach(function(container) {
27+
var image = new DockerImage(container.image);
28+
if (image.tag === 'latest') {
29+
errors.add_error('no_latest',"latest is used in " + $.metadata.name, 1)
30+
}
31+
});
32+
}
33+
});
34+
```
35+
36+
As you can see, for each section in the YAML, we check if the item is a `Deployment`, if it is use one of Copper's internal helper classes `DocerkImage` to load the image name and parse it. `DockerImage` understands the intricacies of Docker image names (default tag names, default repos, etc). If the tag is `latest` we push an error into the `errors` list.
37+
38+
Once our script has run, Copper will check `errors` for any errors.
39+
40+
Each validation error should have 3 attributes:
41+
`check_name`: The name of the check we just performed
42+
`title`: Some explanation about this error
43+
`severity`: A numerical representation of the severity of this error.
44+
45+
You can set the maximum allowed severity when running Copper using the `--threshold` argument.
46+
47+
### Helpers
48+
49+
To see what helpers are available for you to use in your scripts, see the files in the `libjs` folder in the repository. All these files are loaded before your script is run and therefore are available to use within your scripts.

0 commit comments

Comments
 (0)