From 97b85e1f6931423860b53a45df23e47336eea565 Mon Sep 17 00:00:00 2001 From: ikraduya Date: Sun, 3 Mar 2024 11:22:10 +0700 Subject: [PATCH 1/2] Add an example of alpine image --- examples/example-docker/alpine.Dockerfile | 39 +++++++++++++++++++++++ 1 file changed, 39 insertions(+) create mode 100644 examples/example-docker/alpine.Dockerfile diff --git a/examples/example-docker/alpine.Dockerfile b/examples/example-docker/alpine.Dockerfile new file mode 100644 index 000000000..d13c3ac61 --- /dev/null +++ b/examples/example-docker/alpine.Dockerfile @@ -0,0 +1,39 @@ +# Use alpine latest as the base image +FROM alpine:latest + +# Build variables +ARG NITRO_VERSION=0.3.14 + +# Create build directory +WORKDIR /work + +# Install build dependencies +RUN apk add --no-cache git cmake build-base util-linux-dev zlib-dev + +# Clone code +RUN git clone --recurse-submodules -j2 --depth 1 --branch v${NITRO_VERSION} --single-branch https://github.com/janhq/nitro.git + +# Build +RUN cd nitro && \ + cmake -S nitro_deps/ -B ./build_deps/nitro_deps && \ + cmake --build ./build_deps/nitro_deps/ --config Release && \ + mkdir build && \ + cd build && \ + cmake .. && \ + make -j $(nproc) + +# Install +WORKDIR /app +RUN cp /work/nitro/build/nitro /app/nitro && \ + chmod +x /app/nitro + +# Cleanup +RUN apk del git cmake util-linux-dev zlib-dev && \ + rm -rf /work + +# Expose port +EXPOSE 3928 + +# Set the command to run nitro +ENTRYPOINT [ "/app/nitro" ] +CMD [ "1", "0.0.0.0", "3928" ] From 06b0c5bcdc926d2b1ed4a073df95b0fb6d9fa6a8 Mon Sep 17 00:00:00 2001 From: ikraduya Date: Sun, 3 Mar 2024 12:10:18 +0700 Subject: [PATCH 2/2] Modify dockerfile example for alpine to reduce image size --- examples/example-docker/alpine.Dockerfile | 22 +++++++++++++--------- 1 file changed, 13 insertions(+), 9 deletions(-) diff --git a/examples/example-docker/alpine.Dockerfile b/examples/example-docker/alpine.Dockerfile index d13c3ac61..b80d87009 100644 --- a/examples/example-docker/alpine.Dockerfile +++ b/examples/example-docker/alpine.Dockerfile @@ -1,5 +1,5 @@ # Use alpine latest as the base image -FROM alpine:latest +FROM alpine:latest as builder # Build variables ARG NITRO_VERSION=0.3.14 @@ -8,7 +8,7 @@ ARG NITRO_VERSION=0.3.14 WORKDIR /work # Install build dependencies -RUN apk add --no-cache git cmake build-base util-linux-dev zlib-dev +RUN apk add --no-cache git cmake g++ make util-linux-dev zlib-dev # Clone code RUN git clone --recurse-submodules -j2 --depth 1 --branch v${NITRO_VERSION} --single-branch https://github.com/janhq/nitro.git @@ -20,16 +20,20 @@ RUN cd nitro && \ mkdir build && \ cd build && \ cmake .. && \ - make -j $(nproc) + make -j $(nproc) && \ + chmod +x ./nitro + +# Create the final image +FROM alpine:latest + +# Install runtime dependencies from stripped down g++ and util-linux-dev (without dev packages) +RUN apk add --no-cache libstdc++ gmp isl25 mpc1 mpfr4 zlib libuuid -# Install +# Create working directory WORKDIR /app -RUN cp /work/nitro/build/nitro /app/nitro && \ - chmod +x /app/nitro -# Cleanup -RUN apk del git cmake util-linux-dev zlib-dev && \ - rm -rf /work +# Copy the binary from the builder image +COPY --from=builder /work/nitro/build/nitro /app/nitro # Expose port EXPOSE 3928