Blacksmoke16 / oq

A performant, and portable jq wrapper to facilitate the consumption and output of formats other than JSON; using jq filters to transform the data.
https://blacksmoke16.github.io/oq/
MIT License
190 stars 15 forks source link

oq does not work in a docker container #39

Closed sundipnair closed 4 years ago

sundipnair commented 4 years ago

I have build a docker container like so

FROM crystallang/crystal:latest

RUN git clone https://github.com/Blacksmoke16/oq.git WORKDIR /oq RUN shards build --production RUN chmod +x /oq/bin/oq RUN cp /oq/bin/oq /bin/

ENV PATH /bin/:$PATH

RUN oq --help


I get an error when running oq --help

Sending build context to Docker daemon 5.632kB Step 1/8 : FROM crystallang/crystal:latest ---> e9906ad8c49f Step 2/8 : RUN git clone https://github.com/Blacksmoke16/oq.git ---> Using cache ---> 9989d5d29ddb Step 3/8 : WORKDIR /oq ---> Using cache ---> 9a3f277c8558 Step 4/8 : RUN shards build --production ---> Using cache ---> 1ed78db07894 Step 5/8 : RUN chmod +x /oq/bin/oq ---> Using cache ---> 0ebaf7c94a18 Step 6/8 : RUN cp /oq/bin/oq /bin/ ---> Using cache ---> e02d9d996fff Step 7/8 : ENV PATH /bin/:$PATH ---> Using cache ---> 6bc2e585cc6e Step 8/8 : RUN oq --help ---> Running in d0822a0f3af4 Failed to raise an exception: END_OF_STACK [0x490bb6] CallStack::print_backtrace:Int32 +118 [0x46d466] __crystal_raise +86 [0x46d98e] ??? [0x4bbab6] Crystal::System::File::open<String, String, File::Permissions>:Int32 +214 [0x4b7ec3] File::new<String, String, File::Permissions, Nil, Nil>:File +67 [0x48785d] CallStack::read_dwarf_sections:(Array(Tuple(UInt64, UInt64, String)) | Nil) +109 [0x4875ed] CallStack::decode_line_number:Tuple(String, Int32, Int32) +45 [0x486d78] CallStack#decode_backtrace:Array(String) +296 [0x486c32] CallStack#printable_backtrace:Array(String) +50 [0x4f049d] Exception+ +77 [0x4f02e8] Exception+ +120 [0x4ec07a] AtExitHandlers::run:Int32 +490 [0x55510b] *Crystal::main<Int32, Pointer(Pointer(UInt8))>:Int32 +139 [0x477e76] main +6 [0x7f0eb572e830] __libc_start_main +240 [0x46ba19] _start +41 [0x0] ??? The command '/bin/sh -c oq --help' returned a non-zero code: 5


Please can you help identify the issue. Thanks.

Blacksmoke16 commented 4 years ago

@sundipnair Is there any reason you're wanting to build the binary from source versus just copying the binary from the latest release into the image?

I'm thinking this is some sort of Crystal issue. I would try just using a prebuilt binary within your image.

FROM crystallang/crystal:latest

RUN apt update && apt install -y jq

COPY ./oq /bin/oq
RUN chmod +x /bin/oq
RUN /bin/oq --help

Seems to work fine, and probably would be the more ideal way. I'll keep this open until the Crystal issue is fixed.

sundipnair commented 4 years ago

thanks for your reply.

so where do you find the ./oq?

I get an error

Step 3/5 : COPY ./oq /bin/oq COPY failed: stat /var/lib/docker/tmp/docker-builder017445899/oq: no such file or directory

Blacksmoke16 commented 4 years ago

Oh sorry. I got it from the latest release assets https://github.com/Blacksmoke16/oq/releases/tag/v0.2.1. Then renamed it from oq-0.2.1-linux-x86_64 to oq.

sundipnair commented 4 years ago

thanks. that builds the image alright.

however running oq gives the following error

