From 83b3c27137b1810ed6f0f970d7ee8a2a0fda4397 Mon Sep 17 00:00:00 2001 From: Mehmet Nuri Deveci <5735811+mndeveci@users.noreply.github.com> Date: Tue, 14 Nov 2023 21:20:30 -0800 Subject: [PATCH 01/11] add arch specific targets --- Makefile | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/Makefile b/Makefile index 649e9cc..d44c440 100644 --- a/Makefile +++ b/Makefile @@ -51,6 +51,12 @@ endif build-single-arch: pre-build docker build -f build-image-src/Dockerfile-$(RUNTIME) -t amazon/aws-sam-cli-build-image-$(IS_$(RUNTIME)):x86_64 --build-arg SAM_CLI_VERSION=$(SAM_CLI_VERSION) ./build-image-src +build-multi-arch-x86: pre-build + docker build -f build-image-src/Dockerfile-$(RUNTIME) -t amazon/aws-sam-cli-build-image-$(IS_$(RUNTIME)):x86_64 --platform linux/amd64 --build-arg SAM_CLI_VERSION=$(SAM_CLI_VERSION) --build-arg AWS_CLI_ARCH=x86_64 --build-arg IMAGE_ARCH=x86_64 ./build-image-src + +build-multi-arch-arm64: pre-build + docker build -f build-image-src/Dockerfile-$(RUNTIME) -t amazon/aws-sam-cli-build-image-$(IS_$(RUNTIME)):arm64 --platform linux/arm64 --build-arg SAM_CLI_VERSION=$(SAM_CLI_VERSION) --build-arg AWS_CLI_ARCH=aarch64 --build-arg IMAGE_ARCH=arm64 ./build-image-src + build-multi-arch: pre-build docker build -f build-image-src/Dockerfile-$(RUNTIME) -t amazon/aws-sam-cli-build-image-$(IS_$(RUNTIME)):x86_64 --platform linux/amd64 --build-arg SAM_CLI_VERSION=$(SAM_CLI_VERSION) --build-arg AWS_CLI_ARCH=x86_64 --build-arg IMAGE_ARCH=x86_64 ./build-image-src docker run --privileged --rm tonistiigi/binfmt --install arm64 From b42c514be46ad3d75aedb7a5e748915f36d66b90 Mon Sep 17 00:00:00 2001 From: Mehmet Nuri Deveci <5735811+mndeveci@users.noreply.github.com> Date: Tue, 14 Nov 2023 21:45:08 -0800 Subject: [PATCH 02/11] update test name temp --- tests/test_build_images.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/test_build_images.py b/tests/test_build_images.py index a102b47..0be6ed8 100644 --- a/tests/test_build_images.py +++ b/tests/test_build_images.py @@ -335,7 +335,7 @@ def test_packages(self): @pytest.mark.nodejs20x -class TestBINode20ForArm(AL2023BasedBuildImageBase): +class TestArmBINode20(AL2023BasedBuildImageBase): __test__ = True @classmethod From dbb6dd313cd1c796259cbcae963dda592ce74085 Mon Sep 17 00:00:00 2001 From: Mehmet Nuri Deveci <5735811+mndeveci@users.noreply.github.com> Date: Tue, 14 Nov 2023 21:52:53 -0800 Subject: [PATCH 03/11] update node executable with custom LD_LIBRARY_PATH --- build-image-src/Dockerfile-nodejs20x | 21 +++++++++++++++------ 1 file changed, 15 insertions(+), 6 deletions(-) diff --git a/build-image-src/Dockerfile-nodejs20x b/build-image-src/Dockerfile-nodejs20x index 87b4a50..16a5994 100644 --- a/build-image-src/Dockerfile-nodejs20x +++ b/build-image-src/Dockerfile-nodejs20x @@ -1,11 +1,6 @@ ARG IMAGE_ARCH FROM public.ecr.aws/lambda/nodejs:20-$IMAGE_ARCH -ENV PATH=/var/lang/bin:$PATH \ - LD_LIBRARY_PATH=/var/lang/lib:$LD_LIBRARY_PATH \ - AWS_EXECUTION_ENV=AWS_Lambda_nodejs20.x \ - NODE_PATH=/opt/nodejs/node20/node_modules:/opt/nodejs/node_modules:/var/runtime/node_modules - RUN dnf remove -y microdnf-dnf && \ microdnf install -y dnf @@ -28,6 +23,20 @@ RUN dnf groupinstall -y development && \ python3-devel \ && dnf clean all +RUN mv /var/lang/bin/node /var/lang/bin/node.bin +RUN rm /var/lang/bin/node +RUN cat <> /var/lang/bin/node +#!/bin/bash + +LD_LIBRARY_PATH=${LD_LIBRARY_PATH} exec node.bin -- "$@" +EOT +RUN chmod +x /var/lang/bin/node + +ENV PATH=/var/lang/bin:$PATH \ + LD_LIBRARY_PATH= \ + AWS_EXECUTION_ENV=AWS_Lambda_nodejs20.x \ + NODE_PATH=/opt/nodejs/node20/node_modules:/opt/nodejs/node_modules:/var/runtime/node_modules + # Install AWS CLI ARG AWS_CLI_ARCH RUN curl "https://awscli.amazonaws.com/awscli-exe-linux-$AWS_CLI_ARCH.zip" -o "awscliv2.zip" && unzip awscliv2.zip && ./aws/install && rm awscliv2.zip && rm -rf ./aws @@ -54,4 +63,4 @@ COPY ATTRIBUTION.txt / # Compatible with initial base image ENTRYPOINT [] -CMD ["/bin/bash"] +CMD ["/bin/bash"] \ No newline at end of file From 32e771eb5ef26d14f6846e49fe1dc1564571bdbc Mon Sep 17 00:00:00 2001 From: Mehmet Nuri Deveci <5735811+mndeveci@users.noreply.github.com> Date: Tue, 14 Nov 2023 21:58:12 -0800 Subject: [PATCH 04/11] write new node exec with $ sign --- build-image-src/Dockerfile-nodejs20x | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/build-image-src/Dockerfile-nodejs20x b/build-image-src/Dockerfile-nodejs20x index 16a5994..602a093 100644 --- a/build-image-src/Dockerfile-nodejs20x +++ b/build-image-src/Dockerfile-nodejs20x @@ -25,11 +25,8 @@ RUN dnf groupinstall -y development && \ RUN mv /var/lang/bin/node /var/lang/bin/node.bin RUN rm /var/lang/bin/node -RUN cat <> /var/lang/bin/node -#!/bin/bash - -LD_LIBRARY_PATH=${LD_LIBRARY_PATH} exec node.bin -- "$@" -EOT +RUN echo $'#!/bin/bash \n\ +LD_LIBRARY_PATH=${LD_LIBRARY_PATH} exec node.bin -- "$@"' >> /var/lang/bin/node RUN chmod +x /var/lang/bin/node ENV PATH=/var/lang/bin:$PATH \ From 0f28035fe24120da0c1cdd41b33c8838fabfcc12 Mon Sep 17 00:00:00 2001 From: Mehmet Nuri Deveci <5735811+mndeveci@users.noreply.github.com> Date: Tue, 14 Nov 2023 22:00:30 -0800 Subject: [PATCH 05/11] remove redundant rm --- build-image-src/Dockerfile-nodejs20x | 1 - 1 file changed, 1 deletion(-) diff --git a/build-image-src/Dockerfile-nodejs20x b/build-image-src/Dockerfile-nodejs20x index 602a093..042b7e3 100644 --- a/build-image-src/Dockerfile-nodejs20x +++ b/build-image-src/Dockerfile-nodejs20x @@ -24,7 +24,6 @@ RUN dnf groupinstall -y development && \ && dnf clean all RUN mv /var/lang/bin/node /var/lang/bin/node.bin -RUN rm /var/lang/bin/node RUN echo $'#!/bin/bash \n\ LD_LIBRARY_PATH=${LD_LIBRARY_PATH} exec node.bin -- "$@"' >> /var/lang/bin/node RUN chmod +x /var/lang/bin/node From fe81fb9ec340c4463c8497aa298b1b3edba2b146 Mon Sep 17 00:00:00 2001 From: Mehmet Nuri Deveci <5735811+mndeveci@users.noreply.github.com> Date: Tue, 14 Nov 2023 22:13:44 -0800 Subject: [PATCH 06/11] revert nodejs20 dockerfile changes --- build-image-src/Dockerfile-nodejs20x | 15 +++++---------- 1 file changed, 5 insertions(+), 10 deletions(-) diff --git a/build-image-src/Dockerfile-nodejs20x b/build-image-src/Dockerfile-nodejs20x index 042b7e3..656babd 100644 --- a/build-image-src/Dockerfile-nodejs20x +++ b/build-image-src/Dockerfile-nodejs20x @@ -1,6 +1,11 @@ ARG IMAGE_ARCH FROM public.ecr.aws/lambda/nodejs:20-$IMAGE_ARCH +ENV PATH=/var/lang/bin:$PATH \ + LD_LIBRARY_PATH=/var/lang/lib:$LD_LIBRARY_PATH \ + AWS_EXECUTION_ENV=AWS_Lambda_nodejs20.x \ + NODE_PATH=/opt/nodejs/node20/node_modules:/opt/nodejs/node_modules:/var/runtime/node_modules + RUN dnf remove -y microdnf-dnf && \ microdnf install -y dnf @@ -23,16 +28,6 @@ RUN dnf groupinstall -y development && \ python3-devel \ && dnf clean all -RUN mv /var/lang/bin/node /var/lang/bin/node.bin -RUN echo $'#!/bin/bash \n\ -LD_LIBRARY_PATH=${LD_LIBRARY_PATH} exec node.bin -- "$@"' >> /var/lang/bin/node -RUN chmod +x /var/lang/bin/node - -ENV PATH=/var/lang/bin:$PATH \ - LD_LIBRARY_PATH= \ - AWS_EXECUTION_ENV=AWS_Lambda_nodejs20.x \ - NODE_PATH=/opt/nodejs/node20/node_modules:/opt/nodejs/node_modules:/var/runtime/node_modules - # Install AWS CLI ARG AWS_CLI_ARCH RUN curl "https://awscli.amazonaws.com/awscli-exe-linux-$AWS_CLI_ARCH.zip" -o "awscliv2.zip" && unzip awscliv2.zip && ./aws/install && rm awscliv2.zip && rm -rf ./aws From c60eaad08f5646f7dfdd13160a8dbfeb53f4d8cb Mon Sep 17 00:00:00 2001 From: Mehmet Nuri Deveci <5735811+mndeveci@users.noreply.github.com> Date: Tue, 14 Nov 2023 22:15:18 -0800 Subject: [PATCH 07/11] override ld_lib_path for tests --- tests/build_image_base_test.py | 27 +++++++++++++++++++-------- 1 file changed, 19 insertions(+), 8 deletions(-) diff --git a/tests/build_image_base_test.py b/tests/build_image_base_test.py index 5fcceae..260c6a7 100644 --- a/tests/build_image_base_test.py +++ b/tests/build_image_base_test.py @@ -89,14 +89,25 @@ def test_sam_init(self): if self.dep_manager: sam_init += f" --dependency-manager {self.dep_manager}" - op = self.client.containers.run( - image=self.image, - command=[ - "/bin/sh", - "-c", - sam_init + " && cd sam-app && sam build", - ], - ).decode() + if self.runtime == 'nodejs20.x': + op = self.client.containers.run( + image=self.image, + command=[ + "/bin/sh", + "-c", + sam_init + " && cd sam-app && sam build", + ], + env=["LD_LIBRARY_PATH="] + ).decode() + else: + op = self.client.containers.run( + image=self.image, + command=[ + "/bin/sh", + "-c", + sam_init + " && cd sam-app && sam build", + ], + ).decode() self.assertTrue(op.find("Build Succeeded")) def test_external_apps(self): From e019af27b178fe9172777af4e3a28e431a8ee155 Mon Sep 17 00:00:00 2001 From: Mehmet Nuri Deveci <5735811+mndeveci@users.noreply.github.com> Date: Tue, 14 Nov 2023 22:20:59 -0800 Subject: [PATCH 08/11] update environment --- tests/build_image_base_test.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/build_image_base_test.py b/tests/build_image_base_test.py index 260c6a7..73cabef 100644 --- a/tests/build_image_base_test.py +++ b/tests/build_image_base_test.py @@ -97,7 +97,7 @@ def test_sam_init(self): "-c", sam_init + " && cd sam-app && sam build", ], - env=["LD_LIBRARY_PATH="] + environment=["LD_LIBRARY_PATH="] ).decode() else: op = self.client.containers.run( From f71fab1098fbaf1adc98684e72793932c01eca8c Mon Sep 17 00:00:00 2001 From: Mehmet Nuri Deveci <5735811+mndeveci@users.noreply.github.com> Date: Tue, 14 Nov 2023 22:28:46 -0800 Subject: [PATCH 09/11] add some comments --- tests/build_image_base_test.py | 1 + 1 file changed, 1 insertion(+) diff --git a/tests/build_image_base_test.py b/tests/build_image_base_test.py index 73cabef..799956d 100644 --- a/tests/build_image_base_test.py +++ b/tests/build_image_base_test.py @@ -89,6 +89,7 @@ def test_sam_init(self): if self.dep_manager: sam_init += f" --dependency-manager {self.dep_manager}" + # For nodejs20.x set LD_LIBRARY_PATH env variable to execute sam commands if self.runtime == 'nodejs20.x': op = self.client.containers.run( image=self.image, From 0d8dafcf6ed7d35c1c41d12d6a62a0db2fc3bb83 Mon Sep 17 00:00:00 2001 From: Mehmet Nuri Deveci <5735811+mndeveci@users.noreply.github.com> Date: Tue, 14 Nov 2023 22:30:06 -0800 Subject: [PATCH 10/11] revert test class name change --- tests/test_build_images.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/test_build_images.py b/tests/test_build_images.py index 0be6ed8..a102b47 100644 --- a/tests/test_build_images.py +++ b/tests/test_build_images.py @@ -335,7 +335,7 @@ def test_packages(self): @pytest.mark.nodejs20x -class TestArmBINode20(AL2023BasedBuildImageBase): +class TestBINode20ForArm(AL2023BasedBuildImageBase): __test__ = True @classmethod From df491e43ce8b4499dafa8f4a3148cdd340e46e1e Mon Sep 17 00:00:00 2001 From: Mehmet Nuri Deveci <5735811+mndeveci@users.noreply.github.com> Date: Tue, 14 Nov 2023 22:31:15 -0800 Subject: [PATCH 11/11] remove additional makefile targets --- Makefile | 6 ------ 1 file changed, 6 deletions(-) diff --git a/Makefile b/Makefile index d44c440..649e9cc 100644 --- a/Makefile +++ b/Makefile @@ -51,12 +51,6 @@ endif build-single-arch: pre-build docker build -f build-image-src/Dockerfile-$(RUNTIME) -t amazon/aws-sam-cli-build-image-$(IS_$(RUNTIME)):x86_64 --build-arg SAM_CLI_VERSION=$(SAM_CLI_VERSION) ./build-image-src -build-multi-arch-x86: pre-build - docker build -f build-image-src/Dockerfile-$(RUNTIME) -t amazon/aws-sam-cli-build-image-$(IS_$(RUNTIME)):x86_64 --platform linux/amd64 --build-arg SAM_CLI_VERSION=$(SAM_CLI_VERSION) --build-arg AWS_CLI_ARCH=x86_64 --build-arg IMAGE_ARCH=x86_64 ./build-image-src - -build-multi-arch-arm64: pre-build - docker build -f build-image-src/Dockerfile-$(RUNTIME) -t amazon/aws-sam-cli-build-image-$(IS_$(RUNTIME)):arm64 --platform linux/arm64 --build-arg SAM_CLI_VERSION=$(SAM_CLI_VERSION) --build-arg AWS_CLI_ARCH=aarch64 --build-arg IMAGE_ARCH=arm64 ./build-image-src - build-multi-arch: pre-build docker build -f build-image-src/Dockerfile-$(RUNTIME) -t amazon/aws-sam-cli-build-image-$(IS_$(RUNTIME)):x86_64 --platform linux/amd64 --build-arg SAM_CLI_VERSION=$(SAM_CLI_VERSION) --build-arg AWS_CLI_ARCH=x86_64 --build-arg IMAGE_ARCH=x86_64 ./build-image-src docker run --privileged --rm tonistiigi/binfmt --install arm64