Skip to content

Commit c2098cc

Browse files
Init commit
0 parents  commit c2098cc

File tree

4 files changed

+187
-0
lines changed

4 files changed

+187
-0
lines changed

.travis.yml

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
---
2+
3+
dist: bionic
4+
5+
services:
6+
- docker
7+
8+
stages:
9+
- Static test
10+
- Build test
11+
12+
jobs:
13+
include:
14+
- stage: Static test
15+
env:
16+
- Test: hadolint
17+
language: minimal
18+
script:
19+
- docker run --rm -i hadolint/hadolint < Dockerfile
20+
21+
- stage: Static test
22+
env:
23+
- Test: dockerfile_lint
24+
language: node_js
25+
node_js:
26+
- "8"
27+
script:
28+
- npx --cache .npx dockerfile_lint
29+
cache:
30+
directories:
31+
- .npx
32+
33+
- stage: Build test
34+
language: minimal
35+
before_script:
36+
- LATEST_JSONLINT="$(curl https://registry.npmjs.org/jsonlint -so- | jq -r '.["dist-tags"].latest')"
37+
- export LATEST_JSONLINT
38+
script:
39+
- docker build --build-arg JSONLINT_VERSION="$LATEST_JSONLINT" -t docker-jsonlint:$TRAVIS_COMMIT .
40+
after_success:
41+
- docker run --rm docker-jsonlint:$TRAVIS_COMMIT jsonlint --help

Dockerfile

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
FROM node:12-alpine
2+
3+
ARG JSONLINT_VERSION
4+
ENV npm_config_loglevel=silent
5+
6+
LABEL name="docker-jsonlint"
7+
LABEL maintainer="Peter Dave Hello <hsu@peterdavehello.org>"
8+
9+
LABEL version="$JSONLINT_VERSION"
10+
11+
WORKDIR /json
12+
13+
RUN npm install -g jsonlint@"$JSONLINT_VERSION" && \
14+
rm -rf ~/.npm && \
15+
jsonlint --help

README.md

