I'm giving a try to the openshift platform but I don't get how to configure it to use my local database instance (mySql, postgres, mongodb...) when doing local testing
Should I use environment variables like OPENSHIFT__DB_HOST in my local machine?
Could I use maven profiles or something like that to use a different datasource depending on the environment?
thanks
I have a python/mongodb app. I use
import os
if 'OPENSHIFT_DATA_DIR' in os.environment :
use Openshift's environment variables to setup database connection
else
use local DB or connect to OPenshift DB via port forward
To tell if I'm running on OPENSHIFT or my local PC system.
I have have two separate databases. My local small one for testing and the actual one on OPENSHIFT.
If on OPENSHIFT I just use their environment variables. If on my pc I just connect to my local development database.
You could also use port forward command 'rhc port -forward -a ' and then connect to your OPENSHIFT DB instance. You still would have to determine if your are local or OPENSHIFT to connect correctly.
Related
I am working on a job interview exercise to create a React CRUD application and a PHP API that accesses a mySQL database. The work is to be done on their work server environment that I have to SSH into.
How do I choose which port of their that I want my API to "live" on and then run it so that it accesses their phpmyadmin mySQL server? Then my React application must then run and access the API. They have given me their phpmyadmin port, and a port to use for my UI, and say I must choose the API port.
I was able to create the React app and API on my local machine and have it access my own local my phpmyadmin mySQL running on my local WAMP server. However when trying to run it on their remote environment I ran into a few problems. One of them I believe was running the PHP API through SSH. Do I have to set up tunneling or something? How can I run them both through SSH and have them know which ports theirs to use?
Do you foresee any other potential issues I have not mentioned? More details inc.
Thanks
I created an ASP.NET Core Web API using VS2017. After that I enabled the Docker support for my application.
Next, I was implemented the EF Core feature. After that I tested application locally then it’s working fine, database also created. But whenever I run the application inside local Docker or local Kubernetes the application won't work properly as I expected. because I used the Local SQL Server so, whatever the container running inside either Docker or Kubernetes it doesn't know the SQL Server or SQL Server database.
Can anyone suggest how to use the local database in the container running inside either Docker or Kubernetes?
You need to give the host's IP. In linux, you can use "host.docker.internal" hostname to connect to the host machine. It is supposedly working in Windows, however it has many, many, far too many problems in Windows.
If this hostname does not work for you, you have 2 IP addresses. One is the docker's gateway, that should start with 10...* or 172...* depending on how you set it up. Normally to learn this one, use docker inspect <container> and you can see the default gateway in the network section. However, Kubernetes might change these and it might be providing a better means to access the host. I did not use Kubernetes, so I don't know.
The other option is to use the IP address of the host, assigned by your network using DHCP. It should normally start with 192.168...
Your containers should be able to access applications on your host using these IP addresses. If the problem persists, turn off your firewall, and try pinging from inside the containers.
So Im following the google ruby guide to create and setup a cloud sql instance. Under 'Create and configure a Cloud SQL instance' step 4 it tells you to allow all network fields so the instance is open to all traffic, then underneath that it gives the warning:
This configuration leaves your Cloud SQL instance open to traffic from everyone, everywhere. It is used only for demonstration purposes. In production environments, restrict access to only those IP addresses that need access.
I haven't setup VM servers on a cloud environment before so I have no idea on what IP addresses I should be giving access to the SQL instance or what ones 'need access' do I just change it to the IP of my VMs?
In the context of the guide that you linked, the IP whitelist is necessary so you can access your Cloud SQL instance from your development server on your local computer. For that specific purpuse, you can just whitelist your computer's IP (see http://www.whatsmyip.org) instead off all the world.
When your application is going to be running on App Engine, you don't need to whitelist the IP. There is a separate access control list for that in the Cloud Console where you can list the App Engine applications authorized to connect.
I have just started with google appengine. I am developing an app in php. If I wanted to see the result, I used
dev_appserver.py ./ --php_executable_path /usr/bin/php5-cgi
(It doesn't work without the --php_executable_path parameter for me)
It works fine, except I cannot connect to the cloud sql instance. I read this https://cloud.google.com/appengine/docs/php/cloud-sql and tried to connect to the cloud sql by:
$sql = new mysqli(null,
'root', // username
'', // password
,
null,
'/cloudsql/:'
);
If I deploy something to appengine, this works, but what should I do, if I need to debug the app localy and it depends on the database?
#DTing's answer is correct that Google's docs encourage you to use a local MySQL from the local development server and recommend that pattern.
However, if you disagree and want to run the development server against your "production" SQL in the cloud, that's supported, too (just not encouraged because a bug during development could destroy your production data!).
Specifically, you follow the general instructions at, and pointed to by, https://cloud.google.com/sql/docs/getting-started#work (ignoring the appengine-specific part): make sure your Cloud SQL instance has an IP address, enable the outside-visible IP address of your workstation, make sure the SQL instance has a root password -- then check everything is working with a command line MySQL client, e.g
[[Note: to verify your workstation's outside-visible IP address, use e.g a browser to visit a site such as http://checkmyip.com/ ]]
$ mysql --host=INSTANCE_IP --user=root --password
and once everything is set up properly you just follow the instructions at https://cloud.google.com/appengine/docs/php/cloud-sql/#PHP_Using_a_local_MySQL_instance_during_development :
To connect to a Cloud SQL instance from your development environment,
substitute "127.0.0.1" with the instance IP address. You do not use
the "/cloudsql/"-based connection string to connect to a Cloud SQL
instance if your App Engine app is running locally in the Development
Server.
If you want to use the same code locally and deployed, you can use a
Special $_SERVER keys variable (SERVER_SOFTWARE) to determine where
your code is running. This approach is shown below.
So for example if your Cloud SQL's IP address is 12.34.56.78, you'd use
$sql = new mysqli('12.34.56.78:3306',
'<username>',
'<password>',
<database-name>
);
when $_SERVER['SERVER_SOFTWARE'] is not set or does not contain Google App Engine (which means you're running on the local development server).
https://cloud.google.com/appengine/docs/php/cloud-sql/#PHP_Using_a_local_MySQL_instance_during_development
The Guestbook example above shows how your application can connect to a Cloud SQL instance when the code runs in App Engine and connect to a local MySQL server when the code runs in the Development Server. We encourage this pattern to minimize confusion and maximize flexibility.
I am actually trying to build an windows application and I need to maintain a database ("Not local") on cloud where can I actually maintain? I tried using phpmyadmin but it was to create a local db.
You can use SSH in conjunction with a database admin software such as Sequel pro for OSX or MySQL Workbench (http://www.mysql.com/products/workbench/) for other operating systems.
The most secure way typically would be to connect to the remote database server via SSH. Both these programs have that option available.
So you'd use the ssh key you'd use to SSH into the server, so tunnel into the database via SSH also.