Skip to content

Commit d534fc1

Browse files
committed
feat(Docker): Finalize docker usage
1 parent c282963 commit d534fc1

2 files changed

Lines changed: 101 additions & 46 deletions

File tree

Dockerfile

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,11 +16,13 @@ COPY dist/ docker_entrypoint.sh package-lock.json package.json /app
1616
WORKDIR /app
1717

1818
RUN npm install --omit=dev &&\
19-
npm install -g ajv-formats &&\
20-
chown -R 1000:2000 /app
19+
npm install ajv-formats &&\
20+
ln -s /app/index.js /usr/local/bin/ajv-cli && chmod +x /usr/local/bin/ajv-cli &&\
21+
chown -R 1000:2000 /app /usr/local/bin/ajv-cli
2122

2223
# apt update
2324
RUN apt-get update && apt-get -y upgrade &&\
25+
apt-get install -y jq wget curl &&\
2426
# clean up to slim image
2527
apt-get clean autoclean && apt-get autoremove --yes && rm -rf /var/lib/{apt,dpkg,cache,log}/
2628

README.md

Lines changed: 97 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -8,25 +8,78 @@ Supports [JSON](http://json.org/), [JSON5](http://json5.org/), and [YAML](http:/
88
[![coverage](https://coveralls.io/repos/github/ajv-validator/ajv-cli/badge.svg?branch=master)](https://coveralls.io/github/ajv-validator/ajv-cli?branch=master)
99
[![gitter](https://img.shields.io/gitter/room/ajv-validator/ajv.svg)](https://gitter.im/ajv-validator/ajv)
1010

11-
## Contents
12-
13-
- [Installation](#installation)
14-
- [JSON schema version](#json-schema-version)
15-
- Commands
16-
- [Help](#help-command)
17-
- [Validate data](#validate-data)
18-
- [Compile schemas](#compile-schemas)
19-
- [Migrate schemas](#migrate-schemas)
20-
- [Test validation result](#test-validation-result)
21-
- [Ajv options](#ajv-options)
22-
- [Version History, License](#version_history)
11+
- [ajv-cli](#ajv-cli)
12+
- [Installation](#installation)
13+
- [Usage](#usage)
14+
- [JSON schema language and version](#json-schema-language-and-version)
15+
- [Commands](#commands)
16+
- [Help command](#help-command)
17+
- [Validate data](#validate-data)
18+
- [Parameters](#parameters)
19+
- [`-s` - file name of JSON-schema](#-s---file-name-of-json-schema)
20+
- [`-d` - JSON data](#-d---json-data)
21+
- [`-r` - referenced schemas](#-r---referenced-schemas)
22+
- [`-m` - meta-schemas](#-m---meta-schemas)
23+
- [`-c` - custom keywords/formats definitions](#-c---custom-keywordsformats-definitions)
24+
- [Options](#options)
25+
- [Compile schemas](#compile-schemas)
26+
- [Parameters](#parameters-1)
27+
- [`-s` - file name(s) of JSON-schema(s)](#-s---file-names-of-json-schemas)
28+
- [`-o` - output file for compiled validation function module](#-o---output-file-for-compiled-validation-function-module)
29+
- [Migrate schemas](#migrate-schemas)
30+
- [Parameters](#parameters-2)
31+
- [`-s` - file name(s) of JSON-schema(s)](#-s---file-names-of-json-schemas-1)
32+
- [`-o` - output file for migrated schema](#-o---output-file-for-migrated-schema)
33+
- [Options](#options-1)
34+
- [Test validation result](#test-validation-result)
35+
- [Ajv options](#ajv-options)
36+
- [Version History](#version-history)
37+
- [Licence](#licence)
38+
2339

2440
## Installation
2541

2642
```sh
2743
npm install -g ajv-cli
2844
```
2945

46+
## Usage
47+
48+
Installed Tools (available in the docker image):
49+
- ajv-cli
50+
- wget
51+
- curl
52+
53+
54+
For using in pipelines, e.g. gitlab use the following setup for validating the renovate config in your project:
55+
56+
```
57+
variables:
58+
RENOVATE_PRESETS: 'm13t_default.json backend/*.json frontend/*.json infra/*.json'
59+
60+
Validate Config:
61+
stage: test
62+
image:
63+
name: continuoussecuritytooling/ajv-cli:0.1.0
64+
entrypoint: [""]
65+
before_script:
66+
- wget https://docs.renovatebot.com/renovate-schema.json
67+
- ajv-cli migrate -s renovate-schema.json -o renovate-schema.json
68+
rules:
69+
- if: $CI_COMMIT_BRANCH == "main"
70+
when: never
71+
- if: $CI_PIPELINE_SOURCE == 'push'
72+
when: always
73+
script:
74+
- |
75+
for file in $RENOVATE_PRESETS; do
76+
if [ -f "$file" ]; then
77+
echo "Checking $file"
78+
ajv-cli validate --strict=false --validate-formats=true -c ajv-formats -s renovate-schema.json -d $file
79+
fi
80+
done
81+
```
82+
3083
## JSON schema language and version
3184

3285
Parameter `--spec` can be used with all commands (other than help) to choose JSON schema language:
@@ -203,38 +256,38 @@ This command supports the same options and parameters as [validate](#validate-da
203256

204257
You can pass the following [Ajv options](https://ajv.js.org/options.html):
205258

206-
| Option | Description |
207-
| ------ | ----------- |
208-
| Strict mode |
209-
| `--strict=`| `true`/`false`/`log` - set all [strict mode](https://ajv.js.org/strict-mode.html) restrictions |
210-
| `--strict-schema=`| log on (`log`) or ignore (`false`) [strict ](https://ajv.js.org/strict-mode.html#prohibit-ignored-keywords) restrictions (the default is to log) |
211-
| `--strict-tuples=`| throw on (`true`) or ignore (`false`) [strict schema](https://ajv.js.org/strict-mode.html#prohibit-unconstrained-tuples) restrictions (the default is to throw) |
212-
| `--strict-types=`| throw on (`true`) or ignore (`false`) [strict types](https://ajv.js.org/strict-mode.html#strict-types) restrictions (the default is to log) |
213-
| `--strict-required=`| throw on (`true`) or log (`log`) [required properties](https://ajv.js.org/strict-mode.html#defined-required-properties) restrictions (the default is to ignore) |
214-
| `--allow-matching-properties`| allow `properties` [matching patterns](https://ajv.js.org/strict-mode.html#overlap-between-properties-and-patternproperties-keywords) in `patternProperties` |
215-
| `--allow-union-types`| allow [union types](https://ajv.js.org/strict-mode.html#union-types) |
216-
| `--validate-formats=false`| disable format validation |
217-
| Validation and reporting |
218-
| `--data`| use [$data references](https://ajv.js.org/guide/combining-schemas.html#data-reference) |
219-
| `--all-errors`| collect all validation errors |
220-
| `--verbose` | include schema and data in errors |
221-
| `--comment` | log schema `$comment`s |
222-
| `--inline-refs=` | referenced schemas compilation mode (true/false/\<number\>) |
223-
| Modify validated data |
224-
| `--remove-additional` | remove additional properties (true/all/failing) |
225-
| `--use-defaults` | replace missing properties/items with the values from default keyword |
226-
| `--coerce-types` | change type of data to match type keyword |
227-
| Advanced |
228-
| `--multiple-of-precision` | precision of multipleOf, pass integer number |
229-
| `--messages=false` | do not include text messages in errors |
230-
| `--loop-required=` | max size of `required` to compile to expression (rather than to loop) |
231-
| `--loop-enum=` | max size of `enum` to compile to expression (rather than to loop) |
232-
| `--own-properties` | only validate own properties (not relevant for JSON, but can have effect for JavaScript objects) |
233-
| Code generation |
234-
| `--code-es5` | generate ES5 code |
235-
| `--code-lines` | generate multi-line code |
236-
| `--code-optimize=` | disable optimization (`false`) or number of optimization passes (1 pass by default) |
237-
| `--code-formats=` | code to require formats object (only needed if you generate standalone code and do not use [ajv-formats](https://github.com/ajv-validator/ajv-formats)) |
259+
| Option | Description |
260+
| ----------------------------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------- |
261+
| Strict mode |
262+
| `--strict=` | `true`/`false`/`log` - set all [strict mode](https://ajv.js.org/strict-mode.html) restrictions |
263+
| `--strict-schema=` | log on (`log`) or ignore (`false`) [strict ](https://ajv.js.org/strict-mode.html#prohibit-ignored-keywords) restrictions (the default is to log) |
264+
| `--strict-tuples=` | throw on (`true`) or ignore (`false`) [strict schema](https://ajv.js.org/strict-mode.html#prohibit-unconstrained-tuples) restrictions (the default is to throw) |
265+
| `--strict-types=` | throw on (`true`) or ignore (`false`) [strict types](https://ajv.js.org/strict-mode.html#strict-types) restrictions (the default is to log) |
266+
| `--strict-required=` | throw on (`true`) or log (`log`) [required properties](https://ajv.js.org/strict-mode.html#defined-required-properties) restrictions (the default is to ignore) |
267+
| `--allow-matching-properties` | allow `properties` [matching patterns](https://ajv.js.org/strict-mode.html#overlap-between-properties-and-patternproperties-keywords) in `patternProperties` |
268+
| `--allow-union-types` | allow [union types](https://ajv.js.org/strict-mode.html#union-types) |
269+
| `--validate-formats=false` | disable format validation |
270+
| Validation and reporting |
271+
| `--data` | use [$data references](https://ajv.js.org/guide/combining-schemas.html#data-reference) |
272+
| `--all-errors` | collect all validation errors |
273+
| `--verbose` | include schema and data in errors |
274+
| `--comment` | log schema `$comment`s |
275+
| `--inline-refs=` | referenced schemas compilation mode (true/false/\<number\>) |
276+
| Modify validated data |
277+
| `--remove-additional` | remove additional properties (true/all/failing) |
278+
| `--use-defaults` | replace missing properties/items with the values from default keyword |
279+
| `--coerce-types` | change type of data to match type keyword |
280+
| Advanced |
281+
| `--multiple-of-precision` | precision of multipleOf, pass integer number |
282+
| `--messages=false` | do not include text messages in errors |
283+
| `--loop-required=` | max size of `required` to compile to expression (rather than to loop) |
284+
| `--loop-enum=` | max size of `enum` to compile to expression (rather than to loop) |
285+
| `--own-properties` | only validate own properties (not relevant for JSON, but can have effect for JavaScript objects) |
286+
| Code generation |
287+
| `--code-es5` | generate ES5 code |
288+
| `--code-lines` | generate multi-line code |
289+
| `--code-optimize=` | disable optimization (`false`) or number of optimization passes (1 pass by default) |
290+
| `--code-formats=` | code to require formats object (only needed if you generate standalone code and do not use [ajv-formats](https://github.com/ajv-validator/ajv-formats)) |
238291

239292
Options can be passed using either dash-case or camelCase.
240293

0 commit comments

Comments
 (0)