前提・実現したいこと
現在、APIサーバーをGAEで立てようとしています。
このチュートリアル(https://cloud.google.com/endpoints/docs/openapi/get-started-app-engine?hl=ja)を
Ruby言語を選んで、参考にしながらとりあえず立てることができたのですが、
このチュートリアル(https://cloud.google.com/appengine/docs/flexible/ruby/using-cloud-sql#before_you_begin)をやっていて
DBに接続するところで詰まってしまいました。
cloud_sql_proxyを使ってローカルからDB接続することは成功したのですが、
gaeにdeployするとエラーでデプロイできなくなってしまったので、そのデプロイで出るエラーを解決したいです。
※DBはGCP内ではありますが別プロジェクトにあります
発生している問題・エラーメッセージ
209e729f8486: Layer already exists b31a4422279c: Pushed fe8739e9df49: Pushed 6fb446f7ac33: Pushed latest: digest: sha256:c899761948f5c9a3a3d1179dcf76bd1df44ad36934d8b109c6ce7c4f5f42914e size: 2206 DONE ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- Updating service [default] (this may take several minutes)...failed. ERROR: (gcloud.beta.app.deploy) Error Response: [9] Application startup error: /app/vendor/bundle/ruby/2.3.0/gems/mysql2-0.5.2/lib/mysql2/client.rb:90:in `connect': Mysql2::Error::ConnectionError: Can't connect to local MySQL server through socket '/cloudsql/xxxxxx:asia-northeast1:xxxxxxxxx' (2) (Sequel::DatabaseConnectionError) from /app/vendor/bundle/ruby/2.3.0/gems/mysql2-0.5.2/lib/mysql2/client.rb:90:in `initialize' from /app/vendor/bundle/ruby/2.3.0/gems/sequel-5.11.0/lib/sequel/adapters/mysql2.rb:44:in `new' from /app/vendor/bundle/ruby/2.3.0/gems/sequel-5.11.0/lib/sequel/adapters/mysql2.rb:44:in `connect' from /app/vendor/bundle/ruby/2.3.0/gems/sequel-5.11.0/lib/sequel/connection_pool.rb:127:in `make_new' from /app/vendor/bundle/ruby/2.3.0/gems/sequel-5.11.0/lib/sequel/connection_pool/threaded.rb:206:in `assign_connection' from /app/vendor/bundle/ruby/2.3.0/gems/sequel-5.11.0/lib/sequel/connection_pool/threaded.rb:138:in `acquire' from /app/vendor/bundle/ruby/2.3.0/gems/sequel-5.11.0/lib/sequel/connection_pool/threaded.rb:90:in `hold' from /app/vendor/bundle/ruby/2.3.0/gems/sequel-5.11.0/lib/sequel/database/connecting.rb:253:in `synchronize' from /app/vendor/bundle/ruby/2.3.0/gems/sequel-5.11.0/lib/sequel/database/connecting.rb:279:in `test_connection' from /app/vendor/bundle/ruby/2.3.0/gems/sequel-5.11.0/lib/sequel/database/connecting.rb:58:in `connect' from /app/vendor/bundle/ruby/2.3.0/gems/sequel-5.11.0/lib/sequel/core.rb:116:in `connect' from /app/vendor/bundle/ruby/2.3.0/gems/sequel-5.11.0/lib/sequel/core.rb:394:in `adapter_method' from /app/vendor/bundle/ruby/2.3.0/gems/sequel-5.11.0/lib/sequel/core.rb:401:in `block (2 levels) in def_adapter_method' from app.rb:29:in `<main>'
該当のソースコード
Ruby
1require "base64" 2require "json" 3require "sinatra" 4require "sequel" 5require 'dotenv' 6 7Dotenv.load 8 9DB = Sequel.mysql2 user: ENV["MYSQL_USER"], 10 password: ENV["MYSQL_PASSWORD"], 11 database: ENV["MYSQL_DATABASE"], 12 socket: ENV["MYSQL_SOCKET_PATH"]
※MYSQL_SOCKET_PATHは /cloudsql/<インスタンス接続名>
試したこと
これから同プロジェクトにDBがあったらつながるのか?を試します。
補足情報(FW/ツールのバージョンなど)
ここにより詳細な情報を記載してください。
回答1件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。