How can i do install correctly gems and bundler in rails container?

Hii
I have macos m1 pro, but i feel i have problems with cache in many projects i try build not only rails, i dont know in this case if its the mac or syntax or my error in something.

In this project im doing i’m using docker compose, but i have two dockerfile and docker compose im trying making this, but always said:

I dont know how debugging more to verify im coping the gems and installing correctly

Command in entrypoint is: ./bin/dev → I would like put more photos but new users media limit is 1.

Dockerfile:

ARG RUBY_VERSION=3.3.6
FROM docker.io/library/ruby:$RUBY_VERSION-slim AS base

# Rails app lives here
WORKDIR /rails

# Install base packages
# Replace libpq-dev with sqlite3 if using SQLite, or libmysqlclient-dev if using MySQL
RUN apt-get update -qq && \
  apt-get install --no-install-recommends -y curl libjemalloc2 libvips libpq-dev && \
  rm -rf /var/lib/apt/lists /var/cache/apt/archives

# Set production environment
ENV RAILS_ENV="production" \
  BUNDLE_DEPLOYMENT="1" \
  BUNDLE_PATH="/usr/local/bundle" \
  BUNDLE_WITHOUT="development"

# Throw-away build stage to reduce size of final image
FROM base AS build

# Install packages needed to build gems
RUN apt-get update -qq && \
  apt-get install --no-install-recommends -y build-essential curl git pkg-config && \
  rm -rf /var/lib/apt/lists /var/cache/apt/archives

# Install JavaScript dependencies and Node.js for asset compilation
#
# Uncomment the following lines if you are using NodeJS need to compile assets
#
# ARG NODE_VERSION=18.12.0
# ARG YARN_VERSION=1.22.19
# ENV PATH=/usr/local/node/bin:$PATH
# RUN curl -sL https://github.com/nodenv/node-build/archive/master.tar.gz | tar xz -C /tmp/ && \
#     /tmp/node-build-master/bin/node-build "${NODE_VERSION}" /usr/local/node && \
#     npm install -g yarn@$YARN_VERSION && \
#     npm install -g mjml && \
#     rm -rf /tmp/node-build-master

# Install application gems
COPY Gemfile Gemfile.lock ./

RUN gem update --system
RUN gem install bundler -i '2.6.2'
RUN bundle _2.6.2_ install && \
  rm -rf ~/.bundle/ "${BUNDLE_PATH}"/ruby/*/cache "${BUNDLE_PATH}"/ruby/*/bundler/gems/*/.git && \
  bundle exec bootsnap precompile --gemfile

# Install node modules
#
# Uncomment the following lines if you are using NodeJS need to compile assets
#
# COPY package.json yarn.lock ./
# RUN --mount=type=cache,id=yarn,target=/rails/.cache/yarn YARN_CACHE_FOLDER=/rails/.cache/yarn \
#     yarn install --frozen-lockfile

# Copy application code
COPY . .

# Precompile bootsnap code for faster boot times
RUN bundle exec bootsnap precompile app/ lib/

# Precompiling assets for production without requiring secret RAILS_MASTER_KEY
RUN SECRET_KEY_BASE_DUMMY=1 ./bin/rails assets:precompile

# Final stage for app image
FROM base

# Copy built artifacts: gems, application
COPY --from=build "${BUNDLE_PATH}" "${BUNDLE_PATH}"
COPY --from=build /rails /rails

# Run and own only the runtime files as a non-root user for security
RUN groupadd --system --gid 1000 rails && \
  useradd rails --uid 1000 --gid 1000 --create-home --shell /bin/bash && \
  chown -R rails:rails db log storage tmp
USER 1000:1000

# Entrypoint prepares the database.
ENTRYPOINT ["/rails/bin/docker-entrypoint"]

# Start server via Thruster by default, this can be overwritten at runtime
EXPOSE 3000
CMD [./bin/rails", "server"]

Docker compose:

services:
  easy-post-ia-back:
    build:
      context: .
      dockerfile: Dockerfile
    command: bash -c "./.docker-container/docker-entrypoint.sh"
    image: easy-post-ia-back:${ENVIRONMENT_RAILS}
    container_name: easy-post-ia-back
    restart: on-failure:2
    tty: true
    stdin_open: true
    env_file:
      - .env
    depends_on:
      easy-post-ia-postgresdb:
        condition: service_healthy
      redis:
        condition: service_started
    ports:
      - "${API_PORT}:${API_PORT}"
    volumes:
      - .:/rails
      - bundle_cache:/usr/local/bundle
    healthcheck:
      test: ["CMD", "curl", "--fail", "http://localhost:3000/up"]
      interval: 200s
      retries: 3
      start_period: 50s
      timeout: 10s
    networks:
      - easy-post-ia-backend-network
  easy-post-ia-postgresdb:
    container_name: "easy-post-ia-pg_db"
    image: postgres:latest
    ports:
      - "${POSTGRES_DB_PORT}:${POSTGRES_DB_PORT}"
    environment:
      - POSTGRES_PASSWORD=${POSTGRES_DB_PASSWD}
      - POSTGRES_USER=${POSTGRES_DB_USER}
      - POSTGRES_DB=${POSTGRES_DB}
      - POSTGRES_HOST_AUTH_METHOD=trust
    volumes:
      - pg_data:/var/lib/postgresql/data
    healthcheck:
      test: pg_isready -U postgres
      interval: 2s
      timeout: 5s
      retries: 10
    networks:
      - easy-post-ia-backend-network
  redis:
    container_name: "easy-post-ia-redis"
    image: redis
    volumes:
      - redis_data:/data
    healthcheck:
      test: ["CMD", "redis-cli", "ping"]
      interval: 200s
      retries: 5
      start_period: 10s
      timeout: 10s
    ports:
      - "6379:6379"
    networks:
      - easy-post-ia-backend-network
  # sidekiq:
  #   user: root
  #   build: ./
  #   container_name: easy-post-ia-sidekiq
  #   command: bundle exec sidekiq -C /rails/config/sidekiq.yml --verbose
  #   depends_on:
  #     - redis
  #     - easy-post-ia-postgresdb
  #   volumes:
  #     - .:/rails
  #     - bundle_cache:/usr/local/bundle
  #   env_file:
  #     - .env
  #   networks:
  #     - easy-post-ia-backend-network
  #
networks:
  easy-post-ia-backend-network:
    driver: bridge
volumes:
  pg_data:
  redis_data:
  bundle_cache:

Note: I dont know what i do more

Have you tried starting a container from the image and passing a shell as argument so you can interactively look for the modules in the container? If yo don’t find the modules, you can find out why. If you find but not where you expect them to be, that is one clue you can work with.

This topic was automatically closed 10 days after the last reply. New replies are no longer allowed.