cat template.yml | oq -o json -i yaml jq - commandline JSON processor [version 1.5-1-a5b5cbe] Usage: jq [options] [file...]

jq is a tool for processing JSON inputs, applying the
given filter to its JSON text inputs and producing the
filter's results as JSON on standard output.
The simplest filter is ., which is the identity filter,
copying jq's input to its output unmodified (except for
formatting).
For more advanced filters see the jq(1) manpage ("man jq")
and/or https://stedolan.github.io/jq

Some of the options include:
 -c     compact instead of pretty-printed output;
 -n     use `null` as the single input value;
 -e     set the exit status code based on the output;
 -s     read (slurp) all inputs into an array; apply filter to it;
 -r     output raw strings, not JSON texts;
 -R     read raw strings, not JSON texts;
 -C     colorize JSON;
 -M     monochrome (don't colorize JSON);
 -S     sort keys of objects on output;
 --tab  use tabs for indentation;
 --arg a v  set variable $a to value <v>;
 --argjson a v  set variable $a to JSON value <v>;
 --slurpfile a f    set variable $a to an array of JSON texts read from <f>;
See the manpage for more options.
Blacksmoke16 commented 4 years ago

Need to provide the jq filter to use.

Try cat template.yml | oq -i yaml .

Where in this case the . is the filter. The filter can also be in a file using jq's -f filter_file option.

sundipnair commented 4 years ago

Thanks ..

sundipnair commented 4 years ago

@Blacksmoke16 , I have added some instuctions to the read me to craete a docker container. I have pushed a branch called docker_install_instrcution. how do I get this PR'd.

Blacksmoke16 commented 4 years ago

https://github.com/Blacksmoke16/oq#contributing Would be the thing to reference. Should just be able to make it from your fork to this repo.

Blacksmoke16 commented 4 years ago

@sundipnair Actually after thinking about this more; I think it would be better to just actually create an image and have it available to use, versus just documenting how to do that. (Or at least also mention how to include oq into an existing image).

I can take care of this, don't think it 'll be too hard.

sundipnair commented 4 years ago

OK. Thanks.

On Tue, 5 Nov 2019 at 15:59, Blacksmoke16 notifications@github.com wrote:

@sundipnair https://github.com/sundipnair Actually after thinking about this more; I think it would be better to just actually create an image and have it available to use, versus just documenting how to do that. (Or at least also mention how to include oq into an existing image).

I can take care of this, don't think it 'll be too hard.

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/Blacksmoke16/oq/issues/39?email_source=notifications&email_token=AKIRQLYPXQBMS7545UJY2HDQSGJ7RA5CNFSM4JIR2GKKYY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGOEDDGDKY#issuecomment-549872043, or unsubscribe https://github.com/notifications/unsubscribe-auth/AKIRQL4AD3LHFG5ENMCUXGLQSGJ7RANCNFSM4JIR2GKA .

Blacksmoke16 commented 4 years ago

~@sundipnair I pushed an image that includes the static oq from 1.0.0 in an Alpine image. Does that suit your needs?~

I'll also add a section to the readme on using oq within another image.

EDIT: See my latest comment.

sundipnair commented 4 years ago

@Blacksmoke16 , Good one. I was able to build my own image and work with that ...

I will play with your container for some of my personal stuff and see how it goes.

Might be worth adding the docker link on the Readme file.

Blacksmoke16 commented 4 years ago

Actually, @sundipnair what is your use case for needing oq in a docker image versus just downloading the binary onto your OS?

The binary on Github is statically linked so at this point the image isn't doing much more than installing jq and wrapping a binary.

EDIT: Er, I assume you really just want to get oq into an image you're building yourself?

sundipnair commented 4 years ago

@Blacksmoke16 , Just wanted to dynamically edit a yaml as part of a ci/cd step. So needed oq in an image that can be used within the pipeline.

Blacksmoke16 commented 4 years ago

:+1: Perfect, https://github.com/Blacksmoke16/oq#docker should cover how to do that.