Setting up Cypress end-to-end testing for GitLab CI

Hello, all. I am very new to Elixir/Phoenix and am having trouble setting up end-to-end testing for my Phoenix app. I am able to run ExUnit tests just fine with “mix test,” but to run Cypress tests I need to boot the server with “mix phx.server.” The problem is that the server never starts (localhost:4000 is inaccessible), and running “mix phx.server” just seems to block forever, without any output to the command line at all.

Here are the contents of my config/test.exs

use Mix.Config

# Configure your database
config :we_pivot, WePivot.Repo,
  adapter: Ecto.Adapters.Postgres,
  username: System.get_env("POSTGRES_USER") || "postgres",
  password: System.get_env("POSTGRES_PASSWORD") || "postgres",
  database: System.get_env("POSTGRES_DB") || "we_pivot_test",
  hostname: System.get_env("POSTGRES_HOST") || "postgres",
  pool: Ecto.Adapters.SQL.Sandbox

config :we_pivot, WePivotWeb.Endpoint,
  server: true,
  http: [port: 4000]

# Print only warnings and errors during test
config :logger, level: :warn

And my .gitlab-ci.yml

image: registry.gitlab.com/msoe.edu/sdl/sd20/bgpss/we-pivot

services:
  - postgres:latest
  
variables:
  POSTGRES_DB: we_pivot_test
  POSTGRES_HOST: postgres
  POSTGRES_USER: postgres
  POSTGRES_PASSWORD: "postgres"
  MIX_ENV: "test"

before_script:
  # Check Elixir/Erlang version
  - elixir -v
  # Install hex locally
  - mix local.hex --force
  # Install Phoenix MIX archive
  - mix archive.install --force hex phx_new 1.4.10
  # Retrieve server dependencies for test environment
  - mix deps.get
  # Ensure mix ecto.create runs by adding rebar3
  - mix local.rebar --force
  # Install Cypress
  - export PATH="$HOME/.yarn/bin:$HOME/.config/yarn/global/node_modules/.bin:$PATH"
  - yarn install
  # Install node dependencies using yarn
  - cd assets && yarn install && cd ..
  # Create postgres database
  - mix ecto.create
  # Run migrations
  - mix ecto.migrate
  # Download Data
  - python3 scripts/DownloadData.py
  
stages:
  - test

runserver:
  stage: test
  script: mix phx.server
  cache:
    paths:
      - ~/.cache
      - .yarn

exunit:
  stage: test
  script:
    - mix test
  # Use cache to speed up builds
  cache:
    paths:
      - ~/.cache
      - .yarn

cypress:
  stage: test
  script:
    - yarn run cypress run
  # Use cache to speed up builds
  cache:
    paths:
      - ~/.cache
      - .yarn

And the Dockerfile for the image I’m using

#
# DockerFile: Create Docker image for WePivot CI
#   - start with lastest elixir image, add Phoenix and Python dependencies

FROM elixir:latest
# Install curl
RUN apt-get update; apt-get install -y curl

# Install project dependencies
# Install Node.js directly from nodesource to avoid yarn installation issues
RUN curl -sL https://deb.nodesource.com/setup_12.x | bash
RUN apt-get -y install nodejs
# Install PostgreSQL
RUN apt-get -y install postgresql-client
# Install inotify-tools for code-reloading
RUN apt-get -y install inotify-tools
# Install yarn as outlined in (https://yarnpkg.com/lang/en/docs/install/#alternatives-stable)
RUN curl -o- -L https://yarnpkg.com/install.sh | bash
# Add to path
RUN export PATH="$HOME/.yarn/bin:$HOME/.config/yarn/global/node_modules/.bin:$PATH"
# Install Cypress dependencies
RUN apt-get -y install xvfb libgtk-3-dev libnotify-dev libgconf-2-4 libnss3 libxss1 libasound2
# Install Python 3 and dependencies
RUN apt-get -y install python3
RUN apt-get -y install python3-pip
RUN pip3 install pandas
RUN pip3 install xlrd

You can run the server in the background so you have access to the shell, this can be done by using && or by running the server as a daemon / detached process

$ PORT=4001 MIX_ENV=test elixir --erl "-detached" -S mix phx.server