From 6b95913272e10af185b68338057b6d97e42e0916 Mon Sep 17 00:00:00 2001 From: Jeeva Kandasamy Date: Sun, 11 Feb 2024 22:30:59 +0530 Subject: [PATCH 1/2] tune multiarch container image build time Signed-off-by: Jeeva Kandasamy --- .github/workflows/publish_container_image.yaml | 17 ++++++++++++++--- Dockerfile | 8 +++++--- Dockerfile.without_builder | 18 ++++++++++++++++++ build.sh => scripts/build_container.sh | 13 ++++++++++++- 4 files changed, 49 insertions(+), 7 deletions(-) create mode 100644 Dockerfile.without_builder rename build.sh => scripts/build_container.sh (59%) diff --git a/.github/workflows/publish_container_image.yaml b/.github/workflows/publish_container_image.yaml index 622782c9..6e245066 100644 --- a/.github/workflows/publish_container_image.yaml +++ b/.github/workflows/publish_container_image.yaml @@ -1,12 +1,14 @@ name: publish container images on: push: - branches: [main] + branches: + - main + - release-v* # example: release-v1.14 tags: ['v*'] jobs: setup: - name: Setup + name: build container runs-on: ubuntu-latest steps: @@ -26,8 +28,17 @@ jobs: username: ${{ github.actor }} password: ${{ secrets.GITHUB_TOKEN }} + - name: Cache node modules + uses: actions/cache@v2 + env: + cache-name: cache-node-modules + with: + path: | + **/node_modules + key: ${{ runner.os }}-node-${{ hashFiles('**/yarn.lock') }} + - name: Build and push Dynamic Console container image - run: ./build.sh + run: ./scripts/build_container.sh env: SUPPORT_MULTI_ARCH: "true" CONSOLE_PLUGIN_IMAGE_REPO: 'ghcr.io/${{ github.repository }}' diff --git a/Dockerfile b/Dockerfile index 1de30536..15f219c5 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,14 +1,16 @@ -FROM registry.access.redhat.com/ubi8/nodejs-16:latest AS build +FROM registry.access.redhat.com/ubi8/nodejs-16:latest AS builder-ui USER root RUN command -v yarn || npm i -g yarn ADD . /usr/src/app WORKDIR /usr/src/app -RUN yarn install && yarn build + +RUN yarn install --frozen-lockfile && \ + yarn build FROM registry.access.redhat.com/ubi8/nginx-120:latest -COPY --from=build /usr/src/app/dist /usr/share/nginx/html +COPY --from=builder-ui /usr/src/app/dist /usr/share/nginx/html COPY ./nginx.conf /etc/nginx/nginx.conf diff --git a/Dockerfile.without_builder b/Dockerfile.without_builder new file mode 100644 index 00000000..02d2e717 --- /dev/null +++ b/Dockerfile.without_builder @@ -0,0 +1,18 @@ +# used to generate multiarch container image + +# performing "yarn install" on multiarch with "docker buildx" takes a lot of time +# to avoid this, "yarn install" and "yarn build" should be executed outside of docker +# and only copy the "dist" to different platform/architecture runtime containers +# WARNING: with this approach, if we use platform naive package may lead to a malfunction +# however in this project, the code will be executed on a browser, +# hence assuming no impact on this approach + +FROM registry.access.redhat.com/ubi8/nginx-120:latest + +COPY ./dist /usr/share/nginx/html + +COPY ./nginx.conf /etc/nginx/nginx.conf + +USER 1001 + +ENTRYPOINT ["nginx", "-g", "daemon off;"] diff --git a/build.sh b/scripts/build_container.sh similarity index 59% rename from build.sh rename to scripts/build_container.sh index ae45a645..7725515b 100755 --- a/build.sh +++ b/scripts/build_container.sh @@ -14,11 +14,22 @@ echo "Building the Console Plugin Image: ${CONSOLE_PLUGIN_IMAGE}" # builds multi arch images if [ "$SUPPORT_MULTI_ARCH" = "true" ]; then + # performing "yarn install" on multiarch with "docker buildx" takes a lot of time + # to avoid this, "yarn install" and "yarn build" should be executed outside of docker + # and only copy the "dist" to different platform/architecture runtime containers + # WARNING: with this approach, if we use platform naive package may lead to a malfunction + # however in this project, the code will be executed on a browser, + # hence assuming no impact on this approach + yarn install --frozen-lockfile + yarn build + docker buildx build --push \ --progress=plain \ --platform "linux/amd64,linux/arm64,linux/ppc64le,linux/s390x" \ + --file ./docker/Dockerfile.without_builder \ --tag ${CONSOLE_PLUGIN_IMAGE} . + else # build platform specific image - ${CONTAINER_RUNTIME} build --tag ${CONSOLE_PLUGIN_IMAGE} . + ${CONTAINER_RUNTIME} build --file ./docker/Dockerfile --tag ${CONSOLE_PLUGIN_IMAGE} . ${CONTAINER_RUNTIME} push ${CONSOLE_PLUGIN_IMAGE} fi From 1f6c7bb2ca87c56e9d723d60cfa5adf48890f04b Mon Sep 17 00:00:00 2001 From: Jeeva Kandasamy Date: Mon, 12 Feb 2024 16:09:00 +0530 Subject: [PATCH 2/2] fix dockerfile location Signed-off-by: Jeeva Kandasamy --- scripts/build_container.sh | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/scripts/build_container.sh b/scripts/build_container.sh index 7725515b..595787e0 100755 --- a/scripts/build_container.sh +++ b/scripts/build_container.sh @@ -26,10 +26,10 @@ if [ "$SUPPORT_MULTI_ARCH" = "true" ]; then docker buildx build --push \ --progress=plain \ --platform "linux/amd64,linux/arm64,linux/ppc64le,linux/s390x" \ - --file ./docker/Dockerfile.without_builder \ + --file ./Dockerfile.without_builder \ --tag ${CONSOLE_PLUGIN_IMAGE} . else # build platform specific image - ${CONTAINER_RUNTIME} build --file ./docker/Dockerfile --tag ${CONSOLE_PLUGIN_IMAGE} . + ${CONTAINER_RUNTIME} build --file ./Dockerfile --tag ${CONSOLE_PLUGIN_IMAGE} . ${CONTAINER_RUNTIME} push ${CONSOLE_PLUGIN_IMAGE} fi