When I use the google cloud run service my docker container will return the error:
PG::ConnectionBad: could not connect to server: No such file or directory
Is the server running locally and accepting
connections on Unix domain socket "/var/run/postgresql/.s.PGSQL.5432"?
I've enabled the cloud sql admin api
on the relevant project. I ssh'ed into the instance that I was running with GCP services available in the google cloud shell, and checked /var/run/postgresql/.s.PGSQL.5432
. There was nothing available. Google cloud run docks say to set the designation for the socket to under /cloudsql/
, but no socket appears to exist there either.
Nothing in cloud sql/run open issues or the issue tracker suggests that this should be an issue.
Deploy command uses the --add-cloudsql-instances flag without error, so I believe there should be no issue there.
Relevant database.yml section:
staging:
adapter: postgresql
encoding: utf8
pool: 5
timeout: 5000
database: project_staging
username: project_staging
password: <%= Rails.application.credentials[:db_password] %>
socket: "/cloudsql/my-project-name:asia-northeast1:project-database-name/"
Dockerfile to set up the container -
FROM ruby:2.6.2
ARG environment
// Bunch of env code
RUN apt-get update -qq && apt-get install -y nodejs postgresql-client
RUN mkdir /myapp
WORKDIR /usr/src/app
RUN gem install bundler
COPY Gemfile Gemfile.lock ./
ENV BUNDLE_FROZEN=true
RUN bundle install
COPY . .
# Add a script to be executed every time the container starts.
COPY entrypoint.sh /usr/bin/
RUN chmod +x /usr/bin/entrypoint.sh
ENTRYPOINT ["entrypoint.sh"]
EXPOSE 3000
ENV RAILS_LOG_TO_STDOUT=true
Do I need to install more than just postgresql-client here?
Almost certainly irrelevant, but the start script:
cd /usr/src/app
bundle exec rake db:create
bundle exec rake db:migrate
# Do some protective cleanup
> log/${RAILS_ENV}.log
rm -f tmp/pids/server.pid
bundle exec rails server -e ${RAILS_ENV} -b 0.0.0.0 -p $PORT
I'm honestly baffled here. Is it a configuration issue? A cloud run issue? Am I missing some kind of package? I expected it to just connect to the socket without issue on boot.