From 357c3565f6a82582745570a78fd64ede86b709a9 Mon Sep 17 00:00:00 2001 From: 0xawaz Date: Thu, 27 Jun 2024 12:10:38 +0200 Subject: [PATCH 1/3] upgrade erlang 22 to 22.3.4-slim --- Dockerfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Dockerfile b/Dockerfile index 838cea90..552ac49d 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,5 +1,5 @@ # Build stage 0 -FROM erlang:22 +FROM erlang:22.3.4-slim # Install some libs RUN apt-get update -y && apt-get install -y \ From 805232220c52db445b829a93a908794f6e2c2cc0 Mon Sep 17 00:00:00 2001 From: 0xawaz Date: Thu, 27 Jun 2024 12:11:17 +0200 Subject: [PATCH 2/3] cleanup apt packages --- Dockerfile | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/Dockerfile b/Dockerfile index 552ac49d..51119dfc 100644 --- a/Dockerfile +++ b/Dockerfile @@ -2,8 +2,9 @@ FROM erlang:22.3.4-slim # Install some libs -RUN apt-get update -y && apt-get install -y \ - libstdc++6 openssl libtinfo5 +RUN apt-get update && \ + apt-get install --no-install-recommends -y libstdc++6 openssl libtinfo5 && \ + rm -rf /var/lib/apt/lists/* # Set working directory WORKDIR /opt/thepower From 19977fdf0f9f6ea76762c49d64b7337505ac600e Mon Sep 17 00:00:00 2001 From: 0xawaz Date: Fri, 28 Jun 2024 10:26:18 +0200 Subject: [PATCH 3/3] add multistage builds in Dockerfiles --- Dockerfile | 42 +++++++++++++++++++++++++++--------------- 1 file changed, 27 insertions(+), 15 deletions(-) diff --git a/Dockerfile b/Dockerfile index 51119dfc..72a3dad6 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,26 +1,38 @@ -# Build stage 0 -FROM erlang:22.3.4-slim +## +# Build stage +FROM --platform=linux/amd64 ubuntu:22.04 AS build # Install some libs -RUN apt-get update && \ - apt-get install --no-install-recommends -y libstdc++6 openssl libtinfo5 && \ - rm -rf /var/lib/apt/lists/* +RUN apt-get update -yqq && \ + apt-get install -yqq cmake clang libtool gcc git curl libssl-dev \ + build-essential automake autoconf libncurses5-dev elixir iputils-ping \ + erlang-base erlang-public-key erlang-asn1 erlang-ssl erlang-dev erlang-inets \ + erlang-eunit erlang-common-test rebar3 # Set working directory WORKDIR /opt/thepower -RUN mkdir -p /opt/thepower/db - -# Copy Power_node application COPY . . -# Set symlink -RUN ln -s /usr/bin/openssl /usr/local/bin/openssl +# Build binaries +RUN rebar3 compile +RUN rebar3 release +RUN rebar3 tar + +RUN mkdir -p build + +# TODO: Copy only necessary resources for runtime: bin lib releases +RUN cp -r bin build/ -# Expose relevant ports -EXPOSE 49841 -EXPOSE 29841 +## +# Runtime stage: image for tpnode binary +FROM erlang:22.3.4-slim AS runtime + +# Set working directory +WORKDIR /opt/thepower -ENTRYPOINT [ "./bin/thepower" ] +# Copy tpnode binaries and config: bin, lib and releases +COPY --from=build /opt/thepower/build/ . -CMD ["foreground"] \ No newline at end of file +# TODO: confirm the behaviour of the binary to choose the accurate entrypoint +ENTRYPOINT ["./bin/thepower"] \ No newline at end of file