Connect Cloud SQL for MySql from Cloud Run - google-cloud-sql

I'm trying to connect to Google Cloud SQL for MySql through Google Cloud Run. I've been through many posts at SO and also the Google documentation. But doesn't seem to get it working for myself. I admit that I have never containerized any application and I am predominantly a data person.
Note: I already have Cloud SQL instance created which I can connect through Cloud shell.
1) My code is based on Google documentation at
https://cloud.google.com/sql/docs/mysql/connect-run
and the github code at
https://github.com/GoogleCloudPlatform/python-docs-samples/blob/master/cloud-sql/mysql/sqlalchemy/main.py
2) Build the image
gcloud builds submit --tag gcr.io/my-project/my-test-image
3) Deploy the image
gcloud run deploy --image gcr.io/my-project/my-test-image
4) When I try to invoke the service in Cloud Shell using the following, I get output as "Service Unavailable"
curl -H "Authorization: Bearer $(gcloud auth print-identity-token)" https://my-service.run.app
Can anyone please help me to resolve this?
Changes -
I had not provided the mysql instance name. I corrected it and now I'm getting error as below -
[INFO] Listening at: http://0.0.0.0:8080 (1)"
"Traceback (most recent call last): File
"/usr/local/lib/python3.8/site-packages/pymysql/connections.py", line
571, in connect
sock.connect(self.unix_socket) FileNotFoundError: [Errno 2] No such file or directory"
I don't understand why it's listening at 0.0.0.0:8080. I removed the host and port from my code and I still get this "info" and the error I get is that "FileNotFoundError". I'm not sure which file it needs. Does it need some kind of connections file? If yes what's the format of the file?

I wrote a tutorial on how to Connect Cloud SQL(MySql) from Cloud Run (Java), but the flow is the same. link
Please make sure you understand the point 13, where you have to pass the instance connection name with the flag --add-cloudsql-instances, this will start the cloud sql proxi for you.
13.Configure the service for use with Cloud Run
gcloud run services update run-mysql --add-cloudsql-instances run-to-sql:europe-west2:database-external --set-env-vars CLOUD_SQL_CONNECTION_NAME=run-to-sql:europe-west2:database-external DB_USER=user_name,DB_PASS=user_password,DB_NAME=user_database
SO link

Related

gcloud init generates bad url with 279.0.0

I installed a fresh gcloud sdk (in Azure Cloud Shell if it matters...)
chad#Azure:~$ gcloud --version
Google Cloud SDK 279.0.0
bq 2.0.53
core 2020.01.31
gsutil 4.47
I'm trying to run 'gcloud init' -- but the URL it renders does not work...
chad#Azure:~$ gcloud init
Welcome! This command will take you through the configuration of gcloud.
Your current configuration has been set to: [default]
You can skip diagnostics next time by using the following flag:
gcloud init --skip-diagnostics
Network diagnostic detects and fixes local network connection issues.
Checking network connection...done.
Reachability Check passed.
Network diagnostic passed (1/1 checks passed).
You must log in to continue. Would you like to log in (Y/n)?
Go to the following link in your browser:
https://accounts.google.com/o/oauth2/auth?code_challenge= I REMOVED
A BUNCH OF CODES HERE &scope=https%3A%2F%2Fwww.googleapis.com%2Fauth%2Fuserinfo.email+https3A%2F%2Fwww.googleapis.com%2Fauth%2Fcloud-platform+https%3A%2F%2Fwww.googleapis.com%2Fauth%2Fappengine.admin+https%3A%2%2Fwww.googleapis.com%2Fauth%2Fcompute+https%3A%2F%2Fwww.googleapis.com%2Fauth%2Faccounts.reauth
Enter verification code:
Am I missing something?
#John Hanley -- for the win!
Can't believe I didn't think of that -- thanks much.
Chad
p.s. looks like a bug in Azure Console or Windows Terminal truncating wrapped text...

Cloud SQL API [sql-component.googleapis.com] not enabled on project

