2

i just have push my Symfony 5.4 application in my company server with Gitlab-ci and docker.

I have a Dokcerfile in the root avec my projet:

FROM php:7.4-apache

ENV APACHE_DOCUMENT_ROOT /var/www/html/public

RUN sed -ri -e 's!/var/www/html!${APACHE_DOCUMENT_ROOT}!g' /etc/apache2/sites-available/*.conf 


COPY . /var/www/html/

RUN apt-get update \
    && apt-get install -y --no-install-recommends locales apt-utils git libicu-dev g++ libpng-dev libxml2-dev libzip-dev libonig-dev libxslt-dev;

RUN echo "en_US.UTF-8 UTF-8" > /etc/locale.gen && \
    echo "fr_FR.UTF-8 UTF-8" >> /etc/locale.gen && \
    locale-gen

# INSTALL COMPOSER
RUN curl -sSk https://getcomposer.org/installer | php -- --disable-tls && \
   mv composer.phar /usr/local/bin/composer

# INSTALL EXTENSION PHP
RUN docker-php-ext-configure intl
RUN docker-php-ext-install pdo pdo_mysql gd opcache intl zip calendar dom mbstring zip gd xsl
RUN pecl install apcu && docker-php-ext-enable apcu



# INSTALL YARN 
RUN apt-get update && apt-get install -y gnupg2
RUN curl -sS https://dl.yarnpkg.com/debian/pubkey.gpg | apt-key add -
RUN echo "deb https://dl.yarnpkg.com/debian/ stable main" | tee /etc/apt/sources.list.d/yarn.list
RUN apt-get update && apt-get install -y yarn


RUN apt update 

RUN chown -R www-data:www-data /var/www/html

RUN a2enmod rewrite
RUN  service apache2 restart

And i have this job on my gitlab pipeline:

deploy_image:
    stage: deploy
    script: 
        - docker login -u $CI_REGISTRY_USER -p $CI_REGISTRY_PASSWORD $CI_REGISTRY
        - cd /srv/docker/stacks/r-panda
        - docker network disconnect --force r-panda_default traefik_app
        - /usr/local/bin/docker-compose down 
        - /usr/local/bin/docker-compose pull 
        - /usr/local/bin/docker-compose up -d
        - docker network connect r-panda_default traefik_app
    after_script:
        - docker exec r-panda_app yarn install
        - docker exec r-panda_app yarn run build
        - ls -al
    environment:
        name: dev
        url: $SERVER_URL 
    variables:
        DATABASE_URL: $DATABASE_URL
    tags:
        - deploy

And there is my docker-compose.yaml on the server who run the contener with the application:

version: '3.9'
services:
    r-panda_app:
        container_name: r-panda_app
        image: panda
        environment:
            - DATABASE_URL="mysql://db_user:db_pass@bbd_server:3306/panda_bdd"
        restart: always
        labels:
            - traefik.enable=true
            - traefik.http.routers.router-r-panda.rule=Host(`r-panda.fr`)
            - traefik.http.routers.router-r-panda.tls.certresolver=myresolver
            - traefik.http.routers.router-r-panda.tls=true 

With this config i have the following error: An exception occurred in the driver: SQLSTATE[HY000] [2002] No such file or directory

But if i change my config/packages/doctrine.yaml

This

doctrine:
    dbal:
        driver: 'pdo_mysql'
        server_version: '5.7'
        charset: utf8mb4
        url: '%env(resolve:DATABASE_URL)%'

To this:

doctrine:
    dbal:
        driver: 'pdo_mysql'
        server_version: '5.7'
        charset: utf8mb4
        url: 'the real path for the DATABASE_URL'

Everything works

I don't know what to do, can someone help me

IAI
  • 83
  • 1
  • 1
  • 4

0 Answers0