From 7248bb15fc8a269122f60e9a114fd09dbd0efab1 Mon Sep 17 00:00:00 2001 From: David Wilkie Date: Wed, 18 Sep 2024 14:57:57 +0700 Subject: [PATCH] Fix nat instance health checker (#83) --- .tool-versions | 2 +- .../nat_instance/health_checker/Dockerfile | 49 ++++++------------- .../nat_instance/health_checker/Gemfile | 3 -- .../nat_instance/health_checker/Gemfile.lock | 19 ------- .../health_checker/config/application.rb | 4 +- .../health_checker/spec/spec_helper.rb | 2 +- 6 files changed, 20 insertions(+), 59 deletions(-) diff --git a/.tool-versions b/.tool-versions index 252da6ad..a8260c39 100644 --- a/.tool-versions +++ b/.tool-versions @@ -1,2 +1,2 @@ terraform 1.8.2 -ruby 3.3.1 +ruby 3.3.5 diff --git a/infrastructure/somleng/modules/nat_instance/health_checker/Dockerfile b/infrastructure/somleng/modules/nat_instance/health_checker/Dockerfile index f8836086..9be1f244 100644 --- a/infrastructure/somleng/modules/nat_instance/health_checker/Dockerfile +++ b/infrastructure/somleng/modules/nat_instance/health_checker/Dockerfile @@ -1,48 +1,31 @@ -ARG FUNCTION_DIR="/function" -ARG RUBY_VERSION=3.3 -FROM public.ecr.aws/docker/library/ruby:$RUBY_VERSION-alpine AS build-image - -RUN apk update && \ - apk upgrade && \ - apk add --update --no-cache build-base +# syntax=docker/dockerfile:1.7-labs -RUN gem install bundler +ARG RUBY_VERSION=3.3 +FROM public.ecr.aws/lambda/ruby:$RUBY_VERSION AS build-image -ARG FUNCTION_DIR -RUN mkdir -p ${FUNCTION_DIR} -COPY Gemfile Gemfile.lock ${FUNCTION_DIR}/ -WORKDIR ${FUNCTION_DIR} +RUN dnf update && \ + dnf -y install gcc make -ENV BUNDLE_APP_CONFIG="${FUNCTION_DIR}/.bundle" +COPY Gemfile Gemfile.lock ${LAMBDA_TASK_ROOT}/ -RUN bundle config --local deployment true && \ +RUN gem install bundler && \ + bundle config --local deployment true && \ bundle config --local path "vendor/bundle" && \ - bundle config --local without 'development test' - -RUN bundle install --jobs 20 --retry 5 + bundle config --local without 'development test' && \ + bundle install RUN rm -rf vendor/bundle/ruby/*/cache/ && find vendor/ -name "*.o" -delete && find vendor/ -name "*.c" -COPY app.rb ${FUNCTION_DIR} -COPY app/ ${FUNCTION_DIR}/app/ -COPY config/ ${FUNCTION_DIR}/config/ - -############################# - -FROM public.ecr.aws/docker/library/ruby:$RUBY_VERSION-alpine +COPY app.rb ${LAMBDA_TASK_ROOT}/ +COPY app/ ${LAMBDA_TASK_ROOT}/app/ +COPY --exclude=*.key config/ ${LAMBDA_TASK_ROOT}/config/ -ARG FUNCTION_DIR -WORKDIR ${FUNCTION_DIR} +# ############################# -ENV BUNDLE_APP_CONFIG="${FUNCTION_DIR}/.bundle" -COPY --from=build-image ${FUNCTION_DIR} ${FUNCTION_DIR} +FROM public.ecr.aws/lambda/ruby:$RUBY_VERSION -RUN apk update && \ - apk upgrade && \ - gem install bundler && \ - gem install aws_lambda_ric +COPY --from=build-image ${LAMBDA_TASK_ROOT} ${LAMBDA_TASK_ROOT} ENV RUBY_YJIT_ENABLE=true -ENTRYPOINT [ "/usr/local/bundle/bin/aws_lambda_ric" ] CMD [ "app.App::Handler.process" ] diff --git a/infrastructure/somleng/modules/nat_instance/health_checker/Gemfile b/infrastructure/somleng/modules/nat_instance/health_checker/Gemfile index cce963c2..fc13d5b0 100644 --- a/infrastructure/somleng/modules/nat_instance/health_checker/Gemfile +++ b/infrastructure/somleng/modules/nat_instance/health_checker/Gemfile @@ -16,8 +16,5 @@ group :development do end group :test do - gem "pry" gem "rspec" - gem "simplecov", require: false - gem "simplecov-cobertura", require: false end diff --git a/infrastructure/somleng/modules/nat_instance/health_checker/Gemfile.lock b/infrastructure/somleng/modules/nat_instance/health_checker/Gemfile.lock index 3b50c668..6b98ea1c 100644 --- a/infrastructure/somleng/modules/nat_instance/health_checker/Gemfile.lock +++ b/infrastructure/somleng/modules/nat_instance/health_checker/Gemfile.lock @@ -33,11 +33,9 @@ GEM aws-eventstream (~> 1, >= 1.0.2) base64 (0.2.0) bigdecimal (3.1.8) - coderay (1.1.3) concurrent-ruby (1.3.4) connection_pool (2.4.1) diff-lcs (1.5.1) - docile (1.4.1) drb (2.2.1) i18n (1.14.5) concurrent-ruby (~> 1.0) @@ -45,22 +43,17 @@ GEM json (2.7.2) language_server-protocol (3.17.0.3) logger (1.6.1) - method_source (1.1.0) minitest (5.25.1) ox (2.14.18) parallel (1.26.3) parser (3.3.5.0) ast (~> 2.4.1) racc - pry (0.14.2) - coderay (~> 1.1) - method_source (~> 1.0) racc (1.8.1) rack (3.1.7) rainbow (3.1.1) rake (13.2.1) regexp_parser (2.9.2) - rexml (3.3.7) rspec (3.13.0) rspec-core (~> 3.13.0) rspec-expectations (~> 3.13.0) @@ -104,15 +97,6 @@ GEM rubocop-rails ruby-progressbar (1.13.0) securerandom (0.3.1) - simplecov (0.22.0) - docile (~> 1.1) - simplecov-html (~> 0.11) - simplecov_json_formatter (~> 0.1) - simplecov-cobertura (2.1.0) - rexml - simplecov (~> 0.19) - simplecov-html (0.13.1) - simplecov_json_formatter (0.1.4) tzinfo (2.0.6) concurrent-ruby (~> 1.0) unicode-display_width (2.5.0) @@ -126,12 +110,9 @@ DEPENDENCIES aws-sdk-cloudwatch aws-sdk-ec2 ox - pry rake rspec rubocop-rails-omakase - simplecov - simplecov-cobertura BUNDLED WITH 2.5.18 diff --git a/infrastructure/somleng/modules/nat_instance/health_checker/config/application.rb b/infrastructure/somleng/modules/nat_instance/health_checker/config/application.rb index 94349246..1a485780 100644 --- a/infrastructure/somleng/modules/nat_instance/health_checker/config/application.rb +++ b/infrastructure/somleng/modules/nat_instance/health_checker/config/application.rb @@ -1,2 +1,2 @@ -Dir["#{File.dirname(__FILE__)}/**/*.rb"].sort.each { |f| require f } -Dir["#{File.dirname(__FILE__)}/../app/**/*.rb"].sort.each { |f| require f } +Dir["#{File.dirname(__FILE__)}/**/*.rb"].each { |f| require f } +Dir["#{File.dirname(__FILE__)}/../app/**/*.rb"].each { |f| require f } diff --git a/infrastructure/somleng/modules/nat_instance/health_checker/spec/spec_helper.rb b/infrastructure/somleng/modules/nat_instance/health_checker/spec/spec_helper.rb index 223568c9..224e7309 100644 --- a/infrastructure/somleng/modules/nat_instance/health_checker/spec/spec_helper.rb +++ b/infrastructure/somleng/modules/nat_instance/health_checker/spec/spec_helper.rb @@ -103,4 +103,4 @@ # Kernel.srand config.seed end -Dir["#{File.dirname(__FILE__)}/support/**/*.rb"].sort.each { |f| require f } +Dir["#{File.dirname(__FILE__)}/support/**/*.rb"].each { |f| require f }