I am running a cloud build trigger on a cloudbuid.yaml file in which I build a docker container and then deploy it to cloud run. The error stacktrace is as follows:
API [sql-component.googleapis.com] not enabled on project
The problem is that I have enabled both SQL and SQL Admin APIs in both projects (one for the cloud build and one for the database), which was confirmed in the console and in gcloud.
Here is the yaml code for the step I am referring to:
- name: 'gcr.io/cloud-builders/gcloud'
args: [
'beta',
'run',
'deploy',
'MY_NAME',
'--image', 'gcr.io/MY_PROJECT/MY_IMAGE',
'--region', 'MY_REGION',
'--platform', 'managed',
'--set-cloudsql-instances', 'MY_CONNECTION_NAME',
'--set-env-vars', 'NODE_ENV=production,INSTANCE_CONNECTION_NAME=MY_CONNECTION_NAME,SQL_USER=MY_USER,SQL_PASSWORD=MY_PASSWORD,SQL_NAME=MY_SCHEMA,TOPIC_NAME=MY_TOPIC'
]
Any suggestions?
Thanks.
P.S.: As per Eespinola suggestion, I checked and confirmed I am running Google Cloud SDK 254.0.0.
P.S. 2: I have also tried to create a project from scratch but ended up with the same results.
Ok so as per the same thread eespinola posted (see above), the Cloud Build gcloud step will be updated according to Cloud SDK 254.0.0 update in a near future (the actual date may or may not be posted in the same thread in the future). Until then, the alternative is to use the YAML file without the --add-cloudsql-instances flag and add it manually in the UI (I still have not tried this but it should work as per Google's development team).

Deploy API REST IBM Hyperledger Composer Blockchain (bad flag in substitute command: 'U' ERROR)

I'm getting this error trying to deploy a card to a working blockchain on cloud, any idea? Thanks in advance. I'm using a mac, following the guide (Kubernetes installed/configured well, I think):
https://ibm-blockchain.github.io/interacting/
./create/create_composer-rest-server.sh --paid --business-network-card /Users/sm/jsblock/tutorial-network/PeerAdmin#fabric-network.card
Configured to setup a paid storage on ibm-cs
Preparing yaml file for create composer-rest-server
sed: 1: "s/%COMPOSER_CARD%//User ...": bad flag in substitute command: 'U'
Creating composer-rest-server pod
Running: kubectl create -f /Users/sm/jsblock/ibm-container-service/cs-offerings/scripts/../kube-configs/composer-rest-server.yaml
error: no objects passed to create
Composer rest server created successfully
There is an error in that document. And you are also specifying the Peer Admin card when you need to use a Network Admin Card.
There are 2 sets of 'parallel' documents for paid and free clusters. The command you are using has --paid in it in error. If you remove --paid and use the Network Admin Card I think it will solve the problem.
Your command will look something like this: ./create/create_composer-rest-server.sh --business-network-card admin#YOUR-network
I tried again with the install proccess (deployed blockchain instance seemed to work weall): https://ibm-blockchain.github.io/simple/
But I noticed that the script:
./create_all.sh
...never ended (mostly an internal kubernetes problems I guess). And I reset the installation:
./delete_all.sh
./create_all.sh
I tried again, now everything Ok. I could get my awesome API REST talking with my Hyperledger Blockchain, deployed on IBM Cloud. Ready to develop something amazing.

Connection to a S3 instance using a service-connector

I'm trying to create a service-connector to my s3 instance like this:
cf service-connector 13001 mybucketname.ds31s3.swisscom.com:443
But I get the following error:
Server-Error 403: Check of security groups failed (no access)
I have created my service key according to this documentation.
Connecting to my MongoDB works perfectly using a service connector.
You can access Swisscom's S3 directly without the service connector.
The error message suggests that your current org and space do no have access to the S3. This is usually the case is there is no app-binding for that service in the current space. Please check whether you created your service key in the right org and space.
There was a misconfiguration due to security changes. We fixed the issue, so connecting to s3 with the service-connector should now work.

Error when deploying nodeBB application on Bluemix. How to fix it and deploy successfully?

I want to deploy NodeBB on Bluemix using Compose for Redis service. I follow the setup instructions at https://docs.nodebb.org/en/latest/installing/os/osx-mavericks.html
But when I push the app to Bluemix the application fails to start. I get an error. Please refer to link below.
Error on pushing nodeBB on Bluemix
However the nodeBB application runs fine on my local macbook.
How to resolve this error.Please let me know how to deploy nodeBB on Bluemix successfully?
The error indicates the public/uploads/sounds folder is not found on the staged application. It is not getting pushed along with the other application files.
This folder is used by the nodeBB application to copy sound files at runtime. To make sure that the empty public folder is pushed to Bluemix create a .cfignore file. Add the following line to it
!/public
The following errors can prevent the nodeBB application to run on Bluemix.
1) If the credential to Compose for Redis is not setup correctly OR the Compose of Redis is unavailable in Bluemix
For the Redis connection to setup properly create a Compose for Redis service in Bluemix. Then Copy the Redis credentials from the service credentials as shown below.
{
"db_type": "redis",
"name": "bmix_dal_yp_94747ceb_7c86_4319_b7be_88c2e9c829eb",
"uri_cli": "redis-cli -h sl-us-dal-9-portal.0.dblayer.com -p PORT -a PASSWORD”,
"deployment_id": "583e1bea52de460017000124",
"uri": "redis://admin: PASSWORD#sl-us-dal-9-portal.0.dblayer.com:PORT”
}
PORT represents Redis port number and PASSWORD represents Redis password
Use the credentials to update the config.json correctly when you run command ./nodebb setup [ on Unix or Mac]
Make sure Compose for Redis service is up and running. Otherwise you will get connection errors from the nodebb application when you start it.
2) If the port that the nodebb application can listen on Bluemix is not updated to app.js before pushing the application to Bluemix then it will cause the application to fail to start on Bluemix.
Update
nconf.set('port', urlObject.port || nconf.get('port') || nconf.get('PORT') || (nconf.get('PORT_ENV_VAR') ? nconf.get(nconf.get('PORT_ENV_VAR')) : false) || 4567);
TO
nconf.set('port', process.env.VCAP_APP_PORT || urlObject.port || nconf.get('port') || nconf.get('PORT') || (nconf.get('PORT_ENV_VAR') ? nconf.get(nconf.get('PORT_ENV_VAR')) : false) || 4567);
3) Make sure that the application runs on the local machine without any errors before pushing it to the Bluemix. Command : ./nodebb start OR node app.js
The instruction to setup and run nodeBB on local can be found here ttps://docs.nodebb.org/en/latest/installing/os/osx-mavericks.html