I have a Rails app running locally with Docker and now I'm trying to deploy it to Google Cloud Platform using Cloud Run, following this great tutorial by Laurent Julliard.
I'm using following GCP services:
Cloud Build to build the container image.
Cloud Run for the deploy.
Cloud Storage for Rails Active Storage.
Cloud SQL for my Postgres DB.
Cloud Key Management Service for my secrets.
Last 3 services are not relevant for this issue (I think 🤷🏻♂️).
My deploy process has 2 steps:
Build the container image using Cloud Build
Deploy the image using Cloud Run
Build the container image using Cloud Build
cloudbuild.yaml file describe the steps Cloud Build has to go through to build your container.
steps:
# Decrypt Rails Master key file
- name: gcr.io/cloud-builders/gcloud
args: ["kms", "decrypt", "--ciphertext-file=./config/master.key.enc",
"--plaintext-file=./config/master.key",
"--location=us-central1","--keyring=whale-on-rails",
"--key=rails_master_key"]
# Decrypt Whale on Rails service account credentials
- name: gcr.io/cloud-builders/gcloud
args: ["kms", "decrypt", "--ciphertext-file=./config/whale_on_rails.key.enc",
"--plaintext-file=./config/whale_on_rails.key",
"--location=us-central1","--keyring=whale-on-rails",
"--key=whale_on_rails_key"]
# Build image with tag 'latest' and pass decrypted Rails DB password as argument
- name: 'gcr.io/cloud-builders/docker'
args: [ 'build',
'--tag', 'gcr.io/$PROJECT_ID/whale_on_rails:latest',
'--build-arg', 'DB_PWD',
'--build-arg', 'RUBY_VERSION=${_RUBY_VERSION}',
'--build-arg', 'PG_MAJOR=${_PG_MAJOR}',
'--build-arg', 'NODE_MAJOR=${_NODE_MAJOR}',
'--build-arg', 'YARN_VERSION=${_YARN_VERSION}',
'--build-arg', 'BUNDLER_VERSION=${_BUNDLER_VERSION}',
'--build-arg', 'RAILS_ENV=${_RAILS_ENV}',
'--build-arg', 'REDIS_URL=${_REDIS_URL}',
'--build-arg', 'DATABASE_HOST=${_DATABASE_HOST}',
'--build-arg', 'DATABASE_USER=${_DATABASE_USER}',
'--build-arg', 'DATABASE_NAME=${_DATABASE_NAME}',
'.'
]
secretEnv: ['DB_PWD']
env:
- RAILS_ENV=${_RAILS_ENV}
- REDIS_URL=redis://redis:6379/
- DATABASE_HOST=/cloudsql/whale-on-rails:us-central1:whale-on-rails-production
- DATABASE_USER=postgres
- DATABASE_NAME=whale-on-rails
# Push new image to Google Cloud Registry
- name: 'gcr.io/cloud-builders/docker'
args: ['push', 'gcr.io/$PROJECT_ID/whale_on_rails:latest']
secrets:
- kmsKeyName: projects/whale-on-rails/locations/us-central1/keyRings/whale-on-rails/cryptoKeys/db_pwd_key
secretEnv:
DB_PWD: "CiQArHLfBqlON9MNzM+eKp/Un/HJucmgUftgl5LkYBzvLjsXsaQSOQCBzWJBAh061i7dJrNhEQeWqJHgSkaJpRka9w9nxmbiFzHZ1fpXOm0d7FWAi/8v36EDXmWnxkYXsw=="
substitutions:
_RUBY_VERSION: '2.6.5'
_PG_MAJOR: '11'
_NODE_MAJOR: '12'
_YARN_VERSION: '1.13.0'
_BUNDLER_VERSION: '2.0.2'
_RAILS_ENV: production
_REDIS_URL: redis://redis:6379/
_DATABASE_HOST: /cloudsql/whale-on-rails:us-central1:whale-on-rails-production
_DATABASE_USER: postgres
_DATABASE_NAME: whale-on-rails
Dockerfile: this file is invoked by the ‘Build image’ step in Cloud Build.
ARG RUBY_VERSION
FROM ruby:$RUBY_VERSION
ARG PG_MAJOR
ARG NODE_MAJOR
ARG BUNDLER_VERSION
ARG YARN_VERSION
ARG RAILS_ENV
# Add PostgreSQL to sources list
RUN curl -sSL https://www.postgresql.org/media/keys/ACCC4CF8.asc | apt-key add - \
&& echo 'deb http://apt.postgresql.org/pub/repos/apt/ stretch-pgdg main' $PG_MAJOR > /etc/apt/sources.list.d/pgdg.list
# Add NodeJS to sources list
RUN curl -sL https://deb.nodesource.com/setup_$NODE_MAJOR.x | bash -
# Add Yarn to the sources list
RUN curl -sS https://dl.yarnpkg.com/debian/pubkey.gpg | apt-key add - \
&& echo 'deb http://dl.yarnpkg.com/debian/ stable main' > /etc/apt/sources.list.d/yarn.list
# Install dependencies
COPY .docker/dev/Aptfile /tmp/Aptfile
RUN apt-get update -qq && DEBIAN_FRONTEND=noninteractive apt-get -yq dist-upgrade && \
DEBIAN_FRONTEND=noninteractive apt-get install -yq --no-install-recommends \
build-essential \
postgresql-client-$PG_MAJOR \
nodejs \
yarn=$YARN_VERSION-1 \
$(cat /tmp/Aptfile | xargs) && \
apt-get clean && \
rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/* && \
truncate -s 0 /var/log/*log
# Create a directory for the app code
ENV APP_HOME=/usr/src/app
# RUN mkdir -p ${APP_HOME}
WORKDIR ${APP_HOME}
# Install production dependencies (Gems installation in
# local vendor directory)
COPY Gemfile Gemfile.lock ./
ENV BUNDLE_FROZEN=true
# Upgrade RubyGems and install required Bundler version
RUN gem update --system && \
gem install bundler:$BUNDLER_VERSION
RUN bundle install
ENV RAILS_ENV=$RAILS_ENV
ENV RAILS_SERVE_STATIC_FILES=true
ENV RAILS_LOG_TO_STDOUT=true
COPY . .
# Pre-compile Rails assets (master key needed)
RUN yarn install
RUN RAILS_ENV=production bundle exec rails assets:precompile
# Set Google App Credentials environment variable with Service Account
ENV GOOGLE_APPLICATION_CREDENTIALS=${APP_HOME}/config/whale_on_rails.key
# Database environment variables
ARG DATABASE_NAME
ARG DATABASE_HOST
ARG DATABASE_USER
ARG DB_PWD
ENV DATABASE_PASSWORD=$DB_PWD
ENV DATABASE_NAME=$DATABASE_NAME
ENV DATABASE_HOST=$DATABASE_HOST
ENV DATABASE_USER=$DATABASE_USER
RUN chmod +x ${APP_HOME}/.docker/script/entry
ENTRYPOINT ["/usr/src/app/.docker/script/entry"]
entrypoint
#!/usr/bin/env bash
cd /usr/src/app
# Create, migrate and seed the Rails production DB
bundle exec rails db:prepare
# Do some protective cleanup
> log/production.log
rm -f tmp/pids/server.pid
# Run the web service on container startup
bundle exec rails server -e production -b 0.0.0.0 -p $PORT
Finally, I'm using the following command to build the container.
$ gcloud builds submit --config cloudbuild.yaml
This process works great. The problem comes in the next step...
Deploy the image using Cloud Run
$ gcloud beta run deploy whale-on-rails --image gcr.io/$PROJECT_ID/whale_on_rails \ 4m 58s Ruby 2.6.5
--set-cloudsql-instances whale-on-rails-production \
--region us-central1 --allow-unauthenticated --platform managed
In this step, I get this error in terminal:
ERROR: (gcloud.beta.run.deploy) Cloud Run error: Container failed to start. Failed to start and then listen on the port defined by the PORT environment variable. Logs for this revision might contain more information.
And checking out Cloud Run logs, I get this:
2019-10-24 13:03:35.448 CEST<main>: warning: timer_create failed: Success, signals racy
2019-10-24 13:03:37.756 CEST=> Booting Puma
2019-10-24 13:03:37.756 CEST=> Rails 6.0.0 application starting in production
2019-10-24 13:03:37.756 CEST=> Run `rails server --help` for more startup options
2019-10-24 13:03:40.687 CESTExiting
2019-10-24 13:03:40.687 CEST(erb):21:in `<main>': undefined local variable or method `“config' for main:Object (NameError)
2019-10-24 13:03:40.687 CEST from /usr/local/lib/ruby/2.6.0/erb.rb:901:in `eval'
2019-10-24 13:03:40.687 CEST from /usr/local/lib/ruby/2.6.0/erb.rb:901:in `result'
2019-10-24 13:03:40.688 CEST from /usr/local/bundle/gems/activestorage-6.0.0/lib/active_storage/engine.rb:111:in `block (2 levels) in <class:Engine>'
2019-10-24 13:03:40.688 CEST from /usr/local/bundle/gems/activesupport-6.0.0/lib/active_support/lazy_load_hooks.rb:72:in `class_eval'
2019-10-24 13:03:40.688 CEST from /usr/local/bundle/gems/activesupport-6.0.0/lib/active_support/lazy_load_hooks.rb:72:in `block in execute_hook'
...
2019-10-24 13:03:40.689 CEST from /usr/src/app/bin/rails:9:in `<top (required)>'
2019-10-24 13:03:40.689 CEST from /usr/local/bundle/gems/spring-2.1.0/lib/spring/client/rails.rb:28:in `load'
2019-10-24 13:03:40.689 CEST from /usr/local/bundle/gems/spring-2.1.0/lib/spring/client/rails.rb:28:in `call'
2019-10-24 13:03:40.689 CEST from /usr/local/bundle/gems/spring-2.1.0/lib/spring/client/command.rb:7:in `call'
2019-10-24 13:03:40.689 CEST from /usr/local/bundle/gems/spring-2.1.0/lib/spring/client.rb:30:in `run'
2019-10-24 13:03:40.689 CEST from /usr/local/bundle/gems/spring-2.1.0/bin/spring:49:in `<top (required)>'
2019-10-24 13:03:40.689 CEST from /usr/local/bundle/gems/spring-2.1.0/lib/spring/binstub.rb:11:in `load'
2019-10-24 13:03:40.689 CEST from /usr/local/bundle/gems/spring-2.1.0/lib/spring/binstub.rb:11:in `<top (required)>'
2019-10-24 13:03:40.689 CEST from /usr/src/app/bin/spring:15:in `require'
2019-10-24 13:03:40.689 CEST from /usr/src/app/bin/spring:15:in `<top (required)>'
2019-10-24 13:03:40.689 CEST from bin/rails:3:in `load'
2019-10-24 13:03:40.689 CEST from bin/rails:3:in `<main>'
2019-10-24 13:03:41.492 CESTContainer called exit(1).
My question is, why I'm getting this error? Everything looks fine in the hole process and I've followed the tutorial step by step (the only difference is that they are using MySQL and here I'm using Postgres).
Related
I'm trying to run a repetitive task using the Whenever gem for my rails app. It is running in a Docker container created using Docker Compose and hosted on an Ubuntu server.
I can successfully create and update the crontab file using the Whenever gem but it doesn't seem to be executing the task.
The task I want to execute repetitively in the background while the app is running is:
rake searchkick:reindex CLASS=Property
I usually execute this command successfully from the terminal after creating a web run container using 'docker-compose run web bash'. This reindexes my ElasticSearch server using the searchkick gem.
The relevant versions are below:
- ruby 2.7.2p137
- rails (6.0.3.6)
- elasticsearch (6.8.3)
- elasticsearch-api (= 6.8.3)
- elasticsearch-transport (= 6.8.3)
- searchkick (4.4.4)
- activemodel (>= 5)
- elasticsearch (>= 6)
- hashie
- whenever (1.0.0)
- chronic (>= 0.6.3)
Cron is installed using the Dockerfile:
RUN apt-get update -qq && \
apt-get install -y curl \
build-essential \
libpq-dev \
cron \
vim \
nano \
postgresql \
postgresql-contrib \
postgresql-client
The Dockerfile runs a script when the container is created:
COPY entrypoint.sh /usr/bin/
RUN chmod +x /usr/bin/entrypoint.sh
ENTRYPOINT ["entrypoint.sh"]
EXPOSE 3000
The script (entrypoint.sh) creates a crontab file.
#!/bin/bash
set -e
# For development check if the gems as installed, if not, then uninstall them.
if ! [ bundle check ]; then
bundle install
fi
# Remove a potentially pre-existing server.pid for Rails.
rm -f /myapp/tmp/pids/server.pid
# Yarn - Check Files.
yarn install --check-files
# Create empty crontab file.
crontab -l | { cat; echo ""; } | crontab -
# Update crontab file using whenever command.
bundle exec whenever --set 'environment=production' --update-crontab
# Run the command - runs any arguments passed into this entrypoint file.
exec "$#"
The 'bundle exec whenever --set 'environment=production' --update-crontab' command above updates the crontab file as per the schedule.rb file below:
set :output, "log/cron_log.log"
env :PATH, ENV['PATH']
# Reindex Property records every 3 mins.
every 3.minutes do
rake "searchkick:reindex CLASS=Property"
end
I've also tried using this:
every 3.minutes do
command "cd /myapp && rake searchkick:reindex CLASS=Property"
end
When I execute 'docker-compose run web bash' to use the rails terminal, I see this response at the end:
no crontab for root
[write] crontab file updated
To check that it was created correctly, I view the crontab file in the rails app with 'crontab -l' and it shows:
# Begin Whenever generated tasks for: /myapp/config/schedule.rb at: 2021-04-24 13:07:12 +0000
PATH=/usr/local/bundle/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
0,3,6,9,12,15,18,21,24,27,30,33,36,39,42,45,48,51,54,57 * * * * /bin/bash -l -c 'cd /myapp && RAILS_ENV=production bundle exec rake searchkick:reindex CLASS=Property --silent >> log/cron_log.log 2>&1'
# End Whenever generated tasks for: /myapp/config/schedule.rb at: 2021-04-24 13:07:12 +0000
Update: After using cron service status and cron service start, the logs in myApp/log/cron_log.log show the following:
bundler: failed to load command: rake (/usr/local/bin/rake)
Bundler::GemNotFound: Could not find rake-13.0.3 in any of the sources
/usr/local/lib/ruby/2.7.0/bundler/spec_set.rb:86:in `block in materialize'
/usr/local/lib/ruby/2.7.0/bundler/spec_set.rb:80:in `map!'
/usr/local/lib/ruby/2.7.0/bundler/spec_set.rb:80:in `materialize'
/usr/local/lib/ruby/2.7.0/bundler/definition.rb:170:in `specs'
/usr/local/lib/ruby/2.7.0/bundler/definition.rb:237:in `specs_for'
/usr/local/lib/ruby/2.7.0/bundler/definition.rb:226:in `requested_specs'
/usr/local/lib/ruby/2.7.0/bundler/runtime.rb:101:in `block in definition_method'
/usr/local/lib/ruby/2.7.0/bundler/runtime.rb:20:in `setup'
/usr/local/lib/ruby/2.7.0/bundler.rb:149:in `setup'
/usr/local/lib/ruby/2.7.0/bundler/setup.rb:20:in `block in <top (required)>'
/usr/local/lib/ruby/2.7.0/bundler/ui/shell.rb:136:in `with_level'
/usr/local/lib/ruby/2.7.0/bundler/ui/shell.rb:88:in `silence'
/usr/local/lib/ruby/2.7.0/bundler/setup.rb:20:in `<top (required)>'
bundler: failed to load command: rake (/usr/local/bin/rake)
Bundler::GemNotFound: Could not find rake-13.0.3 in any of the sources
/usr/local/lib/ruby/2.7.0/bundler/spec_set.rb:86:in `block in materialize'
/usr/local/lib/ruby/2.7.0/bundler/spec_set.rb:80:in `map!'
/usr/local/lib/ruby/2.7.0/bundler/spec_set.rb:80:in `materialize'
/usr/local/lib/ruby/2.7.0/bundler/definition.rb:170:in `specs'
/usr/local/lib/ruby/2.7.0/bundler/definition.rb:237:in `specs_for'
/usr/local/lib/ruby/2.7.0/bundler/definition.rb:226:in `requested_specs'
/usr/local/lib/ruby/2.7.0/bundler/runtime.rb:101:in `block in definition_method'
/usr/local/lib/ruby/2.7.0/bundler/runtime.rb:20:in `setup'
/usr/local/lib/ruby/2.7.0/bundler.rb:149:in `setup'
/usr/local/lib/ruby/2.7.0/bundler/setup.rb:20:in `block in <top (required)>'
/usr/local/lib/ruby/2.7.0/bundler/ui/shell.rb:136:in `with_level'
/usr/local/lib/ruby/2.7.0/bundler/ui/shell.rb:88:in `silence'
/usr/local/lib/ruby/2.7.0/bundler/setup.rb:20:in `<top (required)>'
So it seems to have set up the crontab file and the cronjob is trying to run but it is not finding rake-13.0.3. I'm going to check if this is an issue with the bundler gem version versus what is in the gemfile.
Appreciate any help.
you can run cron to start cron service (linux) in your entrypoint.sh
# Update crontab file using whenever command.
cron && bundle exec whenever --set 'environment=production' --update-crontab
schedule don't know the gems path so the Bundler::GemNotFound error be throw, to solve this, you can avoid missing paths by setting all ENV in schedule.rb
set :output, "log/cron_log.log"
ENV.each { |k, v| env(k, v) }
# ...
I'm trying to setup pronto for Gitlab CI, locally everything works fine, but when pronto runs on Gitlab CI "Rugged::ReferenceError: revspec 'origin/master' not found" error raising
cache:
paths:
- vendor/
services:
- name: mysql:8.0
command: ["mysqld", "--character-set-server=utf8mb4", "--collation-server=utf8mb4_unicode_ci", "--default-authentication-plugin=mysql_native_password"]
variables:
MYSQL_DATABASE: $MYSQL_DATABASE
MYSQL_ROOT_PASSWORD: $MYSQL_ROOT_PASSWORD
DB_USERNAME: $DB_USERNAME
DB_HOST: $DB_HOST
DISABLE_SPRING: 1
before_script:
- cp config/database.yml.example config/database.yml
- apt-get update -qq && apt-get install -y -qq cmake
- gem install bundler --no-document
- bundle check || bundle install --path vendor --jobs $(nproc) "${FLAGS[#]}"
spec:
script:
- bundle exec rspec
pronto:
script:
- bundle exec pronto run -c origin/master --exit-code
Rugged::ReferenceError: revspec 'origin/master' not found
vendor/ruby/2.6.0/gems/pronto-0.10.0/lib/pronto/git/repository.rb:87:in `merge_base'
vendor/ruby/2.6.0/gems/pronto-0.10.0/lib/pronto/git/repository.rb:87:in `merge_base'
vendor/ruby/2.6.0/gems/pronto-0.10.0/lib/pronto/git/repository.rb:17:in `diff'
vendor/ruby/2.6.0/gems/pronto-0.10.0/lib/pronto.rb:62:in `run'
vendor/ruby/2.6.0/gems/pronto-0.10.0/lib/pronto/cli.rb:66:in `block in run'
vendor/ruby/2.6.0/gems/pronto-0.10.0/lib/pronto/cli.rb:64:in `chdir'
vendor/ruby/2.6.0/gems/pronto-0.10.0/lib/pronto/cli.rb:64:in `run'
vendor/ruby/2.6.0/gems/thor-0.20.3/lib/thor/command.rb:27:in `run'
vendor/ruby/2.6.0/gems/thor-0.20.3/lib/thor/invocation.rb:126:in `invoke_command'
vendor/ruby/2.6.0/gems/thor-0.20.3/lib/thor.rb:387:in `dispatch'
vendor/ruby/2.6.0/gems/thor-0.20.3/lib/thor/base.rb:466:in `start'
vendor/ruby/2.6.0/gems/pronto-0.10.0/bin/pronto:6:in `<top (required)>'
vendor/ruby/2.6.0/bin/pronto:23:in `load'
vendor/ruby/2.6.0/bin/pronto:23:in `<top (required)>'
I expect to run pronto on gitlab without Exceptions
I don't know if this is the best solution, but this worked for me:
In your gitlab repo, go to settings -> CI/CD
In the section General pipelines -> Git strategy for pipelines, mark the option git clone instead of git fetch
I also had to add a git fetch command just above the pronto invocation:
pronto:
script:
- git fetch
- bundle exec pronto run -c origin/master --exit-code
I'm trying to deploy a Rails 5 app to Elastic Beanstalk but I am getting the following error in my log file that appears to indicate that my home directory is not properly set.
I tried setting the HOME environment variable by setting HOME to ~/my-app-name but I have had no luck and it doesn't appear to be using the variable anyway. I set the variable under the software section in the environment configurations.
/var/log/eb-activity.log:
+ cd /var/app/ondeck
+ su -s /bin/bash -c 'bundle exec
/opt/elasticbeanstalk/support/scripts/check-for-rake-task.rb assets:precompile' webapp
`/home/webapp` is not a directory.
Bundler will use `/tmp/bundler/home/webapp' as your home directory temporarily.
+ '[' false == true ']'
+ su -s /bin/bash -c 'bundle exec rake assets:precompile' webapp
`/home/webapp` is not a directory.
Bundler will use `/tmp/bundler/home/webapp' as your home directory temporarily.
rake aborted!
Psych::SyntaxError: (<unknown>): did not find expected alphabetic or numeric
character while scanning an alias at line 83 column 22
/var/app/ondeck/config/environments/production.rb:96:in `block in <top (required)>'
/var/app/ondeck/config/environments/production.rb:1:in `<top (required)>'
/var/app/ondeck/config/environment.rb:5:in `<top (required)>'
/opt/rubies/ruby-2.5.3/bin/bundle:23:in `load'
/opt/rubies/ruby-2.5.3/bin/bundle:23:in `<main>'
Tasks: TOP => environment
(See full trace by running task with --trace) (Executor::NonZeroExitStatus)
I found a a similar issue here: issue deploying rails 5 application to AWS using Elastic Beanstalk due to rb-readline
I also asked another question yesterday about the psych error (posted link below) but I am beginning to think that this error may be caused due to the invalid reference to HOME. I'm rather lost at this point and have been working on this for several hours with absolutely no luck.
Another question I posted yesterday about the psych error:
Error Deploying on Elastic Beanstalk - Rails
Ruby: 2.7.0
Rails: 6.0.2.1
Solidus: v2.10.0
Just add the "commands" section below to your .ebextensions/packages.config
Add required commands:
# Setup linux packages
option_settings:
- option_name: BUNDLE_DISABLE_SHARED_GEMS
value: "1"
- option_name: BUNDLE_PATH
value: "vendor/bundle"
packages:
yum:
git: []
ImageMagick: []
ImageMagick-devel: []
openssl-devel: []
postgresql93-devel: []
commands:
01_node_get:
# run this command from /tmp directory
cwd: /tmp
# flag -y for no-interaction installation
command: 'curl --silent --location https://rpm.nodesource.com/setup_8.x | sudo bash -'
02_node_install:
# run this command from /tmp directory
cwd: /tmp
command: 'sudo yum -y install nodejs'
03_yarn_get:
# run this command from /tmp directory
cwd: /tmp
# don't run the command if yarn is already installed (file /usr/bin/yarn exists)
test: '[ ! -f /usr/bin/yarn ] && echo "yarn not installed"'
command: 'sudo wget https://dl.yarnpkg.com/rpm/yarn.repo -O /etc/yum.repos.d/yarn.repo'
04_yarn_install:
# run this command from /tmp directory
cwd: /tmp
test: '[ ! -f /usr/bin/yarn ] && echo "yarn not installed"'
command: 'sudo yum -y install yarn'
05_home_dir:
test: '[ ! -p /home/webapp ] && echo "webapp not exited"'
command: 'sudo mkdir -p /home/webapp'
06_grant_home_dir:
test: '[ ! -p /home/webapp ] && echo "webapp not exited"'
command: 'sudo chmod 777 /home/webapp'
source: https://medium.com/#tranduchanh.ms/deploy-and-manage-production-rails-5-app-with-aws-elastic-beanstalk-3efb0dfe021a
I'm trying to run sidekiq worker with Rails. When I try to docker-compose up worker I get the following error:
worker_1 | Error connecting to Redis on 127.0.0.1:6379 (Errno::ECONNREFUSED)
worker_1 | /home/app/Nyvur/vendor/bundle/ruby/2.2.0/gems/redis-3.2.2/lib/redis/client.rb:332:in `rescue in establish_connection'
worker_1 | /home/app/Nyvur/vendor/bundle/ruby/2.2.0/gems/redis-3.2.2/lib/redis/client.rb:318:in `establish_connection'
worker_1 | /home/app/Nyvur/vendor/bundle/ruby/2.2.0/gems/redis-3.2.2/lib/redis/client.rb:94:in `block in connect'
worker_1 | /home/app/Nyvur/vendor/bundle/ruby/2.2.0/gems/redis-3.2.2/lib/redis/client.rb:280:in `with_reconnect'
worker_1 | /home/app/Nyvur/vendor/bundle/ruby/2.2.0/gems/redis-3.2.2/lib/redis/client.rb:93:in `connect'
worker_1 | /home/app/Nyvur/vendor/bundle/ruby/2.2.0/gems/redis-3.2.2/lib/redis/client.rb:351:in `ensure_connected'
worker_1 | /home/app/Nyvur/vendor/bundle/ruby/2.2.0/gems/redis-3.2.2/lib/redis/client.rb:208:in `block in process'
worker_1 | /home/app/Nyvur/vendor/bundle/ruby/2.2.0/gems/redis-3.2.2/lib/redis/client.rb:293:in `logging'
worker_1 | /home/app/Nyvur/vendor/bundle/ruby/2.2.0/gems/redis-3.2.2/lib/redis/client.rb:207:in `process'
worker_1 | /home/app/Nyvur/vendor/bundle/ruby/2.2.0/gems/redis-3.2.2/lib/redis/client.rb:113:in `call'
worker_1 | /home/app/Nyvur/vendor/bundle/ruby/2.2.0/gems/redis-3.2.2/lib/redis.rb:211:in `block in info'
worker_1 | /home/app/Nyvur/vendor/bundle/ruby/2.2.0/gems/redis-3.2.2/lib/redis.rb:57:in `block in synchronize'
worker_1 | /usr/lib/ruby/2.2.0/monitor.rb:211:in `mon_synchronize'
worker_1 | /home/app/Nyvur/vendor/bundle/ruby/2.2.0/gems/redis-3.2.2/lib/redis.rb:57:in `synchronize'
worker_1 | /home/app/Nyvur/vendor/bundle/ruby/2.2.0/gems/redis-3.2.2/lib/redis.rb:210:in `info'
worker_1 | /home/app/Nyvur/vendor/bundle/ruby/2.2.0/gems/sidekiq-4.0.1/lib/sidekiq/cli.rb:71:in `block in run'
worker_1 | /home/app/Nyvur/vendor/bundle/ruby/2.2.0/gems/sidekiq-4.0.1/lib/sidekiq.rb:84:in `block in redis'
worker_1 | /home/app/Nyvur/vendor/bundle/ruby/2.2.0/gems/connection_pool-2.2.0/lib/connection_pool.rb:64:in `block (2 levels) in with'
worker_1 | /home/app/Nyvur/vendor/bundle/ruby/2.2.0/gems/connection_pool-2.2.0/lib/connection_pool.rb:63:in `handle_interrupt'
worker_1 | /home/app/Nyvur/vendor/bundle/ruby/2.2.0/gems/connection_pool-2.2.0/lib/connection_pool.rb:63:in `block in with'
worker_1 | /home/app/Nyvur/vendor/bundle/ruby/2.2.0/gems/connection_pool-2.2.0/lib/connection_pool.rb:60:in `handle_interrupt'
worker_1 | /home/app/Nyvur/vendor/bundle/ruby/2.2.0/gems/connection_pool-2.2.0/lib/connection_pool.rb:60:in `with'
worker_1 | /home/app/Nyvur/vendor/bundle/ruby/2.2.0/gems/sidekiq-4.0.1/lib/sidekiq.rb:81:in `redis'
worker_1 | /home/app/Nyvur/vendor/bundle/ruby/2.2.0/gems/sidekiq-4.0.1/lib/sidekiq/cli.rb:68:in `run'
worker_1 | /home/app/Nyvur/vendor/bundle/ruby/2.2.0/gems/sidekiq-4.0.1/bin/sidekiq:13:in `<top (required)>'
worker_1 | /home/app/Nyvur/vendor/bundle/ruby/2.2.0/bin/sidekiq:23:in `load'
worker_1 | /home/app/Nyvur/vendor/bundle/ruby/2.2.0/bin/sidekiq:23:in `<main>'
nyvur_worker_1 exited with code 1
Here's my docker-compose file:
web: &app_base
build: .
ports:
- "80:80"
volumes:
- .:/Nyvur
command: /usr/bin/start_server.sh
links:
- postgres
- mongo
- redis
environment: &app_environment
SIDEKIQ_CONCURRENCY: 50
SIDEKIQ_TIMEOUT: 10
ENABLE_DEBUG_SERVER: true
RACK_ENV: production
RAILS_ENV: production
worker:
build: .
volumes:
- .:/Nyvur
ports: []
links:
- postgres
- mongo
- redis
command: bundle exec sidekiq -c 50
postgres:
image: postgres:9.1
ports:
- "5432:5432"
environment:
LC_ALL: C.UTF-8
POSTGRES_DB: Nyvur_production
POSTGRES_USER: postgres
POSTGRES_PASSWORD: 3x1mpl3
mongo:
image: mongo:3.0.7
ports:
- "27017:27017"
redis:
image: redis
ports:
- "6379:6379"
My Dockerfile:
FROM phusion/passenger-customizable
MAINTAINER VodkaMD <support#nyvur.com>
ENV RACK_ENV="production" RAILS_ENV="production"
SECRET_KEY_BASE="e09afa8b753cb175bcef7eb5f737accd02a4c16d9b6e5d475943605abd4277cdf47c488812d21d9c7117efd489d876f34be52f7ef7e88b21759a079339b198ce"
ENV HOME /root
CMD ["/sbin/my_init"]
RUN /pd_build/utilities.sh
RUN /pd_build/ruby2.2.sh
RUN /pd_build/python.sh
RUN /pd_build/nodejs.sh
RUN /pd_build/redis.sh
RUN /pd_build/memcached.sh
RUN apt-get update && apt-get install -y vim nano dialog net-tools build-essential wget libpq-dev git
RUN apt-get clean && rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/*
# RUN mkdir /etc/nginx/ssl
# RUN openssl req -x509 -nodes -days 365 -newkey rsa:2048 -keyout /etc/nginx/ssl/nginx.key -out /etc/nginx/ssl/nginx.crt
RUN rm -f /etc/service/nginx/down
RUN rm -f /etc/service/redis/down
RUN rm -f /etc/service/sshd/down
RUN rm -f /etc/service/memcached/down
WORKDIR /tmp
ADD Gemfile /tmp/
ADD Gemfile.lock /tmp/
RUN mkdir /home/app/Nyvur
ADD . /home/app/Nyvur
RUN chown -R app:app /home/app/Nyvur
WORKDIR /home/app/Nyvur
RUN bundle install --deployment
RUN bundle exec rake assets:precompile
RUN rm /etc/nginx/sites-enabled/default
COPY config/nginx/nginx_nyvur.conf /etc/nginx/sites-enabled/nginx_nyvur.conf
ADD config/nginx/postgres-env.conf /etc/nginx/main.d/postgres-env.conf
ADD config/nginx/rails-env.conf /etc/nginx/main.d/rails-env.conf
ADD config/nginx/start_server.sh /usr/bin/start_server.sh
RUN chmod +x /usr/bin/start_server.sh
RUN mkdir -p /home/app/Nyvur/tmp/pids
RUN mkdir -p /home/app/Nyvur/tmp/sockets
RUN mkdir -p /home/app/Nyvur/log
RUN apt-get clean && rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/*
EXPOSE 80 443 9292
I've tried different configurations, I've checked other builds, but the problem still persists, So far, Sidekiq runs well outside of Docker.
Check if your redis server is running, start redis by using the following command in the terminal:
redis-server
Error connecting to Redis on 127.0.0.1:6379 (Errno::ECONNREFUSED)
Your app tries to connect on the localhost interface of the container it is running in, but redis is running in a different container.
Modify your app config to use the link name of the redis container (redis in your case) as hostname for the connection.
On macOS (using Homebrew), I was able to fix this by running:
brew services start redis
If you haven't yet installed redis, you'll need to run the following first:
brew install redis
I have solved this error using the following snippet
sudo apt install redis-server
and then by running the redis-server using —
redis-server
Redis quick review
Had a similar issue, in my case I have a script that starts redis and other initial settings and I forgot to run it. It usually breaks with CaS (Tomcat) but this time it broke due to redis and I had all but forgotten that was being setup by the script.
Anyway to complement other answers, a quick way to check if there are issues is to run
redis-cli
Which will let you know if redis is working and therefore help you remember if you need to run it.
If Redi isn't running you'll get a redis console:
redis-cli
Could not connect to Redis at 127.0.0.1:6379: Connection refused
not connected>
If it is running you'll get a redis console (in interactive mode), see documentation:
redis-cli
127.0.0.1:6379>
For example you can say: PING and it will return PONG
redis-cli
127.0.0.1:6379> PING
PONG
To run the Redis Server don't forget to just do:
redis-server
Just start your redis server by using redis-server command.
After start sidekiq
If you are using heroku and having such problem then you need to specify REDIS_PROVIDER_URL in your env
Make sure you installed redis-server on your system :-
sudo apt install redis-server
I don't succeed providing a dockerfile via Vagrant on Windows. If I use an image (e.g. d.image = "phusion/baseimage" instead of build_dir everything is fine - but when building from a dockerfile (as shown in the vagrantfile below) - I get the following error (of course I have a Dockerfile in infrastructure/ssh-docker!):
PS C:\privat\cloud-backup\cloud-backup-for-podio> vagrant up
Bringing machine 'app' up with 'docker' provider...
==> app: Docker host is required. One will be created if necessary...
app: Docker host VM is already ready.
==> app: Syncing folders to the host VM...
app: Preparing SMB shared folders...
app: Mounting SMB shared folders...
C:/HashiCorp/Vagrant/embedded/gems/gems/vagrant-1.7.4/plugins/guests/linux/cap/choose_addressable_ip_addr.rb:7:in `block
in choose_addressable_ip_addr': undefined method `each' for nil:NilClass (NoMethodError)
from C:/HashiCorp/Vagrant/embedded/gems/gems/vagrant-1.7.4/plugins/guests/linux/cap/choose_addressable_ip_addr.rb:6:in `tap'
from C:/HashiCorp/Vagrant/embedded/gems/gems/vagrant-1.7.4/plugins/guests/linux/cap/choose_addressable_ip_addr.rb:6:in `choose_addressable_ip_addr'
from C:/HashiCorp/Vagrant/embedded/gems/gems/vagrant-1.7.4/lib/vagrant/capability_host.rb:111:in `call'
from C:/HashiCorp/Vagrant/embedded/gems/gems/vagrant-1.7.4/lib/vagrant/capability_host.rb:111:in `capability'
...
Vagrantfile:
Vagrant.configure("2") do |config
config.ssh.username = 'vagrant'
config.ssh.password = 'tcuser'
config.ssh.port = 22
config.vm.define "app" do |app|
app.vm.synced_folder ".", "/vagrant", type: "smb", smb_host: "MY_IP", smb_username: "WINUSER#DOMAIN", smb_password: "WINPASSWORD"
app.vm.provider "docker" do |d|
#d.image = "phusion/baseimage"
d.build_dir = "infrastructure/ssh-docker"
d.name = "app"
d.remains_running = true
end
end
end
Dockerfile:
FROM phusion/baseimage
ENV HOME /root
# enable ssh
RUN rm -f /etc/service/sshd/down
# Regenerate SSH host keys. baseimage-docker does not contain any, so you
# have to do that yourself. You may also comment out this instruction; the
# init system will auto-generate one during boot.
RUN /etc/my_init.d/00_regen_ssh_host_keys.sh
# Use baseimage-docker's init system.
CMD ["/sbin/my_init"]
RUN apt-get update
RUN apt-get install -y openssh-server wget lsb-release sudo
EXPOSE 22
RUN mkdir -p /var/run/sshd
RUN chmod 0755 /var/run/sshd
# Create and configure vagrant user
RUN useradd --create-home -s /bin/bash vagrant
WORKDIR /home/vagrant
# Configure SSH access
RUN mkdir -p /home/vagrant/.ssh
RUN echo "ssh-rsa AAAAB3NzaC1yc2EAAAABIwAAAQEA6NF8iallvQVp22WDkTkyrtvp9eWW6A8YVr+kz4TjGYe7gHzIw+niNltGEFHzD8+v1I2YJ6oXevct1YeS0o9HZyN1Q9qgCgzUFtdOKLv6IedplqoPkcmF0aYet2PkEDo3MlTBckFXPITAMzF8dJSIFo9D8HfdOV0IAdx4O7PtixWKn5y2hMNG0zQPyUecp4pzC6kivAIhyfHilFR61RGL+GPXQ2MWZWFYbAGjyiYJnAmCP3NOTd0jMZEnDkbUvxhMmBYSdETk1rRgm+R4LOzFUGaHqHDLKLX+FIPKcF96hrucXzcWyLbIbEgE98OHlnVYCzRdK8jlqm8tehUc9c9WhQ== vagrant insecure public key" > /home/vagrant/.ssh/authorized_keys
RUN chown -R vagrant: /home/vagrant/.ssh
RUN echo -n 'vagrant:vagrant' | chpasswd
# Enable passwordless sudo for the "vagrant" user
RUN mkdir -p /etc/sudoers.d
RUN install -b -m 0440 /dev/null /etc/sudoers.d/vagrant
RUN echo 'vagrant ALL=NOPASSWD: ALL' >> /etc/sudoers.d/vagrant
# Clean up APT when done.
RUN apt-get clean && rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/*
Vagrant version: 1.7.4
Anyone has some idea?
(What I need to do is run a docker image from a dockerfile and have a shared/synced directory..)
You should provide your ip in for smb service
config.vm.synced_folder ".", "/home/vagrant/github-api", type: 'smb', smb_host: "192.168.1.100"