Laravel CI/CD in Gitlab, Docker set my IP MySQL - laravel

I followed this Gitlab tutorial to test and deploy Laravel applications with GitLab CI/CD and Envoy.
All works well, but when I run a pipeline it shows this error:
PDOException::("SQLSTATE[HY000] [1045] Access denied for user 'user'#'172.17.0.4' (using password: YES)")
My IP server is 172.0.0.1 but the pipeline set the IP by 172.17.0.4.
How can I set the IP to make work it?

Finally, it works. I added only this values to the yml file:
variables:
MYSQL_DATABASE: mydatabase
MYSQL_ROOT_PASSWORD: 123456
Obviously the same values to the .env file.
(I also uninstalled and re-installed MySQL, but I don't know if that helped to solve it)

Related

Ansible having problem authenticating with Google Cloud Platform

We are using Ansible to deploy an image to Google Kubernetes Cluster (GKE).
We have setup Ubuntu 20.04 and Python 3.8.5.
playbook.main.yml:
---
- hosts: localhost
vars:
k8s_file_path: /home/pesinn/Documents/...
become: yes
become_method: sudo
roles:
- k8s
main.yml:
- name: First Deployment
k8s:
kubeconfig: /home/pesinn/.kube/config
src: "{{k8s_file_path}}/deployment.yml"
When trying to deploy the image defined in deployment.yml file, by running the playbook, we get this error:
kubernetes.config.config_exception.ConfigException: cmd-path: process returned 1
Cmd: /home/pesinn/y/google-cloud-sdk/bin/gcloud config config-helper --format=json
Stderr: WARNING: Could not open the configuration file: [/root/.config/gcloud/configurations/config_default].
ERROR: (gcloud.config.config-helper) You do not currently have an active account selected.
Please run:
$ gcloud auth login
What we've already done
Initialized the cloud: gcloud init
Logged in and chosen a project gcloud auth login
Run export GOOGLE_APPLICATION_CREDENTIALS="path_to_service_account_key.json"
Run gcloud container clusters get-credentials {gke_project} --region {region}
Run the playbook sudo ansible-playbook playbook.main.yml -vvv
Run gcloud config config-helper --format=json on the local machine without any problems
What is very strange here is that we're logged in for sure. We can access the GKE cluster through kubectl command on the local machine. However, Ansible complains about us not being logged in. Also, in the error logs, we see that it is trying to open /root/.config/gcloud/configurations/config_default. Our default config file is, on the other hand, located in the home folder.
This error occurs randomly. Sometimes Ansible can detect our login and deploys the image, but sometimes it gives us this error. Both scenarios can happens without any code changes being made.
For some reason, ansible does not use GCP's default environment variables for authentication.
You can set
GCP_AUTH_KIND
GCP_SERVICE_ACCOUNT_EMAIL
GCP_SERVICE_ACCOUNT_FILE
GCP_SCOPES
GCP_SERVICE_ACCOUNT_FILE is the equivalent of GOOGLE_APPLICATION_CREDENTIALS
Reference: https://docs.ansible.com/ansible/latest/scenario_guides/guide_gce.html#providing-credentials-as-environment-variables

gcloud app SQLSTATE[HY000] [2002] Connection timed out

I have created laravel application with database it run on localhost so i decide to deploy on GCP appengine but when i click on deploy this happen
SQLSTATE[HY000] [2002] Connection timed out
i connecting to my GCP sql Instance below are my app.yaml
1st i use local host that uses sql_proxy it show no files directory then i remove the DB_Socket then this error come out SQLSTATE[HY000] [2002] Connection timed out
runtime: php
env: flex
runtime_config:
document_root: public
Ensure we skip ".env", which is only for local development
skip_files:
- .env
env_variables:
# Put production environment variables here.
APP_LOG: errorlog
APP_KEY: base64:G9druqluKMZ6TugSgmM1OJVwWSzfstc08acMRBAqxwg=
CACHE_DRIVER: database
SESSION_DRIVER: database
## Set these environment variables according to your CloudSQL configuration.
DB_HOST: 35.231.242.40
DB_DATABASE: lkcfes
DB_USERNAME: root
DB_PASSWORD:
This question is more appropriate for a support case so that a Google Cloud Platform support agent can inspect your app.yaml and Cloud SQL instance.
Having said that, there is a guide here on running Laravel on GAE Flex. You'll find it includes using a "beta_settings" section on your yaml, the Cloud SQL instance's public IP is not used.

How to use local proxy settings in docker-compose

I am setting up a new server for our Redmine installation, since the old installation was done by hand, which makes it difficult to update everything properly. I decided to go with a Docker image but am having trouble starting the docker container due to an error message. The host is running behind a proxy server, which I think, is causing this problem, as everything else such as wget, curl, etc. is working fine.
Error message:
Pulling redmine (redmine:)...
ERROR: Get https://registry-1.docker.io/v2/: dial tcp 34.206.236.31:443: connect: connection refused
I searched on Google about using Docker/Docker-Compose with a proxy server in the background and found a few websites where people had the same issue but none of these really helped me with my problem.
I checked with the Docker documentation and found a guide but this does not seem to work for me: https://docs.docker.com/network/proxy/
I also found an answered question here on StackOverflow: Using proxy on docker-compose in server which might be the solution I am after but I am unsure where exactly I have to put the solution. I guess the person means the docker-compose.yml file but I could be wrong.
This is what my docker-compose.yml looks like:
version: '3.1'
services:
redmine:
image: redmine
restart: always
ports:
- 80:3000
environment:
REDMINE_DB_MYSQL: db
REDMINE_DB_PASSWORD: SECRET_PASSWORD
db:
image: mysql:5.7
restart: always
environment:
MYSQL_ROOT_PASSWORD: SECRET_PASSWORD
MYSQL_DATABASE: redmine
I expect to run the following command without the above error message
docker-compose -f docker-compose.yml up -d
I did a bit more research and seem to have used better key words because I found my solution now. I wanted to share the solution with everyone, in case someone else may ever need it.
Create folder for configuring docker service through systemd
mkdir /etc/systemd/system/docker.service.d
Create service configuration file at /etc/systemd/system/docker.service.d/http-proxy.conf and put the following in the newly created file
[Service]
# NO_PROXY is optional and can be removed if not needed
# Change proxy_url to your proxy IP or FQDN and proxy_port to your proxy port
# For Proxy server which require username and password authentication, just add the proper username and password to the URL. (see example below)
# Example without authentication
Environment="HTTP_PROXY=http://proxy_url:proxy_port" "NO_PROXY=localhost,127.0.0.0/8"
# Example with authentication
Environment="HTTP_PROXY=http://username:password#proxy_url:proxy_port" "NO_PROXY=localhost,127.0.0.0/8"
# Example for SOCKS5
Environment="HTTP_PROXY=socks5://proxy_url:proxy_port" "NO_PROXY=localhost,127.0.0.0/8"
Reload systemctl so that new settings are read
sudo systemctl daemon-reload
Verify that docker service Environment is properly set
sudo systemctl show docker --property Environment
Restart docker service so that it uses updated Environment settings
sudo systemctl restart docker
Now you can execute the docker-compose command on your machine without getting any connection refused error messages.
For the proxy server which requires username and password for authentication: Apart from adding the credentials in /etc/systemd/system/docker.service.d/http-proxy.conf, as suggested in this answer, I also had to add the same to the Dockerfile. Following is a snippet from the Dockerfile.
FROM ubuntu:16.04
ENV http_proxy http://username:password#proxy_url:proxy_port
ENV https_proxy http://username:password#proxy_url:proxy_port
RUN apt-get update \
&& apt-get upgrade -y \
&& apt-get install -y \
build-essential \
bla bla bla ...

Configuring Homestead to work with MySQL Workbench

I just started using Homestead today and so far I don't think I know what I am doing, previously I was using the inbuilt PHP server that comes with Laravel and I had MySQL server and workbench installed separately on my computer.
With this setup I was able to connect to my database with ease, however since I got my Homestead running I can't seem to access that database again. This error keeps popping up:
3/3 ErrorException in Connector.php line 47: SQLSTATE[HY000] [1045]
Access denied for user 'myproject_db101'#'localhost' (using password: YES)
(View: /home/vagrant/Projects/myproject/resources/views/layout/index.blade.php)
(View: /home/vagrant/Projects/myproject/resources/views/layout/index.blade.php)
How can I fix this?
I was facing the same issue and I tried below steps to fix it. Please let me know if they work for you.
Note the homestead ip address for your vagrant box. It is available in Homestead.yaml file under ~/.homestead directory. This directory location would be different on different OS. But since you have already installed vagrant with homestead you should know its location. For me the ip address was 192.168.10.10.
Open up the Mysql Connection wizard and provide the below settings
hostname = 192.168.10.10
port = 3306
username = homestead
password = secret
Test Your connection
For me these settings worked. Check if they work for you.
These other answers might have worked for you guys, but in case anyone has a case like mine, I'm just going to provide what worked for me. Hopefully it helps someone out. I'm working on a brand new homestead installation as of today, but on a very old mac in case thats relevant.
What worked for me was using the regular localhost ip of my machine as the host, and then the homested/secret combination for the password, and using the default port but with a 0 at the end.
This adds up to be the following settings:
Connection method: Standard (TCP/IP)
Host: 127.0.0.1
Username: homestead
Password: secret
Port: 33060
Hopefully this helps someone out. Its the only configuration that worked for me.
Try using homestead's default MySQL credentials: User: root Password: secret
If you are accessing the database from your computer via MySQL Workbench (not from within the homestead VM), you can use localhost:33060 (note: non-standard port). This is mapped to port 3306 within your VM.
From your application and any time you're working from within the homestead VM, you can connect to the database normally as localhost on port 3306.
Very likely a configuration issue. Either the user 'myproject_db101'#'localhost' has no password set or is not allowed to connect from localhost. You need another user with proper rights (e.g. the root user) to fix permissions for that user.

Unable to access the database of homestead environment (laravel) through MYSQL workbench

Unable to access the homestead database through MYSQL workbench Please help me out to solve this issue
error messages at time of testing the connection - "Failed to Connect to MySQL at 127.0.0.1:33060 with user homestead Lost connection to MySQL server at 'reading initial communication packet', system error: 0"
please take a note that
Bind address in my.cnf file is 127.0.0.1 (my.cnf file located at /etc/mysql/)
hosts file contains: 127.0.0.1 localhost projectname (which is located at /etc/)
I have tried changing bind address to 0.0.0.0 but it was also not worked.
Actually I was keep trying to setup the database connectivity by just considering the homestead environment ... But on Keep searching I found one link http://www.acnenomor.com/171821p1/laravel-homestead-vagrant-box-database-problems from where I got idea and I tried once again with the data shown in attached image and it worked for me ... so I am sharing this answer in general .. it may help someone...
Please take a note that I have also tried to connect the database of Laravel homestead environment by installing all the stuffs in other system too and it was worked fine as described in the official document.. so in my case it might be the problem of some changes in configuration file of mysql or any other related environment... so please first go through the official document... http://laravel.com/docs/4.2/homestead#daily-usage
The first thing you need to do is
vagrant up
and then use these connections below for a default homestead installation.
Connection Method: Standard (TCP/IP)
Hostname: 127.0.0.1
Port: 33060
Username: homestead
Password: secret
Try the alternate IP of 192.168.10.10
hostname = 192.168.10.10
port = 3306
username = homestead
password = secret
This works for me on Windows 10 Home Version 20H2 OS Build 19042.1165 (To find this information navigate to Start, Type 'About' and click 'About your PC').
ran into a similar problem while trying to use SQLyog on my windows machine to connect to mySQL on a Homestead environment. I was able to resolve this issue by adding
skip-name-resolve
to the VMs /etc/mysql/my.conf file.
Apparently (according the mysql error logs) connections from the local machine were coming from '10.0.2.2', which caused the warning "IP Address '10.0.0.2' could not be resolved".
You will need to re-add this line every time you spin up the environment.

Resources