Problems storing video/screenshots when testing Rails app with Cypress/CircleCI - ruby-on-rails

I am running Cypress to test a Rails app on CircleCI. I have the tests running on CircleCI with the following config. But no video/screenshot assets are created in CircleCI artefacts if tests fail.
version: 2.1
orbs:
ruby: circleci/ruby#1.0.6
node: circleci/node#3.0.1
jobs:
build:
docker:
- image: cimg/ruby:2.7.2-node
steps:
- checkout # pull down our git code.
- ruby/install-deps # use the ruby orb to install dependencies
- node/install-packages:
pkg-manager: yarn
test:
parallelism: 3
docker:
- image: cimg/ruby:2.7.2-node # this is our primary docker image, where step commands run.
- image: circleci/postgres:12.3
environment: # add POSTGRES environment variables.
POSTGRES_USER: user
POSTGRES_PASSWORD: password
POSTGRES_DB: testdb
environment:
BUNDLE_JOBS: "3"
BUNDLE_RETRY: "3"
PGHOST: 127.0.0.1
PGUSER: user
PGPASSWORD: password
RAILS_ENV: test
steps:
- checkout
- ruby/install-deps
- node/install-packages:
pkg-manager: yarn
- run:
name: Wait for DB
command: dockerize -wait tcp://localhost:5432 -timeout 1m
- run:
name: Database setup
command: bundle exec rails db:schema:load --trace
- run:
name: Load test data
command: bundle exec rails db:seed --trace
- run:
name: Run Rails Server
background: true
command: CYPRESS=1 bundle exec rails s -p 5017
- run:
name: Wait for server
command: |
until $(curl --retry 10 --output /dev/null --silent --head --fail http://127.0.0.1:5017); do
printf '.'
sleep 5
done
- run: sudo apt-get update
- run: sudo apt-get install libgtk2.0-0 libgtk-3-0 libgbm-dev libnotify-dev libgconf-2-4 libnss3 libxss1 libasound2 libxtst6 xauth xvfb
- run: yarn cypress install --force
- run:
yarn: true
command: yarn run cypress run
- store_test_results:
path: test-reports/

Related

Running CircleCI locally bitbucket & token error

Description
Running this:
$ circleci build --branch master --repo-url https://bitbucket.org/cityhive/city-hive-standalone-widget --job e2e
Getting these errors
Cloning into '.'...
Username for 'https://bitbucket.org': fatal: could not read Username for 'https://bitbucket.org': Success
...
# (from Jira orb)
/bin/bash: CIRCLE_TOKEN: Please provide a CircleCI API token for this orb to work!
If I'm trying to pass token I get this:
$ circleci build --token d14c4********* --branch master --repo-url https://bitbucket.org/cityhive/city-hive-standalone-widget --job e2e
Fetching latest build environment...
Docker image digest: sha256:7a080ca333******
WARNING: The requested image's platform (linux/amd64) does not match the detected host platform (linux/arm64/v8) and no specific platform was requested
Error: unknown flag: --token
ERRO[0000] Exit with status 1 due to generic error error="unknown flag: --token"
Location
https://circleci.com/docs/2.0/local-cli/#run-a-job-in-a-container-on-your-machine
Steps to Reproduce
Run job that checks out the code and have the JIRA orb locally locally
Additional Context
running macOS Monterey 12.3.1 (21E258), Silicon apple chip
Docker:
$ docker version
Client:
Cloud integration: v1.0.20
Version: 20.10.10
API version: 1.41
Go version: go1.16.9
Git commit: b485636
Built: Mon Oct 25 07:43:15 2021
OS/Arch: darwin/arm64
Context: default
Experimental: true
Server: Docker Engine - Community
Engine:
Version: 20.10.10
API version: 1.41 (minimum version 1.12)
Go version: go1.16.9
Git commit: e2f740d
Built: Mon Oct 25 07:41:10 2021
OS/Arch: linux/arm64
Experimental: false
containerd:
Version: 1.4.11
GitCommit: 5b46e404f6b9f661a205e28d59c982d3634148f8
runc:
Version: 1.0.2
GitCommit: v1.0.2-0-g52b36a2
docker-init:
Version: 0.19.0
GitCommit: de40ad0
Config.yml
version: 2.1
orbs:
node: circleci/node#5.0.0
jira: circleci/jira#1.3.1
ruby: circleci/ruby#1.4.0
commands:
ch-checkout:
steps:
# Instead of the default `checkout` phase that doesn't support depth.
- run:
name: "Checkout Repository with --Depth 1"
command: |
SSH_CONFIG_DIR="/home/circleci/.ssh"
mkdir -p "$SSH_CONFIG_DIR"
chmod 0700 "$SSH_CONFIG_DIR"
echo "bitbucket.org ssh-rsa AAAAB3NzaC1yc2EAAAABIwAAAQEAubiN81eDcafrgMeLzaFPsw2kNvEcqTKl/VqLat/MaB33pZy0y3rJZtnqwR2qOOvbwKZYKiEO1O6VqNEBxKvJJelCq0dTXWT5pbO2gDXC6h6QDXCaHo6pOHGPUy+YBaGQRGuSusMEASYiWunYN0vCAI8QaXnWMXNMdFP3jHAJH0eDsoiGnLPBlBp4TNm6rYI74nMzgz3B9IikW4WVK+dc8KZJZWYjAuORU3jc1c/NPskD2ASinf8v3xnfXeukU0sJ5N6m5E8VLjObPEO+mN2t/FZTMZLiFqPWc/ALSqnMnnhwrNi2rbfg/rd/IpL8Le3pSBne8+seeFVBoGqzHM9yXw==" >> "$SSH_CONFIG_DIR/known_hosts"
chmod 0600 "$SSH_CONFIG_DIR/known_hosts"
cd '/home/circleci/myapp'
git clone --depth 1 "$CIRCLE_REPOSITORY_URL" --branch "$CIRCLE_BRANCH" .
- run: ls -la ~/myapp/
ch-install-compass:
steps:
- run:
name: Install ruby
command: |
sudo apt update
sudo apt install ruby-dev -y
ruby -v
- run:
name: Install compass
command: sudo gem install compass
ch-ls:
steps:
- run:
name: ls
command: ls
ch-widget-npm:
steps:
- node/install-packages
ch-widget-bower:
steps:
- run:
name: Widget - Install Deps (bower)
command: npx bower install
ch-widget-build:
steps:
- run:
name: Widget - Build
command: npx grunt build:prod
ch-widget-test:
steps:
- run:
name: Widget - Test
command: |
npx grunt build:dev
# this only works by repeating it twice in the same step the test is invoked 🤷‍♀️
Xvfb -s "-nolisten tcp -nolisten unix" -ac :99 -screen 0 1280x1024x16 &
export DISPLAY=:99
Xvfb -s "-nolisten tcp -nolisten unix" -ac :99 -screen 0 1280x1024x16 &
export DISPLAY=:99
npx karma start --browsers Chrome --single-run --env=ci --reporters dots
npx karma start --browsers Chrome --single-run --loader-tests --env=ci --reporters dots
ch-elements-npm:
steps:
- node/install-packages:
app-dir: city-hive-custom-elements
ch-elements-build:
steps:
- run:
name: Custom Elements - Build
command: cd city-hive-custom-elements/; npm run build
ch-elements-test:
steps:
- run:
name: Custom Elements - Tests
command: |
# this only works by repeating it twice in the same step the test is invoked 🤷‍♀️
Xvfb -s "-nolisten tcp -nolisten unix" -ac :99 -screen 0 1280x1024x16 &
export DISPLAY=:99
Xvfb -s "-nolisten tcp -nolisten unix" -ac :99 -screen 0 1280x1024x16 &
export DISPLAY=:99
cd city-hive-custom-elements/; npm run test -- --watch=false
ch-install-chrome:
steps:
- run:
name: Install chrome deps
command: sudo apt update && sudo apt install xdg-utils fonts-liberation libasound2 libatk-bridge2.0-0 libatk1.0-0 libatspi2.0-0 libcairo2 libcups2 libgbm1 libgtk-3-0 libnspr4 libnss3 libpango-1.0-0 libxdamage1 libxkbcommon0
- run:
name: Install chrome
command: |
wget https://dl.google.com/linux/direct/google-chrome-stable_current_amd64.deb
sudo dpkg -i google-chrome-stable_current_amd64.deb
ch-karma-deps:
steps:
- run:
name: Karma - Deps
command: |
sudo apt-get install -y xvfb
ch-spin-widget-dev:
steps:
- run:
name: Spin Widget
command: npx grunt serve:dev
background: true
ch-spin-elements-dev:
steps:
- run:
name: Spin Custom Elements
command: cd city-hive-custom-elements/; npm run serve
background: true
ch-cypress-deps:
steps:
- run:
name: Install Cypress deps
command: sudo apt update && sudo apt install libgtk2.0-0 libgtk-3-0 libgbm-dev libnotify-dev libgconf-2-4 libnss3 libxss1 libasound2 libxtst6 xauth xvfb
ch-wait-for-servers:
steps:
- run:
name: Wait for local servers
command: |
npx wait-on http://localhost:4200
npx wait-on http://localhost:9003
ch-cypress:
steps:
- run:
name: Run Cypress tests
no_output_timeout: 10m
command: |
mkdir ~/test_reports
./bin/ci_e2e
- store_test_results:
path: ~/test_reports
- store_artifacts:
path: ~/test_reports
jobs:
build-widget:
working_directory: ~/myapp
docker:
- image: cimg/node:16.13.1
environment:
# Enable colors in the output
TERM: xterm
steps:
- ch-checkout
- ch-install-compass
- ch-widget-npm
- ch-widget-bower
- ch-widget-build
test-widget:
working_directory: ~/myapp
docker:
- image: cimg/node:16.13.1-browsers
environment:
# Enable colors in the output
TERM: xterm
steps:
- ch-checkout
- ch-install-compass
- ch-widget-npm
- ch-widget-bower
- ch-install-chrome
- ch-karma-deps
- ch-widget-test
build-elements:
working_directory: ~/myapp
docker:
- image: cimg/node:16.13.1
environment:
# Enable colors in the output
TERM: xterm
steps:
- ch-checkout
- ch-elements-npm
- ch-elements-build
test-elements:
working_directory: ~/myapp
docker:
- image: cimg/node:16.13.1-browsers
environment:
# Enable colors in the output
TERM: xterm
steps:
- ch-checkout
- ch-elements-npm
- ch-elements-build
- ch-install-chrome
- ch-karma-deps
- ch-elements-test
e2e:
working_directory: ~/myapp
docker:
- image: cimg/node:16.13.1-browsers
resource_class: large
environment:
# Enable colors in the output
TERM: xterm
parallelism: 31
steps:
- ch-checkout
- ch-install-compass
- ch-widget-npm
- ch-widget-bower
- ch-elements-npm
- ch-spin-widget-dev
- ch-spin-elements-dev
- ch-install-chrome
- ch-cypress-deps
- ch-wait-for-servers
- ch-cypress
workflows:
build-and-test:
jobs:
- build-widget:
post-steps:
- jira/notify
- test-widget:
post-steps:
- jira/notify
- build-elements:
post-steps:
- jira/notify
- test-elements:
post-steps:
- jira/notify
- e2e:
post-steps:
- jira/notify
Try using CIRCLECI_CLI_TOKEN environment variable instead:
CIRCLECI_CLI_TOKEN=d14c4********* \
circleci build \
--branch master \
--repo-url https://bitbucket.org/cityhive/city-hive-standalone-widget \
--job e2e
# goldylucks,
The --token flag is a global flag for the CLI setup:
--token string your token for using CircleCI, also CIRCLECI_CLI_TOKEN
For the Jira orb, the CircleCI API token is needed as an environment variable.
Looking at the output of circleci build -help, I see:
-e, --env -e VAR=VAL Set environment variables, e.g. -e VAR=VAL
This is the flag you'd need to use, as outlined in the CircleCI CLI documentation.

CircleCI AWSCLI SyntaxError: Non-ASCII character '\xc3' error

I am working on a Ruby on Rails project where AWSCLI is used.
Recently, When I push my code to Staging, it tries to import newkeys, PrivateKey, PublicKey from rsa.key and throws an error.
The error message is as follows:
SyntaxError: Non-ASCII character '\xc3' in file /opt/circleci/.pyenv/versions/2.7.12/lib/python2.7/site-packages/rsa/key.py on line 1, but no encoding declared; see http://python.org/dev/peps/pep-0263/ for details
Error message Image
My circleci/config.yml file is as follows:
orbs:
aws-ecr: circleci/aws-ecr#7.0.0
version: 2.1
jobs:
build:
working_directory: ~/mfds
docker:
- image: circleci/ruby:2.3.4-node
environment:
RAILS_ENV: citest
LANG: C.UTF-8
- image: snowhork/mysql_jp:5.7
environment:
MYSQL_ROOT_PASSWORD: ***
MYSQL_DATABASE: myapp
MYSQL_USER: user
MYSQL_PASSWORD: ***
MYSQL_ROOT_HOST: "%"
steps:
- checkout
- restore_cache:
key: gemfiles-{{ checksum "mfds/Gemfile.lock" }}
# Bundle install dependencies
- run: cd mfds/ && bundle install --path vendor/bundle
# Store bundle cache
- save_cache:
key: gemfiles-{{ checksum "mfds/Gemfile.lock" }}
paths:
- /home/circleci/mfds/mfds/vendor/bundle
- run:
name: Wait for db
command: dockerize -wait tcp://localhost:3306 -timeout 1m
# Database setup
- run:
name: db setting
command: |
cd mfds
bundle exec rake db:create
bundle exec rake db:ridgepole:apply[citest]
- run:
name: rspec
command: |
cd mfds
bundle exec rspec
staging_deploy:
machine: true
steps:
- checkout
- run:
name: asset compile
command: |
cd mfds
npm install
./node_modules/.bin/webpack --optimize-minimize
- run:
name: gem install
command: |
gem install aws-sdk-ecs
pip install futures
pip install --upgrade awscli
- run:
name: push image
command: |
export AWS_ACCESS_KEY_ID=$XX_AWS_ACCESS_KEY_ID
export AWS_SECRET_ACCESS_KEY=$XX_AWS_SECRET_ACCESS_KEY
bin/deployv2/docker-push staging
- run:
name: update service
command: |
export AWS_ACCESS_KEY_ID=$XX_AWS_ACCESS_KEY_ID
export AWS_SECRET_ACCESS_KEY=$XX_AWS_SECRET_ACCESS_KEY
bin/deployv2/update-task staging
....
I don't understand how to resolve this problem.

Circle CI fails to execute psql command when running rake db:structure:load

So this is my config.yml
version: 2.1
orbs:
queue: eddiewebb/queue#1.5.0
executors:
node_postgres_redis:
docker:
- image: circleci/ruby:2.4.10-node-browsers
environment:
CC_TEST_REPORTER_ID: 7ceff1524bdc09dsd3e232321cf9daa531154170d590823232eddqw2330f3570
PGHOST: 127.0.0.1
RAILS_ENV: test
TEST_REPORT_PATH: "test/reports"
- image: circleci/postgres:9.6.2-alpine
environment:
POSTGRES_USER: circleci
POSTGRES_DB: circleci-jet-test
POSTGRES_PASSWORD: ""
- image: circleci/redis:3.2
ubuntu:
machine:
image: ubuntu-1604:202004-01
commands:
setup_and_run_test:
steps:
- checkout
# Restore bundle cache
- restore_cache:
key: jet-bundle-{{ .Branch }}-{{ checksum "Gemfile.lock" }}
# imagemagic
- run:
name: Setup Image Magick
command: |
sudo apt-get install libmagickwand-dev imagemagick imagemagick-6.q16 libmagickcore-dev
sudo ln -s /usr/lib/x86_64-linux-gnu/ImageMagick-6.9.7/bin-q16/Magick-config /usr/bin/Magick-config
- run:
name: Install Bundler
command: |
gem install bundler -v 1.17.3
# Install gem dependencies
- run: bundle check --path=vendor/bundle || bundle install --path=vendor/bundle
# Store bundle cache
- save_cache:
key: jet-bundle-{{ .Branch }}-{{ checksum "Gemfile.lock" }}
paths:
- vendor/bundle
# Database setup
- run:
name: Database Setup
command: |
bundle exec rake db:create
bundle exec rake db:migrate
bundle exec rake db:structure:load
Everythings runs properly until it tries to execute
bundle exec rake db:structure:load
Then it throws this error which is a bit weird
failed to execute:
psql -q -f /home/circleci/circleci-jet/db/structure.sql *****_test
Please check the output above for any errors and make sure that psql is installed in your PATH and has proper permissions.
I cannot understand this error and what needs to be done on my side.
Anyone with examples, please can show me direction.
Thanks

CircleCI 2.0 - exit code 127, bundle command not found

I'm trying to get a rails app to run on Circle CI. With the following configuration I can't seem to get anything to work at all. When I ssh in, I can't even run sudo.
Here's the error output:
install dependencies
$ #!/bin/bash -eo pipefail
bundler install --jobs=4 --retry=3 --path vendor/bundle
/bin/bash: bundler: command not found
Exited with code 127
I noticed there is nothing but assets/ under the vendor directory.
Here's my configuration file:
version: 2
jobs:
build:
working_directory: ~/repo
docker:
- image: circleci/postgres:9.6-alpine-postgis-ram
- image: circleci/ruby:2.3
environment:
PGHOST: 127.0.0.1
PGUSER: staging
RAILS_ENV: test
- image: circleci/postgres:10.5
environment:
POSTGRES_USER: staging
POSTGRES_DB: test
POSTGRES_PASSWORD: ""
steps:
- checkout
# Download and cache dependencies
- restore_cache:
keys:
- v1-dependencies-{{ checksum "Gemfile.lock" }}
# fallback to using the latest cache if no exact match is found
- v1-dependencies-
- run:
name: install dependencies
command: |
bundle install --jobs=4 --retry=3 --path vendor/bundle
- save_cache:
paths:
- ./vendor/bundle
key: v1-dependencies-{{ checksum "Gemfile.lock" }}
# Database setup
- run: bundle exec rake db:create
- run: bundle exec rake db:schema:load
# run tests!
- run:
name: run tests
command: |
mkdir /tmp/test-results
TEST_FILES="$(circleci tests glob "spec/**/*_spec.rb" | circleci tests split --split-by=timings)"
bundle exec rspec --format progress \
--format RspecJunitFormatter \
--out /tmp/test-results/rspec.xml \
--format progress \
$TEST_FILES
# collect reports
- store_test_results:
path: /tmp/test-results
- store_artifacts:
path: /tmp/test-results
destination: test-results
All help is appreciated, thanks!
Your commands are running on the postgres container because it is listed first. If you make the ruby container first, then you will have access to bundle. And then when you SSH, you will be inside of the ruby container.
https://circleci.com/docs/2.0/configuration-reference/#docker--machine--macosexecutor
The first image listed in the file defines the primary container image where all steps will run.

Circle Ci- Run rspec tests parallely

I added an additional container in circle ci and tried to run tests parallaly.
This is my circle.yml file.
machine:
ruby:
version: 2.3.0
database:
post:
- cp config/sunspot.ci.yml config/sunspot.yml
- bundle exec sunspot-solr start -p 8981
dependencies:
pre:
- sudo apt-get update; sudo apt-get -y install solr-tomcat
test:
override:
- rvm use 2.3.0 && bundle exec rspec --color --format progress:
environment:
RAILS_ENV: test
parallel: true
files:
- "spec/**/*_spec.rb"
but tests don't seem to be running in parallel.
What am I missing? Thanks in advance
For some reason removing rvm use 2.3.0 from test section fixed my problem.
machine:
ruby:
version: 2.3.0
database:
# After default database task finished
post:
# Circle CI already replace our original sunspot.yml, replace it with backup copy `config/sunspot.yml.ci`
- cp config/sunspot.ci.yml config/sunspot.yml
- bundle exec sunspot-solr start -p 8981
dependencies:
pre:
- sudo apt-get update; sudo apt-get -y install solr-tomcat
test:
override:
- bundle exec rspec --tag ~#flaky --color --profile 20 --format progress:
timeout: 240
environment:
RAILS_ENV: test
parallel: true
files:
- my files here

Resources