GCP Cloud Run & Cloud Sql Connection

Hey all,

I’m wondering if anyone has deployed a docker hosting project to Cloud Run on GCP. I have been able to deploy the web app, but connecting to the Cloud Sql (MySql) instance I also have has been an absolute nightmare.

According to the docs, I need the following in my server.js:

const createUnixSocketPool = async config => {
  const dbSocketPath = process.env.DB_SOCKET_PATH || '/cloudsql';

  // Establish a connection to the database
  return await mysql.createPool({
    user: process.env.DB_USER, // e.g. 'my-db-user'
    password: process.env.DB_PASS, // e.g. 'my-db-password'
    database: process.env.DB_NAME, // e.g. 'my-database'
    // If connecting via unix domain socket, specify the path
    socketPath: `${dbSocketPath}/${process.env.CLOUD_SQL_CONNECTION_NAME}`,
    // Specify additional properties here.
    ...config,
  });
};

The only problem is, the server.js, and even the index.js in our Wappler projects is very different to any of the examples from what seems like the entire interwebs.

All environment variables (process.env.DB_USER, process.env.DB_NAME etc…) are set in the Environment Variables on the run instance using Cloud Secrets.

I suppose my question is, do I need to be adding this connection information somewhere else in my Wappler project? And can Wappler projects connect through the Unix socket the documentation says I need to connect through? socketPath: `${dbSocketPath}/${process.env.CLOUD_SQL_CONNECTION_NAME}?

Community Page
Last updated: