From 4899285a6767e92b17943e5ca39f09e623df729b Mon Sep 17 00:00:00 2001 From: Gustavo Cunha Date: Sun, 22 Oct 2023 11:41:48 +0200 Subject: [PATCH] Run cypress on docker instead of installing everything --- .github/workflows/cypress.yml | 175 ++++++++++++++++------------- .github/workflows/docker.yml | 32 +++--- .github/workflows/pull_request.yml | 16 +-- Dockerfile | 2 +- config/environments/test.rb | 2 + 5 files changed, 121 insertions(+), 106 deletions(-) diff --git a/.github/workflows/cypress.yml b/.github/workflows/cypress.yml index abee2e644..2eefe5ee5 100644 --- a/.github/workflows/cypress.yml +++ b/.github/workflows/cypress.yml @@ -11,17 +11,14 @@ on: required: true env: - RAILS_ENV: development - DATABASE_URL: postgres://postgres:postgres@postgres:5432/gmmcalcombr_development + RAILS_ENV: test + DATABASE_URL: postgres://postgres:postgres@postgres:5432/gmmcalcombr_test jobs: e2e: name: 'End-to-end' runs-on: ubuntu-20.04 - container: - image: ruby:3.2.2 - services: postgres: image: postgres:16 @@ -33,80 +30,96 @@ jobs: - 5432:5432 options: --health-cmd pg_isready --health-interval 10s --health-timeout 5s --health-retries 5 + web: + image: gmmcal/gmmcal:development + env: + DATABASE_URL: postgres://postgres:postgres@postgres:5432/gmmcalcombr_development + ports: + - 3000:3000 + steps: - - uses: actions/checkout@v3 - - # languages - - name: Install APT dependencies - run: | - curl -sL https://deb.nodesource.com/setup_18.x | bash - - curl -sL https://dl.yarnpkg.com/debian/pubkey.gpg | apt-key add - - echo "deb https://dl.yarnpkg.com/debian/ stable main" | tee /etc/apt/sources.list.d/yarn.list - apt-get -yqq install nodejs libpq-dev xvfb libgtk-3-dev libnotify-dev libgconf-2-4 libnss3 libxss1 libasound2 - - - name: Install Chrome browser - run: | - wget -q -O - https://dl-ssl.google.com/linux/linux_signing_key.pub | apt-key add - && \ - echo "deb http://dl.google.com/linux/chrome/deb/ stable main" > /etc/apt/sources.list.d/google.list && \ - apt-get update && \ - apt-get install -y dbus-x11 google-chrome-stable && \ - rm -rf /var/lib/apt/lists/* - - - name: Install yarn - run: npm i -g yarn - - - name: Get yarn cache directory path - id: yarn-cache-dir-path - run: echo "dir=$(yarn cache dir)" >> $GITHUB_OUTPUT - - - uses: actions/cache@v3 - with: - path: vendor/bundle - key: ${{ runner.os }}-gems-gmmcal-${{ hashFiles('/Gemfile.lock') }} - restore-keys: | - ${{ runner.os }}-gems-gmmcal- - - - uses: actions/cache@v3 - id: yarn-cache # use this to check for `cache-hit` (`steps.yarn-cache.outputs.cache-hit != 'true'`) - with: - path: ${{ steps.yarn-cache-dir-path.outputs.dir }} - key: ${{ runner.os }}-yarn-gmmcal-${{ hashFiles('/yarn.lock') }} - restore-keys: | - ${{ runner.os }}-yarn-gmmcal- - - # dependencies - - name: Run bundle install - run: | - bundle config path vendor/bundle - bundle install --jobs 4 --retry 3 - - - name: Run yarn install - run: yarn install - - - name: Setup database - run: | - bundle exec rails db:migrate - - - name: Compile assets - run: | - bundle exec rails assets:precompile - - - name: Load default DB data - run: | - bundle exec rails db:seed - - # script - - name: Run tests - uses: cypress-io/github-action@v6 - with: - start: yarn server:start - wait-on: 'http://localhost:3000' - install: false - spec: ${{ inputs.pattern }} - browser: chrome - - - uses: actions/upload-artifact@v3 - if: failure() - with: - name: ${{ inputs.artifact-name }} - path: spec/end-to-end/screenshots + # - name: Create web network + # run: docker network create --driver=bridge web + + # - name: Run application container + # run: docker run -d --name web -p 3000:3000 --network=web --network=${{ job.services.postgres.network }} -e DATABASE_URL='postgres://postgres:postgres@postgres:5432/gmmcalcombr_test' -e DATABASE_CLEANER_ALLOW_REMOTE_DATABASE_URL=true --rm gmmcal/gmmcal:test bin/rails server -b 0.0.0.0 + + - name: Curl application container + run: curl http://localhost:3000 + + # - uses: actions/checkout@v3 + + # # languages + # - name: Install APT dependencies + # run: | + # curl -sL https://deb.nodesource.com/setup_18.x | bash - + # curl -sL https://dl.yarnpkg.com/debian/pubkey.gpg | apt-key add - + # echo "deb https://dl.yarnpkg.com/debian/ stable main" | tee /etc/apt/sources.list.d/yarn.list + # apt-get -yqq install nodejs libpq-dev xvfb libgtk-3-dev libnotify-dev libgconf-2-4 libnss3 libxss1 libasound2 + + # - name: Install Chrome browser + # run: | + # wget -q -O - https://dl-ssl.google.com/linux/linux_signing_key.pub | apt-key add - && \ + # echo "deb http://dl.google.com/linux/chrome/deb/ stable main" > /etc/apt/sources.list.d/google.list && \ + # apt-get update && \ + # apt-get install -y dbus-x11 google-chrome-stable && \ + # rm -rf /var/lib/apt/lists/* + + # - name: Install yarn + # run: npm i -g yarn + + # - name: Get yarn cache directory path + # id: yarn-cache-dir-path + # run: echo "dir=$(yarn cache dir)" >> $GITHUB_OUTPUT + + # - uses: actions/cache@v3 + # with: + # path: vendor/bundle + # key: ${{ runner.os }}-gems-gmmcal-${{ hashFiles('/Gemfile.lock') }} + # restore-keys: | + # ${{ runner.os }}-gems-gmmcal- + + # - uses: actions/cache@v3 + # id: yarn-cache # use this to check for `cache-hit` (`steps.yarn-cache.outputs.cache-hit != 'true'`) + # with: + # path: ${{ steps.yarn-cache-dir-path.outputs.dir }} + # key: ${{ runner.os }}-yarn-gmmcal-${{ hashFiles('/yarn.lock') }} + # restore-keys: | + # ${{ runner.os }}-yarn-gmmcal- + + # # dependencies + # - name: Run bundle install + # run: | + # bundle config path vendor/bundle + # bundle install --jobs 4 --retry 3 + + # - name: Run yarn install + # run: yarn install + + # - name: Setup database + # run: | + # bundle exec rails db:migrate + + # - name: Compile assets + # run: | + # bundle exec rails assets:precompile + + # - name: Load default DB data + # run: | + # bundle exec rails db:seed + + # # script + # - name: Run tests + # uses: cypress-io/github-action@v6 + # with: + # start: yarn server:start + # wait-on: 'http://localhost:3000' + # install: false + # spec: ${{ inputs.pattern }} + # browser: chrome + + # - uses: actions/upload-artifact@v3 + # if: failure() + # with: + # name: ${{ inputs.artifact-name }} + # path: spec/end-to-end/screenshots diff --git a/.github/workflows/docker.yml b/.github/workflows/docker.yml index 97bdb7661..994063c9a 100644 --- a/.github/workflows/docker.yml +++ b/.github/workflows/docker.yml @@ -21,21 +21,21 @@ jobs: - name: Checkout code uses: actions/checkout@v4 - - name: Set up Docker Buildx - uses: docker/setup-buildx-action@v3 + # - name: Set up Docker Buildx + # uses: docker/setup-buildx-action@v3 - - name: Login to Docker Hub - uses: docker/login-action@v3 - with: - username: ${{ secrets.DOCKERHUB_USERNAME }} - password: ${{ secrets.DOCKERHUB_TOKEN }} + # - name: Login to Docker Hub + # uses: docker/login-action@v3 + # with: + # username: ${{ secrets.DOCKERHUB_USERNAME }} + # password: ${{ secrets.DOCKERHUB_TOKEN }} - - name: Build image - uses: docker/build-push-action@v5 - with: - push: true - context: . - target: ${{ inputs.target }} - tags: ${{ inputs.tag-name }}:${{ inputs.target }} - cache-from: type=registry,ref=gmmcal/gmmcal:buildcache${{ inputs.target }} - cache-to: type=registry,ref=gmmcal/gmmcal:buildcache${{ inputs.target }},mode=max + # - name: Build image + # uses: docker/build-push-action@v5 + # with: + # push: true + # context: . + # target: ${{ inputs.target }} + # tags: ${{ inputs.tag-name }}:${{ inputs.target }} + # cache-from: type=registry,ref=gmmcal/gmmcal:buildcache${{ inputs.target }} + # cache-to: type=registry,ref=gmmcal/gmmcal:buildcache${{ inputs.target }},mode=max diff --git a/.github/workflows/pull_request.yml b/.github/workflows/pull_request.yml index 2d232817b..45c4a48a8 100644 --- a/.github/workflows/pull_request.yml +++ b/.github/workflows/pull_request.yml @@ -49,13 +49,13 @@ jobs: uses: ./.github/workflows/tests.yml needs: build - e2e-admin: - name: Admin - uses: ./.github/workflows/cypress.yml - with: - pattern: spec/end-to-end/tests/admin/**.js - artifact-name: cypress-screenshots-backend - needs: cypress + # e2e-admin: + # name: Admin + # uses: ./.github/workflows/cypress.yml + # with: + # pattern: spec/end-to-end/tests/admin/**.js + # artifact-name: cypress-screenshots-backend + # needs: [build, cypress] e2e-frontend: name: Frontend @@ -63,7 +63,7 @@ jobs: with: pattern: spec/end-to-end/tests/frontend/**.js artifact-name: cypress-screenshots-frontend - needs: cypress + needs: [build, cypress] bundler-audit: name: Bundler Audit / Lint diff --git a/Dockerfile b/Dockerfile index 9fc0221a1..770b711cf 100644 --- a/Dockerfile +++ b/Dockerfile @@ -132,4 +132,4 @@ RUN ls -la # ENTRYPOINT ["/rails/bin/docker-entrypoint"] # Start the server by default, this can be overwritten at runtime -CMD ["cypress", "run", "-c", "'{\"e2e\": {\"baseUrl\":\"http://web:3000\"}}'"] +CMD ["cypress", "run"] diff --git a/config/environments/test.rb b/config/environments/test.rb index 6b0a3c3d3..c08d8e9ef 100644 --- a/config/environments/test.rb +++ b/config/environments/test.rb @@ -63,4 +63,6 @@ logger = ActiveSupport::Logger.new($stdout) logger.formatter = config.log_formatter config.logger = config.logger = Logger.new('/dev/null') + + config.hosts = %w[localhost web] # web is used for cypress tests on CI end