From feb5ff1f2c56c58465b81c71e710f9fd4cbeae5e Mon Sep 17 00:00:00 2001 From: Johann Hoffmann Date: Tue, 8 Feb 2022 15:02:31 +0100 Subject: [PATCH] [WIFI-6729] Speed up Docker image build time (#38) * Re-structure Dockerfile and use docker-image-build composite action Signed-off-by: Johann Hoffmann * Fix aws-sdk-cpp repo url Signed-off-by: Johann Hoffmann * Fix package list syntax error Signed-off-by: Johann Hoffmann * Add curl to build-base Signed-off-by: Johann Hoffmann * Install curl-dev instead of curl in build image Signed-off-by: Johann Hoffmann * Cut build lib copying Signed-off-by: Johann Hoffmann * Remove branch since PR was merged in composite actions repo Signed-off-by: Johann Hoffmann --- .github/workflows/ci.yml | 51 ++++-------------- Dockerfile | 111 +++++++++++++++++++++++---------------- 2 files changed, 76 insertions(+), 86 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 9757ef9..660d7b0 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -25,48 +25,19 @@ jobs: DOCKER_REGISTRY_URL: tip-tip-wlan-cloud-ucentral.jfrog.io DOCKER_REGISTRY_USERNAME: ucentral steps: - - uses: actions/checkout@v2 - - - name: Build Docker image - run: docker build -t wlan-cloud-owsec:${{ github.sha }} . - - - name: Tag Docker image - run: | - TAGS="${{ github.sha }}" - - if [[ ${GITHUB_REF} == "refs/heads/"* ]] - then - CURRENT_TAG=$(echo ${GITHUB_REF#refs/heads/} | tr '/' '-') - TAGS="$TAGS $CURRENT_TAG" - else - if [[ ${GITHUB_REF} == "refs/tags/"* ]] - then - CURRENT_TAG=$(echo ${GITHUB_REF#refs/tags/} | tr '/' '-') - TAGS="$TAGS $CURRENT_TAG" - else # PR build - CURRENT_TAG=$(echo ${GITHUB_HEAD_REF#refs/heads/} | tr '/' '-') - TAGS="$TAGS $CURRENT_TAG" - fi - fi - - echo "Result tags: $TAGS" - - for tag in $TAGS; do - docker tag wlan-cloud-owsec:${{ github.sha }} ${{ env.DOCKER_REGISTRY_URL }}/owsec:$tag - done - - - name: Log into Docker registry - if: startsWith(github.ref, 'refs/tags/') || startsWith(github.ref, 'refs/pull/') || github.ref == 'refs/heads/main' - uses: docker/login-action@v1 + - name: Checkout actions repo + uses: actions/checkout@v2 with: - registry: ${{ env.DOCKER_REGISTRY_URL }} - username: ${{ env.DOCKER_REGISTRY_USERNAME }} - password: ${{ secrets.DOCKER_REGISTRY_PASSWORD }} + repository: Telecominfraproject/.github + path: github - - name: Push Docker images - if: startsWith(github.ref, 'refs/tags/') || startsWith(github.ref, 'refs/pull/') || github.ref == 'refs/heads/main' - run: | - docker images | grep ${{ env.DOCKER_REGISTRY_URL }}/owsec | awk -F ' ' '{print $1":"$2}' | xargs -I {} docker push {} + - name: Build and push Docker image + uses: ./github/composite-actions/docker-image-build + with: + image_name: owsec + registry: tip-tip-wlan-cloud-ucentral.jfrog.io + registry_user: ucentral + registry_password: ${{ secrets.DOCKER_REGISTRY_PASSWORD }} trigger-testing: if: startsWith(github.ref, 'refs/pull/') diff --git a/Dockerfile b/Dockerfile index 4d5aa9f..fe95f38 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,18 +1,51 @@ -FROM alpine AS builder +FROM alpine:3.15 AS build-base RUN apk add --update --no-cache \ - openssl openssh \ - ncurses-libs \ - bash util-linux coreutils curl libcurl \ - make cmake gcc g++ libstdc++ libgcc git zlib-dev \ - openssl-dev boost-dev curl-dev unixodbc-dev postgresql-dev mariadb-dev \ - apache2-utils yaml-dev apr-util-dev \ - librdkafka-dev + make cmake g++ git \ + unixodbc-dev postgresql-dev mariadb-dev \ + librdkafka-dev boost-dev openssl-dev \ + zlib-dev nlohmann-json \ + curl-dev +FROM build-base AS poco-build + +ADD https://api.github.com/repos/stephb9959/poco/git/refs/heads/master version.json RUN git clone https://github.com/stephb9959/poco /poco + +WORKDIR /poco +RUN mkdir cmake-build +WORKDIR cmake-build +RUN cmake .. +RUN cmake --build . --config Release -j8 +RUN cmake --build . --target install + +FROM build-base AS cppkafka-build + +ADD https://api.github.com/repos/stephb9959/cppkafka/git/refs/heads/master version.json RUN git clone https://github.com/stephb9959/cppkafka /cppkafka -RUN git clone https://github.com/nlohmann/json /json + +WORKDIR /cppkafka +RUN mkdir cmake-build +WORKDIR cmake-build +RUN cmake .. +RUN cmake --build . --config Release -j8 +RUN cmake --build . --target install + +FROM build-base AS json-schema-validator-build + +ADD https://api.github.com/repos/pboettch/json-schema-validator/git/refs/heads/master version.json RUN git clone https://github.com/pboettch/json-schema-validator /json-schema-validator + +WORKDIR /json-schema-validator +RUN mkdir cmake-build +WORKDIR cmake-build +RUN cmake .. +RUN make +RUN make install + +FROM build-base AS aws-sdk-cpp-build + +ADD https://api.github.com/repos/aws/aws-sdk-cpp/git/refs/heads/main version.json RUN git clone --recurse-submodules https://github.com/aws/aws-sdk-cpp /aws-sdk-cpp WORKDIR /aws-sdk-cpp @@ -25,46 +58,29 @@ RUN cmake .. -DBUILD_ONLY="sns;s3" \ RUN cmake --build . --config Release -j8 RUN cmake --build . --target install -WORKDIR /cppkafka -RUN mkdir cmake-build -WORKDIR cmake-build -RUN cmake .. -RUN cmake --build . --config Release -j8 -RUN cmake --build . --target install - -WORKDIR /poco -RUN mkdir cmake-build -WORKDIR cmake-build -RUN cmake .. -RUN cmake --build . --config Release -j8 -RUN cmake --build . --target install - -WORKDIR /json -RUN mkdir cmake-build -WORKDIR cmake-build -RUN cmake .. -RUN make -RUN make install - -WORKDIR /json-schema-validator -RUN mkdir cmake-build -WORKDIR cmake-build -RUN cmake .. -RUN make -RUN make install +FROM build-base AS owsec-build ADD CMakeLists.txt build /owsec/ ADD cmake /owsec/cmake ADD src /owsec/src ADD .git /owsec/.git +COPY --from=poco-build /usr/local/include /usr/local/include +COPY --from=poco-build /usr/local/lib /usr/local/lib +COPY --from=cppkafka-build /usr/local/include /usr/local/include +COPY --from=cppkafka-build /usr/local/lib /usr/local/lib +COPY --from=json-schema-validator-build /usr/local/include /usr/local/include +COPY --from=json-schema-validator-build /usr/local/lib /usr/local/lib +COPY --from=aws-sdk-cpp-build /usr/local/include /usr/local/include +COPY --from=aws-sdk-cpp-build /usr/local/lib /usr/local/lib + WORKDIR /owsec RUN mkdir cmake-build WORKDIR /owsec/cmake-build RUN cmake .. RUN cmake --build . --config Release -j8 -FROM alpine +FROM alpine:3.15 ENV OWSEC_USER=owsec \ OWSEC_ROOT=/owsec-data \ @@ -76,13 +92,12 @@ RUN addgroup -S "$OWSEC_USER" && \ RUN mkdir /openwifi RUN mkdir -p "$OWSEC_ROOT" "$OWSEC_CONFIG" && \ chown "$OWSEC_USER": "$OWSEC_ROOT" "$OWSEC_CONFIG" -RUN apk add --update --no-cache librdkafka mariadb-connector-c libpq unixodbc su-exec gettext ca-certificates libcurl curl-dev bash jq curl postgresql-client -COPY --from=builder /owsec/cmake-build/owsec /openwifi/owsec -COPY --from=builder /cppkafka/cmake-build/src/lib/* /lib/ -COPY --from=builder /poco/cmake-build/lib/* /lib/ -COPY --from=builder /aws-sdk-cpp/cmake-build/aws-cpp-sdk-core/libaws-cpp-sdk-core.so /lib/ -COPY --from=builder /aws-sdk-cpp/cmake-build/aws-cpp-sdk-s3/libaws-cpp-sdk-s3.so /lib/ -COPY --from=builder /aws-sdk-cpp/cmake-build/aws-cpp-sdk-sns/libaws-cpp-sdk-sns.so /lib/ + +RUN apk add --update --no-cache librdkafka su-exec gettext ca-certificates bash jq curl \ + mariadb-connector-c libpq unixodbc postgresql-client + +COPY readiness_check /readiness_check +COPY test_scripts/curl/cli /cli COPY owsec.properties.tmpl / COPY wwwassets /dist/wwwassets @@ -92,8 +107,12 @@ COPY wait-for-postgres.sh / RUN wget https://raw.githubusercontent.com/Telecominfraproject/wlan-cloud-ucentral-deploy/main/docker-compose/certs/restapi-ca.pem \ -O /usr/local/share/ca-certificates/restapi-ca-selfsigned.pem -COPY readiness_check /readiness_check -COPY test_scripts/curl/cli /cli +COPY --from=owsec-build /owsec/cmake-build/owsec /openwifi/owsec +COPY --from=cppkafka-build /cppkafka/cmake-build/src/lib/* /usr/local/lib +COPY --from=poco-build /poco/cmake-build/lib/* /usr/local/lib +COPY --from=aws-sdk-cpp-build /aws-sdk-cpp/cmake-build/aws-cpp-sdk-core/libaws-cpp-sdk-core.so /usr/local/lib +COPY --from=aws-sdk-cpp-build /aws-sdk-cpp/cmake-build/aws-cpp-sdk-s3/libaws-cpp-sdk-s3.so /usr/local/lib +COPY --from=aws-sdk-cpp-build /aws-sdk-cpp/cmake-build/aws-cpp-sdk-sns/libaws-cpp-sdk-sns.so /usr/local/lib EXPOSE 16001 17001 16101