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

jsonc docker image on docker hub? #4

Closed
wwuck opened this issue Sep 17, 2020 · 13 comments · May be fixed by #6
Closed

jsonc docker image on docker hub? #4

wwuck opened this issue Sep 17, 2020 · 13 comments · May be fixed by #6

Comments

@wwuck
Copy link

wwuck commented Sep 17, 2020

It would be nice to have a jsonc image on docker hub that could be easily used in CI environments, to easily convert jsonc to regular json.

There is a PR for jq that should provide an example of how to implement.

It looks like from reading that PR that you could then enable auto-builds on docker hub that would automatically build a new docker image on hub.docker.com when code is committed to this github repository.

@komkom
Copy link
Owner

komkom commented Feb 7, 2021

I am not sure if I follow. jsonc is just a go module which can be used as a dependency in go projects.

@wwuck
Copy link
Author

wwuck commented Feb 7, 2021

Hmmm I was referring to the jsonc cli program. I would like to be able to use jsonc in a CI (jenkins) environment for purposes of linting json files that contain comments.

@komkom
Copy link
Owner

komkom commented Feb 8, 2021

What would you need from my side to make this work?

@komkom komkom closed this as completed Feb 20, 2021
@wwuck
Copy link
Author

wwuck commented May 14, 2021

@komkom sorry for the late response on this...

I'm not a golang user so I just modified the sample Dockerfile from the official golang docker image. It appears to run fine with the alpine image so I've used that for faster runtime.

# could also use golang:alpine here if specific version is not required
FROM golang:1.16-alpine

# get the latest alpine security updates
RUN apk --no-cache upgrade

WORKDIR /go/src/app
COPY . .

RUN go get -d -v ./...; \
go install -v ./...

# is it possible to change the built executable from `cmd` to `jsonc`?
ENTRYPOINT ["/go/bin/cmd"]

Then you can create an account on docker hub and connect it to your github repository here to enable automatic builds of the docker images each time you push commits to github.
https://betterprogramming.pub/build-your-docker-images-automatically-when-you-push-on-github-18e80ece76af

The only thing missing here is that jsonc doesn't seem to set a different exit code if I input invalid jsonc content? Without something like that it doesn't really make sense to use it in a CI context.

@wwuck
Copy link
Author

wwuck commented May 14, 2021

I should have also mentioned earlier that my use case here is for linting the vscode devcontainer.json file which appears to be just regular json with javascript-style // comments just like jsonc, although I can't seem to find any reference to comments on the file specs.

I would probably be just using docker run -i --rm komkom/jsonc -m < devcontainer.json to convert the jsonc to regular json and then piping that through jq, assuming that a docker image gets uploaded to komkom/jsonc on docker hub.

@komkom
Copy link
Owner

komkom commented May 16, 2021

I guess I found the bug in cmd/main.go. I pushed a commit to master, now you should get a correct error code in the error case.

@wwuck
Copy link
Author

wwuck commented May 17, 2021

Thanks for the quick fix. I can't seem to trigger the error code.

When I run a test on https://komkom.github.io/ with the contents of (including newline):

{{

I get an error of

error line: 2 pos: 1

which seems correct.

However when I install locally I can't trigger any non-zero exit code.

Installed with the latest go version go1.16.4 linux/amd64 following instructions on github readme:

go get github.com/komkom/jsonc/...

and running jsonc with

/tmp/jsonc-test$ alias jsonc=~/go/bin/cmd
/tmp/jsonc-test$ cat test.jsonc 
{{
/tmp/jsonc-test$ jsonc < test.jsonc 
{/tmp/jsonc-test$ echo $?
0

It doesn't exit with a non-zero exit code and seems to just output just the valid part of the jsonc file, ignoring any invalid file contents. Have I missed a step somewhere here?

@komkom
Copy link
Owner

komkom commented May 17, 2021

Ok can you send me the invalid test.jsonc file. Best would be a short version to check?

@wwuck
Copy link
Author

wwuck commented May 17, 2021

I just created the file with

echo "{{" > test.jsonc

@komkom
Copy link
Owner

komkom commented May 17, 2021

Yes you are right error handling was missing for the cli version. I simplified the cmd pkg now. When testing with your file and with a valid file it works now. Can you double check?

wwuck added a commit to wwuck/jsonc that referenced this issue May 18, 2021
@wwuck wwuck mentioned this issue May 18, 2021
@wwuck
Copy link
Author

wwuck commented May 18, 2021

Thanks, I can get the exit code 1 when I run invalid content through jsonc. I've added a Dockerfile in a PR so you can choose whether you would like to enable the Docker Hub auto-build and get a jsonc Docker image up on Docker Hub.

@komkom
Copy link
Owner

komkom commented May 18, 2021

Ok thanks will take a look. But it will probably take a while.

@wwuck
Copy link
Author

wwuck commented May 18, 2021

Thanks. Meanwhile, I have built a docker image locally from the PR Dockerfile and have run a successful test using jsonc in a docker agent with Jenkins to do some basic linting on a json file with comments!

Thanks again for providing a useful tool.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants