From f11d59d2d945fae53d7eb6a4c5b4e01dff76b5c2 Mon Sep 17 00:00:00 2001 From: Daniel McCoy Stephenson Date: Mon, 24 Jul 2023 13:24:38 -0600 Subject: [PATCH 1/4] Switched over to using alpine:3.12 for the base image in dockerfiles. --- Dockerfile | 69 ++++++++++++++++++++++++++++---------- Dockerfile.dev | 77 ++++++++++++++++++++++++++++++------------- Dockerfile.standalone | 68 ++++++++++++++++++++++++++++---------- docker_build.sh | 2 +- 4 files changed, 156 insertions(+), 60 deletions(-) diff --git a/Dockerfile b/Dockerfile index 7c6bc806..39fd4ce6 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,27 +1,36 @@ -FROM ubuntu:18.04 +# === BUILDER IMAGE === +FROM alpine:3.12 as builder USER root - WORKDIR /asn1_codec - VOLUME ["/asn1_codec_share"] -# Add build tools. -RUN apt-get update && apt-get install -y software-properties-common wget git make gcc-7 g++-7 gcc-7-base && update-alternatives --install /usr/bin/gcc gcc /usr/bin/gcc-7 100 && update-alternatives --install /usr/bin/g++ g++ /usr/bin/g++-7 100 - -# Install cmake. -RUN apt-get install -y cmake +# update the package manager +RUN apk update -# install libtool and automake -RUN apt-get install -y automake libtool +# add build dependencies +RUN apk add --upgrade --no-cache --virtual .build-deps \ + build-base \ + cmake \ + git \ + wget \ + gcc \ + g++ \ + linux-headers \ + make \ + musl-dev \ + openssl-dev \ + protobuf-dev \ + protobuf-c-dev \ + sudo \ + bash \ + automake \ + libtool \ + autoconf -# Install librdkafka. -RUN apt-get install -y sudo -RUN wget -qO - https://packages.confluent.io/deb/7.3/archive.key | sudo apt-key add - -RUN add-apt-repository "deb [arch=amd64] https://packages.confluent.io/deb/7.3 stable main" -RUN add-apt-repository "deb https://packages.confluent.io/clients/deb $(lsb_release -cs) main" -RUN apt update -RUN apt-get install -y libsasl2-modules libsasl2-modules-gssapi-mit libsasl2-dev libssl-dev -RUN apt install -y librdkafka-dev +# add librdkafka from edge branch +RUN sed -i -e 's/v3\.4/edge/g' /etc/apk/repositories \ + && apk upgrade --update-cache --available \ + && apk add --no-cache librdkafka librdkafka-dev # Install pugixml ADD ./pugixml /asn1_codec/pugixml @@ -45,6 +54,7 @@ ADD ./src /asn1_codec/src ADD ./kafka-test /asn1_codec/kafka-test ADD ./unit-test-data /asn1_codec/unit-test-data ADD ./run_acm.sh /asn1_codec +ADD ./data /asn1_codec/data RUN echo "export LD_LIBRARY_PATH=/usr/local/lib" >> ~/.profile RUN echo "export LD_LIBRARY_PATH=/usr/local/lib" >> ~/.bashrc @@ -54,6 +64,29 @@ RUN echo "export CC=gcc" >> ~/.bashrc # Build acm. RUN mkdir -p /build && cd /build && cmake /asn1_codec && make +# === RUNTIME IMAGE === +FROM alpine:3.12 +USER root +WORKDIR /asn1_codec +VOLUME ["/asn1_codec_share"] + +# add runtime dependencies +RUN apk add --upgrade --no-cache \ + bash \ + libstdc++ \ + libgcc \ + libprotobuf \ + protobuf + +# add librdkafka from edge branch +RUN sed -i -e 's/v3\.4/edge/g' /etc/apk/repositories \ + && apk upgrade --update-cache --available \ + && apk add --no-cache librdkafka librdkafka-dev + +# copy the built files from the builder +COPY --from=builder /asn1_codec /asn1_codec +COPY --from=builder /build /build + # Add test data. This changes frequently so keep it low in the file. ADD ./docker-test /asn1_codec/docker-test diff --git a/Dockerfile.dev b/Dockerfile.dev index f532ec0f..2d8f6a6f 100644 --- a/Dockerfile.dev +++ b/Dockerfile.dev @@ -1,32 +1,36 @@ -FROM ubuntu:18.04 +# === BUILDER IMAGE === +FROM alpine:3.12 as builder USER root - WORKDIR /asn1_codec - VOLUME ["/asn1_codec_share"] -# Add build tools. -RUN apt-get update && apt-get install -y software-properties-common wget git make gcc-7 g++-7 gcc-7-base && update-alternatives --install /usr/bin/gcc gcc /usr/bin/gcc-7 100 && update-alternatives --install /usr/bin/g++ g++ /usr/bin/g++-7 100 - -#install editors vim and nano -RUN apt-get update && apt-get install -y vim -RUN apt-get update && apt-get install -y nano +# update the package manager +RUN apk update -# Install cmake. -RUN wget https://cmake.org/files/v3.7/cmake-3.7.2.tar.gz && tar -xvf cmake-3.7.2.tar.gz -RUN cd cmake-3.7.2 && ./bootstrap && make && make install && cd /home +# add build dependencies +RUN apk add --upgrade --no-cache --virtual .build-deps \ + build-base \ + cmake \ + git \ + wget \ + gcc \ + g++ \ + linux-headers \ + make \ + musl-dev \ + openssl-dev \ + protobuf-dev \ + protobuf-c-dev \ + sudo \ + bash \ + automake \ + libtool \ + autoconf -# install libtool and automake -RUN apt-get update && apt-get install -y automake libtool - -# Install librdkafka. -RUN apt-get install -y sudo -RUN wget -qO - https://packages.confluent.io/deb/7.3/archive.key | sudo apt-key add - -RUN add-apt-repository "deb [arch=amd64] https://packages.confluent.io/deb/7.3 stable main" -RUN add-apt-repository "deb https://packages.confluent.io/clients/deb $(lsb_release -cs) main" -RUN apt update -RUN apt-get install -y libsasl2-modules libsasl2-modules-gssapi-mit libsasl2-dev libssl-dev -RUN apt install -y librdkafka-dev +# add librdkafka from edge branch +RUN sed -i -e 's/v3\.4/edge/g' /etc/apk/repositories \ + && apk upgrade --update-cache --available \ + && apk add --no-cache librdkafka librdkafka-dev # Install pugixml ADD ./pugixml /asn1_codec/pugixml @@ -50,6 +54,7 @@ ADD ./src /asn1_codec/src ADD ./kafka-test /asn1_codec/kafka-test ADD ./unit-test-data /asn1_codec/unit-test-data ADD ./run_acm.sh /asn1_codec +ADD ./data /asn1_codec/data RUN echo "export LD_LIBRARY_PATH=/usr/local/lib" >> ~/.profile RUN echo "export LD_LIBRARY_PATH=/usr/local/lib" >> ~/.bashrc @@ -59,6 +64,32 @@ RUN echo "export CC=gcc" >> ~/.bashrc # Build acm. RUN mkdir -p /build && cd /build && cmake /asn1_codec && make +# === RUNTIME IMAGE === +FROM alpine:3.12 +USER root +WORKDIR /asn1_codec +VOLUME ["/asn1_codec_share"] + +# add runtime dependencies +RUN apk add --upgrade --no-cache \ + bash \ + libstdc++ \ + libgcc \ + libprotobuf \ + protobuf + +# add librdkafka from edge branch +RUN sed -i -e 's/v3\.4/edge/g' /etc/apk/repositories \ + && apk upgrade --update-cache --available \ + && apk add --no-cache librdkafka + +# install editors vim and nano +RUN apk update && apk add vim nano + +# copy the built files from the builder +COPY --from=builder /asn1_codec /asn1_codec +COPY --from=builder /build /build + # Add test data. This changes frequently so keep it low in the file. ADD ./docker-test /asn1_codec/docker-test diff --git a/Dockerfile.standalone b/Dockerfile.standalone index ab4f2b1f..9f7ffbaf 100644 --- a/Dockerfile.standalone +++ b/Dockerfile.standalone @@ -1,26 +1,35 @@ -FROM ubuntu:18.04 +# === BUILDER IMAGE === +FROM alpine:3.12 as builder USER root - WORKDIR /asn1_codec -# Add build tools. -RUN apt-get update && apt-get install -y software-properties-common wget git make gcc-7 g++-7 gcc-7-base && update-alternatives --install /usr/bin/gcc gcc /usr/bin/gcc-7 100 && update-alternatives --install /usr/bin/g++ g++ /usr/bin/g++-7 100 - -# Install cmake. -RUN wget https://cmake.org/files/v3.7/cmake-3.7.2.tar.gz && tar -xvf cmake-3.7.2.tar.gz -RUN cd cmake-3.7.2 && ./bootstrap && make && make install && cd /home +# update the package manager +RUN apk update -# install libtool and automake -RUN apt-get update && apt-get install -y automake libtool +# add build dependencies +RUN apk add --upgrade --no-cache --virtual .build-deps \ + build-base \ + cmake \ + git \ + wget \ + gcc \ + g++ \ + linux-headers \ + make \ + musl-dev \ + openssl-dev \ + protobuf-dev \ + protobuf-c-dev \ + sudo \ + bash \ + automake \ + libtool \ + autoconf -# Install librdkafka. -RUN apt-get install -y sudo -RUN wget -qO - https://packages.confluent.io/deb/7.3/archive.key | sudo apt-key add - -RUN add-apt-repository "deb [arch=amd64] https://packages.confluent.io/deb/7.3 stable main" -RUN add-apt-repository "deb https://packages.confluent.io/clients/deb $(lsb_release -cs) main" -RUN apt update -RUN apt-get install -y libsasl2-modules libsasl2-modules-gssapi-mit libsasl2-dev libssl-dev -RUN apt install -y librdkafka-dev +# add librdkafka from edge branch +RUN sed -i -e 's/v3\.4/edge/g' /etc/apk/repositories \ + && apk upgrade --update-cache --available \ + && apk add --no-cache librdkafka librdkafka-dev # Install pugixml ADD ./pugixml /asn1_codec/pugixml @@ -44,9 +53,32 @@ ADD ./src /asn1_codec/src ADD ./kafka-test /asn1_codec/kafka-test ADD ./unit-test-data /asn1_codec/unit-test-data ADD ./run_acm.sh /asn1_codec +ADD ./data /asn1_codec/data # Build acm. RUN mkdir -p /build && cd /build && cmake /asn1_codec && make +# === RUNTIME IMAGE === +FROM alpine:3.12 +USER root +WORKDIR /asn1_codec + +# add runtime dependencies +RUN apk add --upgrade --no-cache \ + bash \ + libstdc++ \ + libgcc \ + libprotobuf \ + protobuf + +# add librdkafka from edge branch +RUN sed -i -e 's/v3\.4/edge/g' /etc/apk/repositories \ + && apk upgrade --update-cache --available \ + && apk add --no-cache librdkafka librdkafka-dev + +# copy the built files from the builder +COPY --from=builder /asn1_codec /asn1_codec +COPY --from=builder /build /build + # Add test data. This changes frequently so keep it low in the file. ADD ./docker-test /asn1_codec/docker-test diff --git a/docker_build.sh b/docker_build.sh index ab5c35f1..4bac1585 100644 --- a/docker_build.sh +++ b/docker_build.sh @@ -1,2 +1,2 @@ -#!/bin/sh +#!/bin/sh docker build -t asn1_codec:latest . \ No newline at end of file From d2928bb015feea5f0bd243ea7f88504e6dfcf7fb Mon Sep 17 00:00:00 2001 From: Daniel McCoy Stephenson Date: Tue, 25 Jul 2023 11:19:00 -0600 Subject: [PATCH 2/4] Removing unnecessary packages --- Dockerfile | 16 +--------------- Dockerfile.dev | 16 +--------------- Dockerfile.standalone | 16 +--------------- 3 files changed, 3 insertions(+), 45 deletions(-) diff --git a/Dockerfile b/Dockerfile index 39fd4ce6..737ae41f 100644 --- a/Dockerfile +++ b/Dockerfile @@ -9,19 +9,9 @@ RUN apk update # add build dependencies RUN apk add --upgrade --no-cache --virtual .build-deps \ - build-base \ cmake \ - git \ - wget \ - gcc \ g++ \ - linux-headers \ make \ - musl-dev \ - openssl-dev \ - protobuf-dev \ - protobuf-c-dev \ - sudo \ bash \ automake \ libtool \ @@ -72,11 +62,7 @@ VOLUME ["/asn1_codec_share"] # add runtime dependencies RUN apk add --upgrade --no-cache \ - bash \ - libstdc++ \ - libgcc \ - libprotobuf \ - protobuf + bash # add librdkafka from edge branch RUN sed -i -e 's/v3\.4/edge/g' /etc/apk/repositories \ diff --git a/Dockerfile.dev b/Dockerfile.dev index 2d8f6a6f..9d21fb69 100644 --- a/Dockerfile.dev +++ b/Dockerfile.dev @@ -9,19 +9,9 @@ RUN apk update # add build dependencies RUN apk add --upgrade --no-cache --virtual .build-deps \ - build-base \ cmake \ - git \ - wget \ - gcc \ g++ \ - linux-headers \ make \ - musl-dev \ - openssl-dev \ - protobuf-dev \ - protobuf-c-dev \ - sudo \ bash \ automake \ libtool \ @@ -72,11 +62,7 @@ VOLUME ["/asn1_codec_share"] # add runtime dependencies RUN apk add --upgrade --no-cache \ - bash \ - libstdc++ \ - libgcc \ - libprotobuf \ - protobuf + bash # add librdkafka from edge branch RUN sed -i -e 's/v3\.4/edge/g' /etc/apk/repositories \ diff --git a/Dockerfile.standalone b/Dockerfile.standalone index 9f7ffbaf..4ad1d31c 100644 --- a/Dockerfile.standalone +++ b/Dockerfile.standalone @@ -8,19 +8,9 @@ RUN apk update # add build dependencies RUN apk add --upgrade --no-cache --virtual .build-deps \ - build-base \ cmake \ - git \ - wget \ - gcc \ g++ \ - linux-headers \ make \ - musl-dev \ - openssl-dev \ - protobuf-dev \ - protobuf-c-dev \ - sudo \ bash \ automake \ libtool \ @@ -65,11 +55,7 @@ WORKDIR /asn1_codec # add runtime dependencies RUN apk add --upgrade --no-cache \ - bash \ - libstdc++ \ - libgcc \ - libprotobuf \ - protobuf + bash # add librdkafka from edge branch RUN sed -i -e 's/v3\.4/edge/g' /etc/apk/repositories \ From 3f85e0b7e757e5c03b5572b5b32ad6c399c28929 Mon Sep 17 00:00:00 2001 From: Daniel McCoy Stephenson Date: Tue, 25 Jul 2023 13:19:37 -0600 Subject: [PATCH 3/4] Installed librdkafka from alpine's stable branch instead of edge. --- Dockerfile | 18 ++++++------------ Dockerfile.dev | 18 ++++++------------ Dockerfile.standalone | 18 ++++++------------ 3 files changed, 18 insertions(+), 36 deletions(-) diff --git a/Dockerfile b/Dockerfile index 737ae41f..c768729e 100644 --- a/Dockerfile +++ b/Dockerfile @@ -15,12 +15,9 @@ RUN apk add --upgrade --no-cache --virtual .build-deps \ bash \ automake \ libtool \ - autoconf - -# add librdkafka from edge branch -RUN sed -i -e 's/v3\.4/edge/g' /etc/apk/repositories \ - && apk upgrade --update-cache --available \ - && apk add --no-cache librdkafka librdkafka-dev + autoconf \ + librdkafka \ + librdkafka-dev # Install pugixml ADD ./pugixml /asn1_codec/pugixml @@ -62,12 +59,9 @@ VOLUME ["/asn1_codec_share"] # add runtime dependencies RUN apk add --upgrade --no-cache \ - bash - -# add librdkafka from edge branch -RUN sed -i -e 's/v3\.4/edge/g' /etc/apk/repositories \ - && apk upgrade --update-cache --available \ - && apk add --no-cache librdkafka librdkafka-dev + bash \ + librdkafka \ + librdkafka-dev # copy the built files from the builder COPY --from=builder /asn1_codec /asn1_codec diff --git a/Dockerfile.dev b/Dockerfile.dev index 9d21fb69..644e3c59 100644 --- a/Dockerfile.dev +++ b/Dockerfile.dev @@ -15,12 +15,9 @@ RUN apk add --upgrade --no-cache --virtual .build-deps \ bash \ automake \ libtool \ - autoconf - -# add librdkafka from edge branch -RUN sed -i -e 's/v3\.4/edge/g' /etc/apk/repositories \ - && apk upgrade --update-cache --available \ - && apk add --no-cache librdkafka librdkafka-dev + autoconf \ + librdkafka \ + librdkafka-dev # Install pugixml ADD ./pugixml /asn1_codec/pugixml @@ -62,12 +59,9 @@ VOLUME ["/asn1_codec_share"] # add runtime dependencies RUN apk add --upgrade --no-cache \ - bash - -# add librdkafka from edge branch -RUN sed -i -e 's/v3\.4/edge/g' /etc/apk/repositories \ - && apk upgrade --update-cache --available \ - && apk add --no-cache librdkafka + bash \ + librdkafka \ + librdkafka-dev # install editors vim and nano RUN apk update && apk add vim nano diff --git a/Dockerfile.standalone b/Dockerfile.standalone index 4ad1d31c..e3747f19 100644 --- a/Dockerfile.standalone +++ b/Dockerfile.standalone @@ -14,12 +14,9 @@ RUN apk add --upgrade --no-cache --virtual .build-deps \ bash \ automake \ libtool \ - autoconf - -# add librdkafka from edge branch -RUN sed -i -e 's/v3\.4/edge/g' /etc/apk/repositories \ - && apk upgrade --update-cache --available \ - && apk add --no-cache librdkafka librdkafka-dev + autoconf \ + librdkafka \ + librdkafka-dev # Install pugixml ADD ./pugixml /asn1_codec/pugixml @@ -55,12 +52,9 @@ WORKDIR /asn1_codec # add runtime dependencies RUN apk add --upgrade --no-cache \ - bash - -# add librdkafka from edge branch -RUN sed -i -e 's/v3\.4/edge/g' /etc/apk/repositories \ - && apk upgrade --update-cache --available \ - && apk add --no-cache librdkafka librdkafka-dev + bash \ + librdkafka \ + librdkafka-dev # copy the built files from the builder COPY --from=builder /asn1_codec /asn1_codec From 494b84e3ef0c63a8f7c23d66e195cdae2277d8ec Mon Sep 17 00:00:00 2001 From: Daniel McCoy Stephenson Date: Mon, 11 Sep 2023 15:54:17 -0600 Subject: [PATCH 4/4] Removed test data from default dockerfile. --- Dockerfile | 3 --- 1 file changed, 3 deletions(-) diff --git a/Dockerfile b/Dockerfile index c768729e..948642fe 100644 --- a/Dockerfile +++ b/Dockerfile @@ -67,9 +67,6 @@ RUN apk add --upgrade --no-cache \ COPY --from=builder /asn1_codec /asn1_codec COPY --from=builder /build /build -# Add test data. This changes frequently so keep it low in the file. -ADD ./docker-test /asn1_codec/docker-test - # run ACM RUN chmod 7777 /asn1_codec/run_acm.sh CMD ["/asn1_codec/run_acm.sh"]