diff --git a/.github/workflows/test-on-push-and-pr.yml b/.github/workflows/test-on-push-and-pr.yml index 14412ce..3d8d35e 100644 --- a/.github/workflows/test-on-push-and-pr.yml +++ b/.github/workflows/test-on-push-and-pr.yml @@ -7,14 +7,30 @@ on: branches: [ '*' ] jobs: - build: + + unit_test: runs-on: ubuntu-latest + strategy: + matrix: + ruby_version: [3.2, 3.3] + steps: + - uses: actions/checkout@v2 + - name: Set up ruby + uses: ruby/setup-ruby@v1 + with: + ruby-version: ${{ matrix.ruby_version }} + - name: Run unit tests + run: | + make init test-unit + + integration_test: + runs-on: ubuntu-latest steps: - - uses: actions/checkout@v2 - - name: Set up ruby - uses: ruby/setup-ruby@v1 - with: - ruby-version: 2.7 - - name: Run 'pr' target - run: make pr + - uses: actions/checkout@v2 + - name: Set up ruby + uses: ruby/setup-ruby@v1 + with: + ruby-version: 3.2 + - name: Run 'pr' target + run: make pr diff --git a/.gitignore b/.gitignore index f6b393d..17b91ff 100644 --- a/.gitignore +++ b/.gitignore @@ -11,3 +11,4 @@ test/examples/hello-world-docker/pkg *.iml .DS_Store Gemfile.lock +codebuild.*/ diff --git a/Makefile b/Makefile index 83ab852..a054712 100644 --- a/Makefile +++ b/Makefile @@ -13,7 +13,8 @@ setup-codebuild-agent: .PHONY: test-smoke test-smoke: setup-codebuild-agent - CODEBUILD_IMAGE_TAG=codebuild-agent test/integration/codebuild-local/test_one.sh test/integration/codebuild/buildspec.os.alpine.1.yml alpine 3.12 2.7 + CODEBUILD_IMAGE_TAG=codebuild-agent test/integration/codebuild-local/test_one.sh test/integration/codebuild/buildspec.os.alpine.yml alpine 3.20 3.2 + CODEBUILD_IMAGE_TAG=codebuild-agent test/integration/codebuild-local/test_one.sh test/integration/codebuild/buildspec.os.alpine.yml alpine 3.20 3.3 .PHONY: test-unit test-unit: @@ -28,7 +29,7 @@ build: rake build .PHONY: pr -pr: init test-unit test-smoke +pr: init test-smoke test-integ define HELP_MESSAGE diff --git a/test/integration/codebuild/buildspec.os.alpine.2.yml b/test/integration/codebuild/buildspec.os.alpine.yml similarity index 97% rename from test/integration/codebuild/buildspec.os.alpine.2.yml rename to test/integration/codebuild/buildspec.os.alpine.yml index 9c9a9d3..80cb87f 100644 --- a/test/integration/codebuild/buildspec.os.alpine.2.yml +++ b/test/integration/codebuild/buildspec.os.alpine.yml @@ -15,11 +15,11 @@ batch: env: variables: DISTRO_VERSION: - - "3.11" + - "3.19" + - "3.20" RUNTIME_VERSION: - - "2.5" - - "2.6" - - "2.7" + - "3.2" + - "3.3" phases: pre_build: commands: diff --git a/test/integration/codebuild/buildspec.os.amazonlinux.yml b/test/integration/codebuild/buildspec.os.amazonlinux2.yml similarity index 97% rename from test/integration/codebuild/buildspec.os.amazonlinux.yml rename to test/integration/codebuild/buildspec.os.amazonlinux2.yml index 08176ce..b0dd850 100644 --- a/test/integration/codebuild/buildspec.os.amazonlinux.yml +++ b/test/integration/codebuild/buildspec.os.amazonlinux2.yml @@ -17,10 +17,7 @@ batch: DISTRO_VERSION: - "2" RUNTIME_VERSION: - - "2.5" - - "2.6" - - "2.7" - - "3.0" + - "3.2" phases: pre_build: commands: @@ -40,7 +37,7 @@ phases: fi - tar -xvf test/integration/resources/${RIE}.tar.gz --directory "${SCRATCH_DIR}" - > - cp "test/integration/docker/Dockerfile.echo.${OS_DISTRIBUTION}" \ + cp "test/integration/docker/Dockerfile.echo.${OS_DISTRIBUTION}${DISTRO_VERSION}" \ "${SCRATCH_DIR}/Dockerfile.echo.${OS_DISTRIBUTION}.tmp" - > echo "COPY ${SCRATCH_DIR}/${RIE} /usr/bin/${RIE}" >> \ diff --git a/test/integration/codebuild/buildspec.os.alpine.1.yml b/test/integration/codebuild/buildspec.os.amazonlinux2023.yml similarity index 91% rename from test/integration/codebuild/buildspec.os.alpine.1.yml rename to test/integration/codebuild/buildspec.os.amazonlinux2023.yml index 361def0..5e12884 100644 --- a/test/integration/codebuild/buildspec.os.alpine.1.yml +++ b/test/integration/codebuild/buildspec.os.amazonlinux2023.yml @@ -2,9 +2,9 @@ version: 0.2 env: variables: - OS_DISTRIBUTION: alpine - EXECUTABLE: "/usr/local/bundle/bin/aws_lambda_ric" - TEST_NAME: "aws-lambda-ruby-ric-alpine-test" + OS_DISTRIBUTION: amazonlinux + EXECUTABLE: "/usr/local/bin/aws_lambda_ric" + TEST_NAME: "aws-lambda-ruby-ric-amazonlinux-test" batch: build-matrix: static: @@ -15,12 +15,9 @@ batch: env: variables: DISTRO_VERSION: - - "3.12" + - "2023" RUNTIME_VERSION: - - "2.5" - - "2.6" - - "2.7" - - "3.0" + - "3.3" phases: pre_build: commands: @@ -40,10 +37,7 @@ phases: fi - tar -xvf test/integration/resources/${RIE}.tar.gz --directory "${SCRATCH_DIR}" - > - cp "test/integration/docker/Dockerfile.echo.${OS_DISTRIBUTION}" \ - "${SCRATCH_DIR}/Dockerfile.echo.${OS_DISTRIBUTION}.tmp" - - > - echo "RUN apk add curl" >> \ + cp "test/integration/docker/Dockerfile.echo.${OS_DISTRIBUTION}${DISTRO_VERSION}" \ "${SCRATCH_DIR}/Dockerfile.echo.${OS_DISTRIBUTION}.tmp" - > echo "COPY ${SCRATCH_DIR}/${RIE} /usr/bin/${RIE}" >> \ diff --git a/test/integration/codebuild/buildspec.os.centos.yml b/test/integration/codebuild/buildspec.os.centos.yml index 74338a6..c9cb5a6 100644 --- a/test/integration/codebuild/buildspec.os.centos.yml +++ b/test/integration/codebuild/buildspec.os.centos.yml @@ -15,12 +15,10 @@ batch: env: variables: DISTRO_VERSION: - - "7" + - "8" RUNTIME_VERSION: - - "2.7" - - "2.6" - - "2.5" - - "3.0" + - "3.2" + - "3.3" phases: pre_build: commands: diff --git a/test/integration/codebuild/buildspec.os.debian.yml b/test/integration/codebuild/buildspec.os.debian.yml index 8140558..a9e0cff 100644 --- a/test/integration/codebuild/buildspec.os.debian.yml +++ b/test/integration/codebuild/buildspec.os.debian.yml @@ -15,12 +15,10 @@ batch: env: variables: DISTRO_VERSION: - - "buster" + - "bookworm" RUNTIME_VERSION: - - "2.5" - - "2.6" - - "2.7" - - "3.0" + - "3.2" + - "3.3" phases: pre_build: commands: diff --git a/test/integration/codebuild/buildspec.os.ubuntu.yml b/test/integration/codebuild/buildspec.os.ubuntu.yml index 2335ec4..f3ca788 100644 --- a/test/integration/codebuild/buildspec.os.ubuntu.yml +++ b/test/integration/codebuild/buildspec.os.ubuntu.yml @@ -15,13 +15,12 @@ batch: env: variables: DISTRO_VERSION: + - "24.04" + - "22.04" - "20.04" - - "18.04" RUNTIME_VERSION: - - "2.7" - - "2.6" - - "2.5" - - "3.0" + - "3.2" + - "3.3" phases: pre_build: commands: diff --git a/test/integration/docker/Dockerfile.echo.amazonlinux2 b/test/integration/docker/Dockerfile.echo.amazonlinux2 new file mode 100644 index 0000000..a8579b1 --- /dev/null +++ b/test/integration/docker/Dockerfile.echo.amazonlinux2 @@ -0,0 +1,64 @@ +# Define global args +ARG DISTRO_VERSION + +# Grab a fresh copy of the image and install ruby and build the runtime interface client gem +FROM amazonlinux:${DISTRO_VERSION} AS build-image + +ARG RUNTIME_VERSION + +RUN yum update -y && \ + yum install -y git-core zlib zlib-devel gcc-c++ patch readline readline-devel libffi-devel openssl-devel make bzip2 autoconf automake libtool bison curl sqlite-devel libyaml-devel + +RUN rm -rf /root/.rbenv/ +RUN git clone https://github.com/rbenv/rbenv.git /root/.rbenv +ENV PATH="/root/.rbenv/bin:$PATH" +RUN echo 'eval "$(rbenv init -)"' >> /root/.bashrc +RUN git clone https://github.com/rbenv/ruby-build.git /root/.rbenv/plugins/ruby-build +RUN source /root/.bashrc +RUN RUNTIME_VERSIONS=($(rbenv install -L | grep -oE $(echo "^${RUNTIME_VERSION}\.[0-9]+"))) && \ + RUNTIME_LATEST_VERSION=${RUNTIME_VERSIONS[-1]} && \ + rbenv install -v ${RUNTIME_LATEST_VERSION} && \ + rbenv global ${RUNTIME_LATEST_VERSION} && \ + cp /root/.rbenv/versions/${RUNTIME_LATEST_VERSION}/bin/gem /usr/local/bin/gem && \ + cp /root/.rbenv/versions/${RUNTIME_LATEST_VERSION}/bin/rake /usr/local/bin/rake && \ + gem install bundler + +ARG RIC_BUILD_DIR="/build" +# Create directory to build the Runtime Interface Client gem +RUN mkdir -p ${RIC_BUILD_DIR} + +WORKDIR ${RIC_BUILD_DIR} +COPY . . +RUN rake build + + +# Grab a fresh copy of the Ruby image +FROM amazonlinux:${DISTRO_VERSION} +RUN yum update -y && yum install -y libyaml-devel +ARG RUNTIME_VERSION + +# Copy ruby from the build-image +COPY --from=build-image /root/.rbenv /root/.rbenv + +ENV PATH="/root/.rbenv/bin:$PATH" + +# Copy the Runtime Interface Client gem and install it +ARG RIC_BUILD_DIR="/build" +COPY --from=build-image ${RIC_BUILD_DIR}/pkg/aws_lambda_ric*.gem aws_lambda_ric.gem +RUN RUNTIME_VERSIONS=($(rbenv install -L | grep -oE $(echo "^${RUNTIME_VERSION}\.[0-9]+"))) && \ + RUNTIME_LATEST_VERSION=${RUNTIME_VERSIONS[-1]} && \ + cp /root/.rbenv/versions/${RUNTIME_LATEST_VERSION}/bin/gem /usr/local/bin/gem && \ + gem install aws_lambda_ric.gem && \ + cp /root/.rbenv/versions/${RUNTIME_LATEST_VERSION}/bin/aws_lambda_ric /usr/local/bin/aws_lambda_ric + +ARG FUNCTION_DIR="/function" + +RUN mkdir -p ${FUNCTION_DIR} +# Copy function code +COPY test/integration/test-handlers/echo/* ${FUNCTION_DIR} +# Set working directory to function root directory +WORKDIR ${FUNCTION_DIR} + +ENTRYPOINT ["aws_lambda_ric"] +CMD ["app.App::Handler.process"] + diff --git a/test/integration/docker/Dockerfile.echo.amazonlinux b/test/integration/docker/Dockerfile.echo.amazonlinux2023 similarity index 97% rename from test/integration/docker/Dockerfile.echo.amazonlinux rename to test/integration/docker/Dockerfile.echo.amazonlinux2023 index 36b2614..c7bb1ab 100644 --- a/test/integration/docker/Dockerfile.echo.amazonlinux +++ b/test/integration/docker/Dockerfile.echo.amazonlinux2023 @@ -7,7 +7,7 @@ FROM amazonlinux:${DISTRO_VERSION} AS build-image ARG RUNTIME_VERSION RUN yum update -y && \ - yum install -y git-core zlib zlib-devel gcc-c++ patch readline readline-devel libffi-devel openssl-devel make bzip2 autoconf automake libtool bison curl sqlite-devel + yum install -y git-core zlib zlib-devel gcc-c++ patch readline readline-devel libffi-devel openssl-devel make bzip2 autoconf automake libtool bison sqlite-devel libyaml-devel RUN rm -rf /root/.rbenv/ RUN git clone https://github.com/rbenv/rbenv.git /root/.rbenv diff --git a/test/integration/docker/Dockerfile.echo.centos b/test/integration/docker/Dockerfile.echo.centos index afc5194..9105c97 100644 --- a/test/integration/docker/Dockerfile.echo.centos +++ b/test/integration/docker/Dockerfile.echo.centos @@ -6,8 +6,13 @@ FROM centos:${DISTRO_VERSION} AS build-image ARG RUNTIME_VERSION +# Fix repo url +RUN sed -i 's/mirrorlist/#mirrorlist/g' /etc/yum.repos.d/CentOS-* +RUN sed -i 's|#baseurl=http://mirror.centos.org|baseurl=http://vault.centos.org|g' /etc/yum.repos.d/CentOS-* + RUN yum update -y && \ yum install -y git-core zlib zlib-devel gcc-c++ patch readline readline-devel libffi-devel openssl-devel make bzip2 autoconf automake libtool bison curl sqlite-devel +RUN yum --enablerepo=powertools install libyaml-devel libffi-devel -y RUN rm -rf /root/.rbenv/ RUN git clone https://github.com/rbenv/rbenv.git /root/.rbenv diff --git a/test/unit/harness-suite.disabled.json b/test/unit/harness-suite.disabled.json new file mode 100644 index 0000000..790d77a --- /dev/null +++ b/test/unit/harness-suite.disabled.json @@ -0,0 +1,34 @@ +[ + { + "name": "test_logger_uses_telemetry_log_fd_when_logdev_is_stdout", + "handler": "log.log_to_stdout_and_read_fd", + "environmentVariables": { + "_LAMBDA_TELEMETRY_LOG_FD": "test/unit/resources/fd/test_fd" + }, + "request": { + "messages": ["Single frame\n even if there are multiple lines\nthird line"], + "fd_path": "test/unit/resources/fd/test_fd" + }, + "assertion": + { + "transform": "\"277413888114[0-9]I, \\[[0-9]{4}-(0[1-9]|1[0-2])-(0[1-9]|[1-2][0-9]|3[0-1])T(2[0-3]|[01][0-9]):[0-5][0-9]:[0-9]{2}.[0-9]{6} #[0-9]*\\] INFO ({){0,1}[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}(}){0,1} -- : Single frame\\\\n even if there are multiple lines\\\\nthird line\"", + "response": true + } + }, + { + "name": "test_logger_uses_telemetry_log_fd_when_logdev_is_stderr", + "handler": "log.log_to_stderr_and_read_fd", + "environmentVariables": { + "_LAMBDA_TELEMETRY_LOG_FD": "test/unit/resources/fd/test_fd" + }, + "request": { + "messages": ["Single frame\n even if there are multiple lines\nthird line"], + "fd_path": "test/unit/resources/fd/test_fd" + }, + "assertion": + { + "transform": "\"277413888114[0-9]E, \\[[0-9]{4}-(0[1-9]|1[0-2])-(0[1-9]|[1-2][0-9]|3[0-1])T(2[0-3]|[01][0-9]):[0-5][0-9]:[0-9]{2}.[0-9]{6} #[0-9]*\\] ERROR ({){0,1}[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}(}){0,1} -- : Single frame\\\\n even if there are multiple lines\\\\nthird line\"", + "response": true + } + } +] \ No newline at end of file diff --git a/test/unit/harness-suite.json b/test/unit/harness-suite.json index 7c1e4b7..0fd0a3e 100644 --- a/test/unit/harness-suite.json +++ b/test/unit/harness-suite.json @@ -189,22 +189,6 @@ "response": "277413888137First message first line\n second line277413888138Second message first line\n second line" } }, - { - "name": "test_logger_uses_telemetry_log_fd_when_logdev_is_stdout", - "handler": "log.log_to_stdout_and_read_fd", - "environmentVariables": { - "_LAMBDA_TELEMETRY_LOG_FD": "test/unit/resources/fd/test_fd" - }, - "request": { - "messages": ["Single frame\n even if there are multiple lines\nthird line"], - "fd_path": "test/unit/resources/fd/test_fd" - }, - "assertion": - { - "transform": "\"277413888114[0-9]I, \\[[0-9]{4}-(0[1-9]|1[0-2])-(0[1-9]|[1-2][0-9]|3[0-1])T(2[0-3]|[01][0-9]):[0-5][0-9]:[0-9]{2}.[0-9]{6} #[0-9]*\\] INFO ({){0,1}[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}(}){0,1} -- : Single frame\\\\n even if there are multiple lines\\\\nthird line\"", - "response": true - } - }, { "name": "test_logger_logs_to_a_file_when_logdev_is_a_file", "handler": "log.log_to_file_and_read_back", @@ -222,22 +206,6 @@ "response": true } }, - { - "name": "test_logger_uses_telemetry_log_fd_when_logdev_is_stderr", - "handler": "log.log_to_stderr_and_read_fd", - "environmentVariables": { - "_LAMBDA_TELEMETRY_LOG_FD": "test/unit/resources/fd/test_fd" - }, - "request": { - "messages": ["Single frame\n even if there are multiple lines\nthird line"], - "fd_path": "test/unit/resources/fd/test_fd" - }, - "assertion": - { - "transform": "\"277413888114[0-9]E, \\[[0-9]{4}-(0[1-9]|1[0-2])-(0[1-9]|[1-2][0-9]|3[0-1])T(2[0-3]|[01][0-9]):[0-5][0-9]:[0-9]{2}.[0-9]{6} #[0-9]*\\] ERROR ({){0,1}[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}(}){0,1} -- : Single frame\\\\n even if there are multiple lines\\\\nthird line\"", - "response": true - } - }, { "name": "test_arguments_are_flattened_and_separated_by_newline_when_logging", "handler": "log.put_messages_and_read_fd", diff --git a/test/unit/lambda_log_formatter_test.rb b/test/unit/lambda_log_formatter_test.rb index 0af92d2..44b505c 100644 --- a/test/unit/lambda_log_formatter_test.rb +++ b/test/unit/lambda_log_formatter_test.rb @@ -16,6 +16,6 @@ def test_formatter actual = under_test.call('INFO', time, progname, msg) - assert_equal "I, [#{time.strftime("%Y-%m-%dT%H:%M:%S.%6N")} ##{$$}] INFO #{$_global_aws_request_id} -- #{progname}: #{msg}", actual + assert_equal "I, [#{time.strftime("%Y-%m-%dT%H:%M:%S.%6N")}##{$$}] INFO #{$_global_aws_request_id} -- #{progname}: #{msg}", actual end end diff --git a/test/unit/resources/runtime_handlers/dependencies.rb b/test/unit/resources/runtime_handlers/dependencies.rb index 5953af1..c16f0d7 100644 --- a/test/unit/resources/runtime_handlers/dependencies.rb +++ b/test/unit/resources/runtime_handlers/dependencies.rb @@ -8,7 +8,7 @@ def get_tomorrow(event:, context:) end def find_dynamic_libs(event:, context:) - shared_lib_dep = `ldd /var/lang/lib/ruby/2.7.0/x86_64-linux/*.so` + shared_lib_dep = "/opt/hostedtoolcache/Ruby/*/x64/lib/ruby/*/x86_64-linux/*.so" if shared_lib_dep.include? "not found" return "Missing dependency" end diff --git a/trigger_github_action b/trigger_github_action new file mode 100644 index 0000000..9766475 --- /dev/null +++ b/trigger_github_action @@ -0,0 +1 @@ +ok