diff --git a/Dockerfile b/Dockerfile index b40d422e..d850d37c 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,27 +1,23 @@ -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 - -# 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 build dependencies +RUN apk add --upgrade --no-cache --virtual .build-deps \ + cmake \ + g++ \ + make \ + bash \ + automake \ + libtool \ + autoconf \ + librdkafka \ + librdkafka-dev # Install pugixml ADD ./pugixml /asn1_codec/pugixml @@ -52,6 +48,7 @@ ADD ./kafka-test /asn1_codec/kafka-test ADD ./unit-test-data /asn1_codec/unit-test-data ADD ./data /asn1_codec/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 @@ -61,8 +58,21 @@ RUN echo "export CC=gcc" >> ~/.bashrc # Build acm. RUN mkdir -p /build && cd /build && cmake /asn1_codec && make -# Add test data. This changes frequently so keep it low in the file. -ADD ./docker-test /asn1_codec/docker-test +# === 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 \ + librdkafka \ + librdkafka-dev + +# copy the built files from the builder +COPY --from=builder /asn1_codec /asn1_codec +COPY --from=builder /build /build # run ACM RUN chmod 7777 /asn1_codec/run_acm.sh diff --git a/Dockerfile.dev b/Dockerfile.dev index 7af0a35e..5621130a 100644 --- a/Dockerfile.dev +++ b/Dockerfile.dev @@ -1,32 +1,23 @@ -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 - -# 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 - -# 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 build dependencies +RUN apk add --upgrade --no-cache --virtual .build-deps \ + cmake \ + g++ \ + make \ + bash \ + automake \ + libtool \ + autoconf \ + librdkafka \ + librdkafka-dev # Install pugixml ADD ./pugixml /asn1_codec/pugixml @@ -57,6 +48,7 @@ ADD ./kafka-test /asn1_codec/kafka-test ADD ./unit-test-data /asn1_codec/unit-test-data ADD ./data /asn1_codec/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 @@ -66,6 +58,25 @@ 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 \ + librdkafka \ + librdkafka-dev + +# 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 db465954..de730379 100644 --- a/Dockerfile.standalone +++ b/Dockerfile.standalone @@ -1,26 +1,22 @@ -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 - -# install libtool and automake -RUN apt-get update && apt-get install -y automake libtool +# update the package manager +RUN apk update -# 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 build dependencies +RUN apk add --upgrade --no-cache --virtual .build-deps \ + cmake \ + g++ \ + make \ + bash \ + automake \ + libtool \ + autoconf \ + librdkafka \ + librdkafka-dev # Install pugixml ADD ./pugixml /asn1_codec/pugixml @@ -51,9 +47,25 @@ ADD ./kafka-test /asn1_codec/kafka-test ADD ./unit-test-data /asn1_codec/unit-test-data ADD ./data /asn1_codec/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 \ + 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