0

I want to setup crontab for sidekiq-cron from docker in rails. During build i was faced some issue like

  • no crontab for root How to resolve this issue? Here are my files to setup server with docker. i want this without whenever gem.

Docker File

FROM ruby:2.7.2
ENV RAILS_ROOT /var/www/quickcard
ENV BUNDLE_VERSION 2.1.4
ENV BUNDLE_PATH usr/local/bundle/gems
ENV RAILS_LOG_TO_STDOUT true
ENV RAILS_PORT 5000
COPY ./entrypoint.sh /usr/local/bin/entrypoint.sh
RUN chmod +x /usr/local/bin/entrypoint.sh
RUN curl -sS https://dl.yarnpkg.com/debian/pubkey.gpg | apt-key add -
RUN echo "deb https://dl.yarnpkg.com/debian/ stable main" | tee /etc/apt/sources.list.d/yarn.list
RUN apt-get update -qq && apt-get install -y build-essential \
git \
libxml2-dev \
libpq-dev \
libxslt-dev \
nodejs \
yarn \
imagemagick \
tzdata \
less \
cron \
&& rm -rf /var/cache/apk/*
RUN gem install bundler --version "$BUNDLE_VERSION"
RUN mkdir -p $RAILS_ROOT
WORKDIR $RAILS_ROOT
ADD Gemfile Gemfile
ADD Gemfile.lock Gemfile.lock
COPY yarn.lock yarn.lock
RUN bundle install
EXPOSE $RAILS_PORT
RUN ln -s $RAILS_ROOT/config/systemd/puma.service /etc/systemd/system/quickcard
COPY . .
RUN crontab -l | { cat; echo ""; } | crontab -
RUN yarn install
RUN yarn install --check-files
RUN ls /var/www/quickcard/public
ENTRYPOINT ["entrypoint.sh"]
CMD ["bundle", "exec", "puma", "-C", "config/puma.rb"]

Compose File

version: '2.2'
services:
  app:
    build: 
      context: .
      dockerfile: ./Dockerfile
    command: bash -c "bundle exec rails s -p 5000 -e production -b 0.0.0.0 &&  RAILS_ENV=production bundle exec rake assets:precompile"
    environment:
      RAILS_ENV: production
    volumes:
      - /var/wwww/quickcard
      - /var/wwww/quickcard/public
    ports:
      - 5000:5000
  sidekiq:
    build: .
    command: bundle exec sidekiq -C config/sidekiq.yml
    environment:
      RAILS_ENV: production
    volumes:
      - /var/wwww/quickcard/tmp
  cron_job:
    build: .
    command: cron -f
  nginx:
    build:
      context: .
      dockerfile: ./nginx.Dockerfile
    volumes:
      - ./log-nginx:/var/log/nginx/
    restart: always
    ports:
      - 80:80
      - 443:443

Any one here to help me to resolve this issue.

Saad Saddique
  • 81
  • 1
  • 4
  • There's quite a bit here; can you reduce this to a [mcve] (for example, do you have the same problem without the Node component or the Nginx container)? Which specific step or command or container output produces the error? – David Maze Jun 24 '22 at 21:37
  • (You've asked several similar questions with a very similar setup. Your `volumes:` blocks mostly do nothing at all and you can safely delete them. There's a typo in their filesystem paths, but if you changed that, the `volumes:` only effect would be to prevent changes in your application code from being visible when you rebuild your image.) – David Maze Jun 24 '22 at 22:19
  • Docker containers run one process only - in your case entrypoint.sh. Unless that starts a cron daemon do not expect one to be running inside the container. – Queeg Jun 26 '22 at 21:54
  • You could look at https://github.com/Ebbe/arask for an easier setup in docker. Disclaimer: I made it. – Esben Damgaard Aug 18 '22 at 11:48

0 Answers0