Skip to content

Commit

Permalink
Reduce Dockerfile size as much as possible
Browse files Browse the repository at this point in the history
Signed-off-by: Juan Cruz Viotti <jv@jviotti.com>
  • Loading branch information
jviotti committed Jun 7, 2024
1 parent bcba28a commit 48242a0
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 27 deletions.
36 changes: 14 additions & 22 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -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" ]
13 changes: 8 additions & 5 deletions README.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 48242a0

Please sign in to comment.