Lines changed: 124 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,124 @@
1+
# docker-jsonlint
2+
3+
[![Build Status](https://travis-ci.com/PeterDaveHello/docker-jsonlint.svg?branch=master)](https://travis-ci.com/PeterDaveHello/docker-jsonlint)
4+
[![Docker Hub pulls](https://img.shields.io/docker/pulls/peterdavehello/jsonlint.svg)](https://hub.docker.com/r/peterdavehello/jsonlint/)
5+
[![Docker image layers](https://images.microbadger.com/badges/image/peterdavehello/jsonlint.svg)](https://microbadger.com/images/peterdavehello/jsonlint/)
6+
[![Docker image version](https://images.microbadger.com/badges/version/peterdavehello/jsonlint.svg)](https://hub.docker.com/r/peterdavehello/jsonlint/tags/)
7+
8+
[![Docker Hub badge](http://dockeri.co/image/peterdavehello/jsonlint)](https://hub.docker.com/r/peterdavehello/jsonlint/)
9+
10+
Dockerized [jsonlint](https://github.com/zaach/jsonlint) with various versions, easy to use and easy to integrate with CI.
11+
12+
## Table of Contents
13+
14+
- [Usage](#usage)
15+
- [Command line](#command-line)
16+
- [Use latest version](#use-latest-version)
17+
- [Use specific version](#use-specific-version)
18+
- [Continuous Integration (CI)](#continuous-integration-ci)
19+
- [Travis CI](#travis-ci)
20+
- [GitLab CI](#gitlab-ci)
21+
- [jsonlint cli usage](#jsonlint-cli-usage)
22+
- [Build](#build)
23+
24+
## Usage
25+
26+
### Command line
27+
28+
#### Use latest version
29+
30+
```sh
31+
docker run --rm -v $PATH_TO_JSON:/json peterdavehello/jsonlint jsonlint -q JSON_FILE.json
32+
33+
# Please replace "$PATH_TO_JSON" with your custom path,
34+
# and replace "JSON_FILE.json" with your real json file filename.
35+
```
36+
37+
#### Use specific version
38+
39+
Just like above, but you can specify version of jsonlint, for example:
40+
41+
```sh
42+
docker run --rm -v $PATH_TO_JSON:/json peterdavehello/jsonlint:1.6.3 jsonlint -q JSON_FILE.json
43+
44+
# Please replace "1.6.3" with the version number you want.
45+
# Don't forget to replace "$PATH_TO_JSON" & "JSON_FILE.json".
46+
```
47+
48+
### Continuous Integration (CI)
49+
50+
#### Travis CI
51+
52+
Enable Docker service in your `.travis.yml`:
53+
54+
```yaml
55+
services:
56+
- docker
57+
```
58+
59+
And use the same command in the `scripts` part as the command line mentions, for example:
60+
61+
```yaml
62+
services:
63+
- docker
64+
65+
scripts:
66+
- docker run --rm -v $TRAVIS_BUILD_DIR:/json peterdavehello/jsonlint:1.6.3 jsonlint -q example.json
67+
```
68+
69+
This will lint a example json file called `example.json`
70+
71+
#### GitLab CI
72+
73+
Add this block to your `.gitlab-ci.yml`:
74+
75+
```yaml
76+
jsonlint:
77+
stage: lint
78+
variables:
79+
jsonlint_version: "1.6.3"
80+
image: peterdavehello/jsonlint:$jsonlint_version
81+
only:
82+
changes:
83+
- "**/*.json"
84+
script:
85+
- find . -name "*.json" | xargs -n 1 jsonlint -q
86+
```
87+
88+
Replace "1.6.3" with the version you want to use, you can also use "latest" for the very new version.
89+
90+
## jsonlint cli usage
91+
92+
Just pass `-h`/`--help` to jsonlint to get its help message, for example:
93+
94+
```sh
95+
$ docker run --rm peterdavehello/jsonlint jsonlint --help
96+
97+
Usage: jsonlint [file] [options]
98+
99+
file file to parse; otherwise uses stdin
100+
101+
Options:
102+
-v, --version print version and exit
103+
-s, --sort-keys sort object keys
104+
-i, --in-place overwrite the file
105+
-t CHAR, --indent CHAR character(s) to use for indentation [ ]
106+
-c, --compact compact error display
107+
-V, --validate a JSON schema to use for validation
108+
-e, --environment which specification of JSON Schema the validation file uses [json-schema-draft-03]
109+
-q, --quiet do not print the parsed json to STDOUT [false]
110+
```
111+
112+
For more details, check out the [jsonlint project](https://github.com/zaach/jsonlint) page.
113+
114+
## Build
115+
116+
Build command, you need to specify a valid jsonlint version argument to `jsonLINT_VERSION`:
117+
118+
```sh
119+
docker build --build-arg JSONLINT_VERSION="1.6.3" -t docker-jsonlint .
120+
121+
# Replace "docker-jsonlint" with the preferred image name
122+
```
123+
124+
You can find a valid version on [jsonlint](https://www.npmjs.com/package/jsonlint?activeTab=versions) npm registry page, or just poke the [registry](https://registry.npmjs.org/jsonlint) to retrieve more details.

hooks/build

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
#!/bin/sh
2+
3+
if [ "latest" = "$DOCKER_TAG" ]; then
4+
DOCKER_TAG=$(curl https://registry.npmjs.org/jsonlint -sLo- | grep -Po '"latest":"\d+\.\d+\.\d+"' | awk -F'"' '{print $4}')
5+
fi
6+
7+
docker build --build-arg JSONLINT_VERSION="$DOCKER_TAG" -f "$DOCKERFILE_PATH" -t "$IMAGE_NAME" .

0 commit comments

Comments
 (0)