edbizarro / gitlab-ci-pipeline-php

:coffee: Docker images for test PHP applications with Gitlab CI (or any other CI platform!)
https://hub.docker.com/r/edbizarro/gitlab-ci-pipeline-php
MIT License
529 stars 167 forks source link

Change mariadb-client for mysql-client #66

Closed abkrim closed 4 years ago

abkrim commented 5 years ago

I've tried use your repo for use with laravel iun a project with 5 databases

The best way for me (I spend some time in try o anothers ways) is add this:

On my project in gitlab add variables for second database But problem when is not mysql client for connect from alpine image to mysql container. I've tried use my own image of mysql and official

db-seeding:
  stage: building
  services:
    - {name: 'abkrim/mysql8_legacy_password', alias: 'mysql'}
  image: abkrim/gitlab-ci-pipeline-php:7.3-alpine
  dependencies:
    - composer
    - yarn
  script:
    - echo "CREATE DATABASE IF NOT EXISTS \`${DB_2}\`;" | mysql --user=root --password="MYSQL_ROOT_PASSWORD" --host=mysql
    - echo "CREATE USER '${DB_2_USER}'@'%' IDENTIFIED BY '${DB_2_PASSWORD}';" | mysql --user=root --password="MYSQL_ROOT_PASSWORD" --host=mysql
    - echo "GRANT ALL ON ${DB_2}.* TO '${DB_2_USER}'@'%';" | mysql --user=root --password="MYSQL_ROOT_PASSWORD" --host=mysql
    - echo "FLUSH PRIVILEGES;" | mysql --user=root --password="MYSQL_ROOT_PASSWORD" --host=mysql
    - php artisan migrate:fresh --seed

On gitlab access to image of alpine and see error

docker run -i -t a6ade0a9cc5d /bin/bash
bash-5.0$ mysql
bash: mysql: command not found
bash-5.0$ hostname -f
95deb901898c
bash-5.0$ ls -lisah /
total 64K    
 533373      4 drwxr-xr-x    1 root     root        4.0K Sep  6 15:50 .
 533373      4 drwxr-xr-x    1 root     root        4.0K Sep  6 15:50 ..
 533379      0 -rwxr-xr-x    1 root     root           0 Sep  6 15:50 .dockerenv
 919064      4 drwxr-xr-x    1 root     root        4.0K Sep  1 07:28 bin
      2      0 drwxr-xr-x    5 root     root         360 Sep  6 15:50 dev
 533380      4 drwxr-xr-x    1 root     root        4.0K Sep  6 15:50 etc
 919246      4 drwxr-xr-x    1 root     root        4.0K Sep  1 07:20 home
 921874      4 drwxr-xr-x    1 root     root        4.0K Sep  1 07:20 lib
 793888      4 drwxr-xr-x    5 root     root        4.0K Aug 20 10:30 media
 793893      4 drwxr-xr-x    2 root     root        4.0K Aug 20 10:30 mnt
 793894      4 drwxr-xr-x    2 root     root        4.0K Aug 20 10:30 opt
      1      0 dr-xr-xr-x  135 root     root           0 Sep  6 15:50 proc
 796875      4 drwx------    1 root     root        4.0K Aug 20 22:58 root
 921911      4 drwxr-xr-x    1 root     root        4.0K Sep  1 07:20 run
 793899      4 drwxr-xr-x    2 root     root        4.0K Aug 20 10:30 sbin
 793968      4 drwxr-xr-x    2 root     root        4.0K Aug 20 10:30 srv
      1      0 dr-xr-xr-x   13 root     root           0 Sep  6 15:50 sys
 921913      4 drwxrwxrwt    1 root     root        4.0K Sep  1 07:28 tmp
 922922      4 drwxr-xr-x    1 root     root        4.0K Sep  1 07:20 usr
 919077      4 drwxr-xr-x    1 root     root        4.0K Sep  1 07:25 var
bash-5.0$ ls -lisah /home/
total 16K    
 919246      4 drwxr-xr-x    1 root     root        4.0K Sep  1 07:20 .
 533373      4 drwxr-xr-x    1 root     root        4.0K Sep  6 15:50 ..
 919247      4 drwxr-sr-x    6 php      php         4.0K Sep  1 07:27 php
 795118      4 drwxr-sr-x    2 www-data www-data    4.0K Aug 20 22:29 www-data
bash-5.0$ sudo su -
95deb901898c:~# apk add mysql-client
fetch http://dl-cdn.alpinelinux.org/alpine/v3.10/main/x86_64/APKINDEX.tar.gz
fetch http://dl-cdn.alpinelinux.org/alpine/v3.10/community/x86_64/APKINDEX.tar.gz
(1/3) Installing mariadb-common (10.3.17-r0)
(2/3) Installing mariadb-client (10.3.17-r0)
(3/3) Installing mysql-client (10.3.17-r0)
Executing busybox-1.30.1-r2.trigger
OK: 450 MiB in 172 packages
95deb901898c:~# mysql
ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/run/mysqld/mysqld.sock' (2)
95deb901898c:~# exit
bash-5.0$ exit

After install manual mysql-client of mysql instead mariadb-client command is correct.

I've tried create a form image on hub.docker, but I not a expert on docker....