title: How to setup TeamCity to work with Cypress without installation of node, xvfb, cypress for each test execution
body: <p>I want to run my cypress.io tests in CI (Teamcity) by scheduled timers. Tests will be run very frequently that is why I am interesting to execute them as quick as possible
  This is my current implementation.
  I run teamcity-server with 3 teamcity-agents with the following docker-compose.yml</p>
  <pre><code>
      version: &quot;3&quot;
      services:
        server:
          image: jetbrains/teamcity-server:2020.1.2
          ports:
            - &quot;8112:8111&quot;
          volumes:
            - ./data_dir:/data/teamcity_server/datadir
            - ./log_dir:/opt/teamcity/logs
        teamcity-agent-1:
          image: jetbrains/teamcity-agent:2020.1.2-linux-sudo
          environment:
            - SERVER_URL=http://server:8111
            - AGENT_NAME=docker-agent-1
            - DOCKER_IN_DOCKER=start
          privileged: true
          container_name: docker_agent_1
        teamcity-agent-2:
          image: jetbrains/teamcity-agent:2020.1.2-linux-sudo
          environment:
            - SERVER_URL=http://server:8111
            - AGENT_NAME=docker-agent-2
            - DOCKER_IN_DOCKER=start
          privileged: true
          container_name: docker_agent_2
        teamcity-agent-3:
          image: jetbrains/teamcity-agent:2020.1.2-linux-sudo
          environment:
            - SERVER_URL=http://server:8111
            - AGENT_NAME=docker-agent-3
            - DOCKER_IN_DOCKER=start
          privileged: true
          container_name: docker_agent_3
  
  </code></pre>
  <p>And in building steps I am using node:10.18.1 in settings as per screen below:
  <a href="https://i.stack.imgur.com/HUIM3.png" rel="noreferrer">enter image description here</a></p>
  <p>My buildings steps are following now:</p>
  <p>1.</p>
  <pre><code>npm install yarn --no-save
  yarn install --no-lockfile
  </code></pre>
  <ol start="2">
  <li></li>
  </ol>
  <pre><code>#!/bin/bash
  set -e -x
  export CYPRESS_CACHE_FOLDER=&quot;%env.cypress_cache_path%&quot;
  export CYPRESS_VAR1=%env.var1%
  export CYPRESS_VAR2=%env.var2%
  
  apt-get update &amp;&amp; apt-get -y install libgtk2.0-0 libgtk-3-0 libnotify-dev libgconf-2-4 libnss3 libxss1 libasound2 libxtst6 xauth xvfb
  
  yarn silent --spec &quot;%env.cypress_path_to_landing_pages%&quot;
  </code></pre>
  <ol start="3">
  <li>yarn generate:html:report</li>
  </ol>
  <p>This is I need to run for every time I execute tests and it takes around 10 mins to execute each test set taking 60-70% time on installation of all dependencies which are</p>
  <pre><code>  {
      &quot;@types/mocha&quot;: &quot;^8.0.0&quot;,
      &quot;cypress&quot;: &quot;4.11.0&quot;,
      &quot;cross-env&quot;: &quot;^7.0.2&quot;,
      &quot;mocha&quot;: &quot;^7.2.0&quot;,
      &quot;mochawesome&quot;: &quot;^6.1.1&quot;,
      &quot;mochawesome-merge&quot;: &quot;^4.1.0&quot;,
      &quot;mochawesome-report-generator&quot;: &quot;^5.1.0&quot;,
      &quot;typescript&quot;: &quot;^3.9.6&quot;
    }
  </code></pre>
  <ul>
  <li>apt-get install xvfb libgtk-3-dev libnotify-dev libgconf-2-4 libnss3 libxss1 libasound2 (which I need to install extra for linux)
  I do belieave that main heavy dependency are cypress and xvfb packages.</li>
  </ul>
  <p>I see 3 ways how to avoid this huge execution time:</p>
  <ol>
  <li>to have a docker image compatible with teamcity containing all cypress ENV: node, cypress, xvfb etc. In that case I do not need to install it every time I run tests. I was following cypress documentation and aware that special docker images are designed for that
  <a href="https://github.com/cypress-io/cypress-docker-images" rel="noreferrer">https://github.com/cypress-io/cypress-docker-images</a></li>
  </ol>
  <p>cypress/base</p>
  <p>cypress/browsers</p>
  <p>cypress/included</p>
  <p>But they are not compatible with Teamcity server (Teamcity agents need to have a java wrapper) or I dont know how to run them from docker-compose.yml
  I tried this but TeamCity server was not able to find this agent and agents tab was empty</p>
  <pre><code>version: &quot;3&quot;
  services:
    server:
      image: jetbrains/teamcity-server:2020.1.2
      ports:
        - &quot;8112:8111&quot;
      volumes:
        - ./data_dir:/data/teamcity_server/datadir
        - ./log_dir:/opt/teamcity/logs
    teamcity-agent-2:
      image: cypress/included:3.4.0
      environment:
        - SERVER_URL=http://server:8111
        - AGENT_NAME=docker-agent-2
        - DOCKER_IN_DOCKER=start
      privileged: true
      container_name: docker_agent_2
  </code></pre>
  <ol start="2">
  <li><p>To cache node_modules and xvfb somehow. I see <a href="https://cypress.slides.com/cypress-io/cypress-on-ci#/5/2/0" rel="noreferrer">https://cypress.slides.com/cypress-io/cypress-on-ci#/5/2/0</a> but can not understand how to put it in my building steps</p>
  </li>
  <li><p>Setup building dependencies in TeamCity and install all dependencies once in one build and move artifacts (node_modules, xvfb etc) somehow to next build which will run tests by timers.</p>
  </li>
  </ol>
  <p>How I understood cypress documentation myself they are suggesting to follow point 1 from my list but how to run their images as teamcity agents I did not understand</p>
  <p>any suggestions are welcome</p>