Running a local server in ci

Replace this template with your information

I have a Symfony application with a React front end, and I want to run cypress end to end tests again the application. For local development, I have an nginx container to serve the application, and I’ve been trying to use that as the server for cypress.

I’ve tried a couple different approaches, including running a cypress image as a service. However, I think the problem I’m having is nginx isn’t serving the application as expected.

Here’s the test container from .gitlab-ci:

e2etest:
  stage: test
  needs: [validate composer, lint php]
  services:
    - mysql:8.0
    # - cypress/included:5.3.0
  variables:
    MYSQL_ROOT_PASSWORD: "root"
    APP_ENV: "test"
  before_script:
    - apt update && apt install -y libgtk2.0-0 libgtk-3-0 libgbm-dev libnotify-dev libgconf-2-4 libnss3 libxss1 libasound2 libxtst6 xauth xvfb
    - curl -L "https://github.com/docker/compose/releases/download/1.27.3/docker-compose-$(uname -s)-$(uname -m)" -o /usr/local/bin/docker-compose
    - chmod +x /usr/local/bin/docker-compose
    - composer2 install --no-progress --prefer-dist --optimize-autoloader --ansi
    - yarn global add cypress wait-on
    - yarn install
    - yarn run build
    - pecl install xdebug
    - echo "zend_extension=/usr/local/lib/php/extensions/no-debug-non-zts-20190902/xdebug.so" >> /usr/local/etc/php/conf.d/xdebug.ini
    - mv .env.ci .env.test.local
    # - ./bin/console doctrine:database:create --env=test --if-not-exists
    # - ./bin/console doctrine:migrations:migrate --allow-no-migration --no-interaction --all-or-nothing --env=test
    - /usr/local/bin/docker-compose --version

  script:
    - /usr/local/bin/docker-compose up -d nginx & wait-on http://localhost:8080
    - cypress run --headless --browser chrome

It’s definitely kind of a mess, but at this point I just want it to run.

Here’s the nginx server from docker-compose:

nginx:
        build: ./docker/nginx
        ports:
            - "8080:80"
            - "8043:443"
        depends_on:
            - php
        networks:
            - blackfire
            - php
        volumes:
            - .:/var/www:cached
            - shared-volume:/var/www/public/files

Finally, the wait-on never finishes, and if I remove the wait-on, cypress tells me it doesn’t find the site at localhost:8080, where I am trying to run the nginx server.

It seems like something about the configuration of the host container makes it so the server is never exposed. Maybe I can run the Symfony php web server in this container without docker.