Skip to content

Commit

Permalink
Run cypress on docker instead of installing everything
Browse files Browse the repository at this point in the history
  • Loading branch information
gmmcal committed Oct 22, 2023
1 parent 1b4029f commit 4899285
Show file tree
Hide file tree
Showing 5 changed files with 121 additions and 106 deletions.
175 changes: 94 additions & 81 deletions .github/workflows/cypress.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
32 changes: 16 additions & 16 deletions .github/workflows/docker.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
16 changes: 8 additions & 8 deletions .github/workflows/pull_request.yml
Original file line number Diff line number Diff line change
Expand Up @@ -49,21 +49,21 @@ 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
uses: ./.github/workflows/cypress.yml
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
Expand Down
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -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"]
2 changes: 2 additions & 0 deletions config/environments/test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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

0 comments on commit 4899285

Please sign in to comment.