From 5d489e4797f1b455a96f82486a6243465741f2b4 Mon Sep 17 00:00:00 2001 From: Juan Cruz Viotti Date: Fri, 7 Jun 2024 12:30:02 -0400 Subject: [PATCH] Reduce Dockerfile size as much as possible (#66) Signed-off-by: Juan Cruz Viotti --- Dockerfile | 36 ++++++++++++++---------------------- README.markdown | 13 ++++++++----- 2 files changed, 22 insertions(+), 27 deletions(-) diff --git a/Dockerfile b/Dockerfile index 6412d58c..9b4d1f6d 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,25 +1,17 @@ -FROM ubuntu as compiler +FROM debian:bookworm as builder +RUN apt-get --yes update && apt-get install --yes --no-install-recommends \ + build-essential cmake && apt-get clean && rm -rf /var/lib/apt/lists/* -RUN apt update +COPY cmake /source/cmake +COPY src /source/src +COPY vendor /source/vendor +COPY CMakeLists.txt /source/CMakeLists.txt -# Install tzdata without being interactive -RUN ln -fs /usr/share/zoneinfo/America/New_York /etc/localtime -RUN DEBIAN_FRONTEND=noninteractive apt-get install -y --no-install-recommends tzdata +RUN cmake -S /source -B ./build -DCMAKE_BUILD_TYPE:STRING=Release -DBUILD_SHARED_LIBS:BOOL=OFF +RUN cmake --build /build --config Release --parallel 4 +RUN cmake --install /build --prefix /usr/local --config Release --verbose --component intelligence_jsonschema -# Tools to compile: -RUN apt install -y build-essential cmake - -COPY cmake /compile/cmake -COPY src /compile/src -COPY vendor /compile/vendor -COPY CMakeLists.txt /compile/CMakeLists.txt -WORKDIR /compile - -RUN cmake -S . -B ./build -DCMAKE_BUILD_TYPE:STRING=Release -DBUILD_SHARED_LIBS:BOOL=OFF -RUN cmake --build ./build --config Release --parallel 4 -RUN cmake --install ./build --prefix /usr/local --config Release --verbose --component intelligence_jsonschema - -FROM ubuntu -COPY --from=compiler /usr/local/bin/jsonschema /usr/local/bin/jsonschema -WORKDIR /schema -ENTRYPOINT ["/usr/local/bin/jsonschema"] +FROM debian:bookworm-slim +COPY --from=builder /usr/local/bin/jsonschema /usr/local/bin/jsonschema +WORKDIR /workspace +ENTRYPOINT [ "/usr/local/bin/jsonschema" ] diff --git a/README.markdown b/README.markdown index 54039f7a..78c53ee9 100644 --- a/README.markdown +++ b/README.markdown @@ -74,18 +74,21 @@ latest pre-built binaries, which you can run as follows: ### From Dockerfile -You can compile the software inside a container and run it with Docker: +You can compile the JSON Schema CLI inside a container and run it with Docker +as follows: ```sh docker build -t jsonschema . ``` -Then you can validate files by mounting them in the `/schema` folder: +Then, you run the JSON Schema CLI by mounting the desired directory as +`/workspace` as follows: ```sh -docker run -it -v "$PWD:/schema" jsonschema lint --verbose myschema.json -# Optionally add to your .alias (or similar) file: -# alias jsonschema="docker run -it -v \"$PWD:/schema\" jsonschema" +docker run -it -v "$PWD:/workspace" jsonschema lint --verbose myschema.json + +# You can optionally add this to your .alias (or similar) file: +# alias jsonschema="docker run -it -v \"$PWD:/workspace\" jsonschema" ``` ### Building from source