Ruby - Running one web server and 4 background jobs off same build is very slow to deploy

Hello everyone,

I need help with my use case where our Ruby application is made of one web server, and 3 background workers. Ultimately they are all using the same build, but then each are running a different process (puma for web server, other worker jobs for others) Today, in Qovery, this means that when a change is made, 4 builds take place of our application. this takes over 30 minutes and honestly last week, we ended up resorting to spinning back our Heroku instance since it is much faster and we needed some continuous rapid prototyping for a demo. I am looking for help so we can run only one base build for our application and then have each instance simply leverage that base image and run whatever process-specific this container will be running

Sharing our docker containers:
As you can see, below, the entire build process is exactly the same, with only one exception for the command that is being run for every container.

First container:

FROM ruby:2.6.9-bullseye AS builder

ENV BUNDLE_WITHOUT='development:test'
ENV BUNDLE_PATH=vendor/bundle
ENV BUNDLE_BIN=vendor/bundle/bin
ENV BUNDLE_DEPLOYMENT=1
ENV BUNDLE_GLOBAL_PATH_APPENDS_RUBY_SCOPE=1


RUN apt-get update -qq && apt-get install -y nodejs postgresql-client && \
  apt-get install ca-certificates && \
  git config --global url."https://github.com/".insteadOf git://github.com/ && \
  bundle config github.https true

WORKDIR /myorg
COPY Gemfile* /myorg

RUN bundle install -j4

WORKDIR /myorg
COPY . /myorg

RUN bundle exec rake assets:precompile

COPY entrypoint.sh /usr/bin/
RUN chmod +x /usr/bin/entrypoint.sh

ENTRYPOINT ["entrypoint.sh"]

EXPOSE 3000
CMD ["bundle", "exec",  "puma", "-C",  "./config/puma.rb"]

Second container:

FROM ruby:2.6.9-bullseye AS builder

ENV BUNDLE_WITHOUT='development:test'
ENV BUNDLE_PATH=vendor/bundle
ENV BUNDLE_BIN=vendor/bundle/bin
ENV BUNDLE_DEPLOYMENT=1
ENV BUNDLE_GLOBAL_PATH_APPENDS_RUBY_SCOPE=1


RUN apt-get update -qq && apt-get install -y nodejs postgresql-client && \
  apt-get install ca-certificates && \
  git config --global url."https://github.com/".insteadOf git://github.com/ && \
  bundle config github.https true

WORKDIR /myorg
COPY Gemfile* /myorg

RUN bundle install -j4

WORKDIR /myorg
COPY . /myorg

RUN bundle exec rake assets:precompile

COPY entrypoint.sh /usr/bin/
RUN chmod +x /usr/bin/entrypoint.sh

ENTRYPOINT ["entrypoint.sh"]

CMD ["bundle", "exec",  "rake", "resque:scheduler"]

Third container:

FROM ruby:2.6.9-bullseye AS builder

ENV BUNDLE_WITHOUT='development:test'
ENV BUNDLE_PATH=vendor/bundle
ENV BUNDLE_BIN=vendor/bundle/bin
ENV BUNDLE_DEPLOYMENT=1
ENV BUNDLE_GLOBAL_PATH_APPENDS_RUBY_SCOPE=1


RUN apt-get update -qq && apt-get install -y nodejs postgresql-client && \
  apt-get install ca-certificates && \
  git config --global url."https://github.com/".insteadOf git://github.com/ && \
  bundle config github.https true

WORKDIR /myorg
COPY Gemfile* /myorg

RUN bundle install -j4

WORKDIR /myorg
COPY . /myorg

RUN bundle exec rake assets:precompile

COPY entrypoint.sh /usr/bin/
RUN chmod +x /usr/bin/entrypoint.sh

ENTRYPOINT ["entrypoint.sh"]

CMD ["bundle", "exec", "rake", "resque:work"]