Host redmine to docker redmine ERROR Errno::ECONNRESET: Connection reset by peer - docker

I need a help from you. my task is dockerized my current redmine.
almost 2 week I am working on this task.
I copied public folder from host redmine to docker container redmine/public
I copied all plugins and installed successfully
but problem is image,my theme background image, wiki image is not disply.
I think my docker redmine is not find path to image.
any one know how to display image?
I will explain what step i do so far.
docker network create --driver bridge redmine_network
docker volume create postgres-data
docker volume create redmine-data
docker container run -d \
--name postgres \
--network redmine_network \
-v postgres-data:/var/lib/postgresql/data \
--restart always \
-e POSTGRES_PASSWORD='password' \
-e POSTGRES_DB='redmine' \
postgres:latest
docker container run -d \
--name redmine \
--network redmine_network \
-p 80:3000 \
--restart always \
-v redmine-data:/usr/src/redmine/files \
-e REDMINE_DB_POSTGRES='postgres' \
-e REDMINE_DB_DATABASE='redmine' \
-e REDMINE_DB_PASSWORD='password' \
redmine:latest
inside the container i install some package and gem for my plugins
docker exec -it redmine bash
apt update
apt install build-essential libpq-dev pkg-config libmagickwand-dev ruby ruby-dev
bundle install --no-deployment
gem install will_paginate
gem install jenkins_api_client
gem install activesupport -v 4.2.8
gem install haml-rails -v 1.0
gem install deface -v 1.0.2
gem install brakeman -v 4.8.0
bundle updates
docker redmine log file
Resolving dependencies...
The Gemfile's dependencies are satisfied
[2020-03-17 16:31:41] INFO WEBrick 1.3.1
[2020-03-17 16:31:41] INFO ruby 2.4.4 (2018-03-28) [x86_64-linux]
[2020-03-17 16:31:41] INFO WEBrick::HTTPServer#start: pid=1 port=3000
[2020-03-17 16:32:03] ERROR Errno::ECONNRESET: Connection reset by peer # io_fillbuf - fd:16
/usr/local/lib/ruby/2.4.0/webrick/httpserver.rb:82:in `eof?'
/usr/local/lib/ruby/2.4.0/webrick/httpserver.rb:82:in `run'
/usr/local/lib/ruby/2.4.0/webrick/server.rb:308:in `block in start_thread'
[2020-03-17 16:32:03] ERROR Errno::ECONNRESET: Connection reset by peer # io_fillbuf - fd:14
/usr/local/lib/ruby/2.4.0/webrick/httpserver.rb:82:in `eof?'
/usr/local/lib/ruby/2.4.0/webrick/httpserver.rb:82:in `run'
/usr/local/lib/ruby/2.4.0/webrick/server.rb:308:in `block in start_thread'
[2020-03-17 16:32:08] ERROR Errno::ECONNRESET: Connection reset by peer # io_fillbuf - fd:19
/usr/local/lib/ruby/2.4.0/webrick/httpserver.rb:82:in `eof?'
/usr/local/lib/ruby/2.4.0/webrick/httpserver.rb:82:in `run'
/usr/local/lib/ruby/2.4.0/webrick/server.rb:308:in `block in start_thread'
[2020-03-17 16:32:08] ERROR Errno::ECONNRESET: Connection reset by peer # io_fillbuf - fd:13
/usr/local/lib/ruby/2.4.0/webrick/httpserver.rb:82:in `eof?'
/usr/local/lib/ruby/2.4.0/webrick/httpserver.rb:82:in `run'
/usr/local/lib/ruby/2.4.0/webrick/server.rb:308:in `block in start_thread'
[2020-03-17 16:32:08] ERROR Errno::ECONNRESET: Connection reset by peer # io_fillbuf - fd:18
/usr/local/lib/ruby/2.4.0/webrick/httpserver.rb:82:in `eof?'
/usr/local/lib/ruby/2.4.0/webrick/httpserver.rb:82:in `run'
/usr/local/lib/ruby/2.4.0/webrick/server.rb:308:in `block in start_thread'
[2020-03-17 16:32:09] ERROR Errno::ECONNRESET: Connection reset by peer # io_fillbuf - fd:16
/usr/local/lib/ruby/2.4.0/webrick/httpserver.rb:82:in `eof?'
/usr/local/lib/ruby/2.4.0/webrick/httpserver.rb:82:in `run'
/usr/local/lib/ruby/2.4.0/webrick/server.rb:308:in `block in start_thread'
[2020-03-17 16:32:09] ERROR Errno::ECONNRESET: Connection reset by peer # io_fillbuf - fd:14
/usr/local/lib/ruby/2.4.0/webrick/httpserver.rb:82:in `eof?'
/usr/local/lib/ruby/2.4.0/webrick/httpserver.rb:82:in `run'
/usr/local/lib/ruby/2.4.0/webrick/server.rb:308:in `block in start_thread'
anyone could explain how to clear this error.. please

I want to make docker redmine same like my host redmine.
i can explain what i did so far.
create docker containers for redmine 3.4.4 and postgresql:latest with network and volume for each container
https://medium.com/#gurayy/setting-up-redmine-with-docker-be110387ba1c
install package and gem in redmine container
copy /public folder to docker redmine:/usr/src/redmine
copy all plugins to docker redmine:/usr/src/redmine/plugins
install plugins
bundle exec rake redmine:plugins NAME=readme_at_repositories RAILS_ENV=production
docker container restart redmine
check everything work fine
make a pg_dump from my host machine
/usr/bin/pg_dump -U postgres -h localhost -W -F -T --file=/tmp/redminedata.sqlc projectportal
enter to my postgresql container and restore my database
pg_restore -c -U postgres -h postgres -d projectportal /tmp/redminedata.sqlc
restart redmine container and I check again redmine in browser
when I check my redmine .png and .jpg files not working (not showing)
all data are migrated but image are missing and my theme background image .
enter image description here

Related

Rails Whenever gem not executing repetitive crontab task with Ubuntu and Docker Compose

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) }
# ...

How do I set up rails app in docker thats already been developed

Im new to using docker and I cant seem to get the app to build and make correctly. I'm sure its some easy DB setup or PG gem config.
Here's the output after trying to
=> Booting Puma
=> Rails 4.2.10 application starting in development on http://0.0.0.0:3000
=> Run rails server -h for more startup options
=> Ctrl-C to shutdown server
Exiting
/usr/local/bundle/gems/activerecord-4.2.10/lib/active_record/connection_adapters/connection
_specification.rb:177:in `rescue in spec': Specified 'postgresql' for database adapter, but
the gem is not loaded. Add `gem 'pg'` to your Gemfile (and ensure its version is at the mi
nimum required by ActiveRecord). (Gem::LoadError)
from /usr/local/bundle/gems/activerecord-4.2.10/lib/active_record/connection_adapte
rs/connection_specification.
rb:174:in `spec'
from /usr/local/bundle/gems/activerecord-4.2.10/lib/active_record/connection_handli
ng.
rb:50:in `establish_connection'
from /usr/local/bundle/gems/activerecord-4.2.10/lib/active_record/railtie.rb:122:in
`block (2 levels) in <class:Railtie>'
from /usr/local/bundle/gems/activesupport-4.2.10/lib/active_support/lazy_load_hooks
.rb:38:in `instance_eval'
from /usr/local/bundle/gems/activesupport-4.2.10/lib/active_support/lazy_load_hooks
.rb:38:in `execute_hook'
from /usr/local/bundle/gems/activesupport-4.2.10/lib/active_support/lazy_load_hooks
.rb:28:in `block in on_load'
from /usr/local/bundle/gems/activesupport-4.2.10/lib/active_support/lazy_load_hooks
.rb:27:in `each'
from /usr/local/bundle/gems/activesupport-4.2.10/lib/active_support/lazy_load_hooks
.rb:27:in `on_load'
from /usr/local/bundle/gems/activerecord-4.2.10/lib/active_record/railtie.
rb:118:in
`block in <class:Railtie>'
from /usr/local/bundle/gems/railties-4.2.10/lib/rails/initializable.rb:30:in `insta
nce_exec'
from /usr/local/bundle/gems/railties-4.2.10/lib/rails/initializable.rb:30:in `run'
from /usr/local/bundle/gems/railties-4.2.10/lib/rails/initializable.rb:55:in `block
in run_initializers'
from /usr/local/lib/ruby/2.4.0/tsort.
rb:228:in `block in tsort_each'
from /usr/local/lib/ruby/2.4.0/tsort.
rb:350:in `block (2 levels) in each_strongly_connected_component'
from /usr/local/lib/ruby/2.4.0/tsort.
rb:431:in `each_strongly_connected_component_from'
from /usr/local/lib/ruby/2.4.0/tsort.
rb:349:in `block in each_strongly_connected_component'
from /usr/local/lib/ruby/2.4.0/tsort.
rb:347:in `each'
from /usr/local/lib/ruby/2.4.0/tsort.
rb:347:in `call'
from /usr/local/lib/ruby/2.4.0/tsort.
rb:347:in `each_strongly_connected_component'
from /usr/local/lib/ruby/2.4.0/tsort.
rb:226:in `tsort_each'
from /usr/local/lib/ruby/2.4.0/tsort.
rb:205:in `tsort_each'
from /usr/local/bundle/gems/railties-4.2.10/lib/rails/initializable.
rb:54:in `run_initializers'
from /usr/local/bundle/gems/railties-4.2.10/lib/rails/application.
rb:352:in `initia
lize!'
from /app/config/environment.rb:7:in `<top (required)>'
from /usr/local/bundle/gems/activesupport-4.2.10/lib/active_support/dependencies.
rb:274:in `require'
from /usr/local/bundle/gems/activesupport-4.2.10/lib/active_support/dependencies.
rb:274:in `block in require'
from /usr/local/bundle/gems/activesupport-4.2.10/lib/active_support/dependencies.
rb:240:in `load_dependency'
from /usr/local/bundle/gems/activesupport-4.2.10/lib/active_support/dependencies.rb
:274:in `require'
from /app/config.ru:3:in `block in <main>'
from /usr/local/bundle/gems/rack-1.6.12/lib/rack/builder.rb:55:in `instance_eval'
from /usr/local/bundle/gems/rack-1.6.12/lib/rack/builder.rb:55:in `initialize'
from /app/config.ru:in `new'
from /app/config.ru:in `<main>'
from /usr/local/bundle/gems/rack-1.6.12/lib/rack/builder.
rb:49:in `eval'
from /usr/local/bundle/gems/rack-1.6.12/lib/rack/builder.
rb:49:in `new_from_string'
from /usr/local/bundle/gems/rack-1.6.12/lib/rack/builder.
rb:40:in `parse_file'
from /usr/local/bundle/gems/rack-1.6.12/lib/rack/server.
rb:300:in `build_app_and_op
tions_from_config'
from /usr/local/bundle/gems/rack-1.6.12/lib/rack/server.
rb:209:in `app'
from /usr/local/bundle/gems/railties-4.2.10/lib/rails/commands/server.
rb:61:in `app
'
from /usr/local/bundle/gems/rack-1.6.12/lib/rack/server.rb:337:in `wrapped_app'
from /usr/local/bundle/gems/railties-4.2.10/lib/rails/commands/server.
rb:139:in `lo
g_to_stdout'
from /usr/local/bundle/gems/railties-4.2.10/lib/rails/commands/server.
rb:78:in `start'
from /usr/local/bundle/gems/railties-4.2.10/lib/rails/commands/commands_tasks.
rb:80
:in `block in server'
from /usr/local/bundle/gems/railties-4.2.10/lib/rails/commands/commands_tasks.
rb:75:in `tap'
from /usr/local/bundle/gems/railties-4.2.10/lib/rails/commands/commands_tasks.
rb:75
:in `server'
from /usr/local/bundle/gems/railties-4.2.10/lib/rails/commands/commands_tasks.
rb:39
:in `run_command!'
from /usr/local/bundle/gems/railties-4.2.10/lib/rails/commands.
rb:17:in `<top (requ
ired)>'
from bin/rails:4:in `require'
from bin/rails:4:in `<main>'
Dockerfile
FROM ruby:2.4.2-alpine
# Open port 3000 to access the Rails applications
# This does not belong in production as a reverse proxy should route to the application internally
EXPOSE 3000
# Starting command line arguments wrapped in `bundle exec`
ENTRYPOINT ["bundle", "exec"]
# Required pager to using irb or rails console within container
ENV PAGER="busybox less"
# Start Rails server by default bound to 0.0.0.0:3000 of the container
CMD ["rails", "server", "-p", "3000", "-b", "0.0.0.0"]
# Create main application directory
RUN mkdir /app
# Copy all contents of the current directory to the main application directory
COPY . /app
# Set the working directory to the main application directory
WORKDIR /app
# Install required system libraries, latest version of bundle and fetch all dependencies
RUN rm -f /app/tmp/pids/server.pid \
&& apk add --no-cache --verbose \
bash \
build-base \
ca-certificates \
gcc \
git \
libffi-dev \
libxml2 \
libxml2-dev \
libxslt \
libxslt-dev \
nodejs \
patch \
postgresql-dev \
ruby \
ruby-dev \
tzdata \
&& gem install bundler --pre \
&& gem install tzinfo:1.2.2 tzinfo-data \
&& gem install nokogiri --version 1.8.1 -- --use-system-libraries --with-xml2-config=/usr/local/bin/xml2-config --with-xslt-config=/usr/local/bin/xslt-config \
&& bundle install
# Once the container is built, run it using the following:
# > docker run --detach <image-name-or-hash>
# This will run the container and start Rails as follows from the application directory:
# > bundle exec rails server -p 3000 -b 0.0.0.0
# If you want to run something different like the Rails console:
# > docker run --interactive -tty <image-name-or-hash> rails console
# This will run the conatiner and start the Rails console as follows from the application directory:
# > bundle exec rails console
The error says you're missing the pg gem while you've defined the database adapter to postgresql in the config/database.yml file.
The question title says "already been developed" so I guess your Gemfile has the gem 'pg' line, and your Gemfile.lock has also a line referring to the version to install ... but can you check? :)
Then you're not sharing your Dockerfile so it's harder to guess what's your issue, but I would bet on a missing bundle install command in the Dockerfile.
Be sure to have a line like that in your Dockerfile:
RUN bundle install
In the case this doesn't help, please update your question with your Dockerfile.
I think is easy to use docker to avoid to install anything in your development environment.
Usually, I use docker to do that, I use a container exposing the ports of the service like I have the service installed in my machine. Doing that, I am avoiding to install any additional services.
If you want to use a few services in your environment, you can find containers for anything, but if you need to build your own image you need to learn more about docker.
And for example, to use postgres I use a docker-compose.yml like that:
version: '3'
services:
postgres:
image: postgres:alpine
ports:
- "5432:5432"
volumes:
- pg-data:/var/lib/postgresql/data
volumes:
pg-data: {}

Unable to deploy Rails app into Google Cloud Run

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).

Sidekiq Error connecting to Redis on 127.0.0.1:6379 (Errno::ECONNREFUSED) on docker-compose

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

Error when running jekyll docker container with boot2docker on Mac

I am running docker on my MBP (Yosemite 10.10.3) with boot2docker (v1.6.2). When I try to run docker run --rm -v "$PWD:/src" grahamc/jekyll build (without sudo) I got the following error:
twer$ $(boot2docker shellinit 2> /dev/null)
twer$ docker run --rm -v "$PWD:/src" grahamc/jekyll build
/usr/local/bundle/gems/bundler-1.9.9/lib/bundler/spec_set.rb:92:in `block in materialize': Could not find coffee-script-source-1.9.1 in any of the sources (Bundler::GemNotFound)
from /usr/local/bundle/gems/bundler-1.9.9/lib/bundler/spec_set.rb:85:in `map!'
from /usr/local/bundle/gems/bundler-1.9.9/lib/bundler/spec_set.rb:85:in `materialize'
from /usr/local/bundle/gems/bundler-1.9.9/lib/bundler/definition.rb:132:in `specs'
from /usr/local/bundle/gems/bundler-1.9.9/lib/bundler/definition.rb:177:in `specs_for'
from /usr/local/bundle/gems/bundler-1.9.9/lib/bundler/definition.rb:166:in `requested_specs'
from /usr/local/bundle/gems/bundler-1.9.9/lib/bundler/environment.rb:18:in `requested_specs'
from /usr/local/bundle/gems/bundler-1.9.9/lib/bundler/runtime.rb:13:in `setup'
from /usr/local/bundle/gems/bundler-1.9.9/lib/bundler.rb:122:in `setup'
from /usr/local/bundle/gems/jekyll-2.5.3/lib/jekyll/plugin_manager.rb:37:in `require_from_bundler'
from /usr/local/bundle/gems/jekyll-2.5.3/bin/jekyll:16:in `<top (required)>'
from /usr/local/bundle/bin/jekyll:23:in `load'
Please help.
It's working fine on my machine:
$ docker run --rm -v "$PWD:/src" -p 4000:4000 grahamc/jekyll serve -H 0.0.0.0
Configuration file: /src/_config.yml
Source: /src
Destination: /src/_site
Generating...
Build Warning: Layout 'nil' requested in atom.xml does not exist.
Build Warning: Layout 'none' requested in feed.xml does not exist.
done.
Auto-regeneration: enabled for '/src'
Configuration file: /src/_config.yml
Server address: http://0.0.0.0:4000/
Server running... press ctrl-c to stop.
My best guess is that you have a Gemfile in your source code.

Resources