[Note] About CircleCI / Ruby (minimum configuration of official doc.) Outline of each setting item and reference link

Introduction

This is a memorandum that I checked each item of the configuration file in Language Guide: Ruby --CircleCI. I tried a short explanation within the scope of my interpretation, but overall it became closer to the linked links.

Purpose of this post

--Understanding the structure of /. Circleci / config.yml --Preparing to streamline similar investigations --Posting experience points

Main story

Links to the relevant tags in the references below are posted in various places. ** Reference of each setting item ** Configure CircleCI-CircleCI

/.circleci/config.yml

version: 2.1 # Use 2.1 to enable using orbs and other features.

 Declare the orbs that we'll use in our config.
 read more about orbs: https://circleci.com/docs/2.0/using-orbs/
orbs:
  ruby: circleci/[email protected] 
  node: circleci/node@2

jobs:
  build: # our first job, named "build"
    docker:
      - image: cimg/ruby:2.7-node # use a tailored CircleCI docker image.
    steps:
      - checkout # pull down our git code.
      - ruby/install-deps # use the ruby orb to install dependencies
      # use the node orb to install our packages
      # specifying that we use `yarn` and to cache dependencies with `yarn.lock`
      # learn more: https://circleci.com/docs/2.0/caching/
      - node/install-packages: 
          pkg-manager: yarn
          cache-key: "yarn.lock"
          
  test:  # our next job, called "test"
    # we run "parallel job containers" to enable speeding up our tests;
    # this splits our tests across multiple containers.
    parallelism: 3 
    # here we set TWO docker images.
    docker:
      - image: cimg/ruby:2.7-node # this is our primary docker image, where step commands run.
      - image: circleci/postgres:9.5-alpine 
        environment: # add POSTGRES environment variables.
          POSTGRES_USER: circleci-demo-ruby
          POSTGRES_DB: rails_blog_test
          POSTGRES_PASSWORD: ""
    # environment variables specific to Ruby/Rails, applied to the primary container.
    environment:
      BUNDLE_JOBS: "3"
      BUNDLE_RETRY: "3"
      PGHOST: 127.0.0.1
      PGUSER: circleci-demo-ruby
      PGPASSWORD: ""
      RAILS_ENV: test
    # A series of steps to run, some are similar to those in "build".
    steps:
      - checkout 
      - ruby/install-deps 
      - node/install-packages:
          pkg-manager: yarn
          cache-key: "yarn.lock"
      # Here we make sure that the secondary container boots 
      # up before we run operations on the database.
      - 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 rspec in parallel
      - ruby/rspec-test

 We use workflows to orchestrate the jobs that we declared above.
workflows:
  version: 2
  build_and_test:     # The name of our workflow is "build_and_test"
    jobs:             # The list of jobs we run as part of this workflow.
      - build         # Run build first.
      - test:         # Then run test,
          requires:   # Test requires that build passes for it to run.
            - build   # Finally, run the build job.

About the outline of each setting item Orbs, Jobs, Steps, Workflows-CircleCI

version:

version: 2.1 # Use 2.1 to enable using orbs and other features.

version --Set CircleCI --CircleCI Specifies the CircleCI version.

orbs:

orbs:
  ruby: circleci/[email protected] 
  node: circleci/node@2

** Documentation about Orb ** What is Orbs? --CircleCI Using Orbs --CircleCI orbs --Set CircleCI-CircleCI

An Orb is a sharable package of configuration elements such as jobs and commands. This setting item describes what to import from Orbs in CircleCI Orb Registry.

** Orb registry page used this time **  Ruby : CircleCI Orb Registry - circleci/ruby  Node : CircleCI Orb Registry - circleci/node

(`ʻOrb Source`` in the Orb registry documentation is just the source code for generating the documentation page. If you want to see the source information of Orb itself (including the file hierarchy), you need to refer to the GitHub repository. )

jobs:

jobs --Configure CircleCI-CircleCI The jobs in this case consist of two parallel jobs, build and test.

build:

  build: # our first job, named "build"
    docker:
      - image: cimg/ruby:2.7-node # use a tailored CircleCI docker image.
    steps:
      - checkout # pull down our git code.
      - ruby/install-deps # use the ruby orb to install dependencies
      # use the node orb to install our packages
      # specifying that we use `yarn` and to cache dependencies with `yarn.lock`
      # learn more: https://circleci.com/docs/2.0/caching/
      - node/install-packages: 
          pkg-manager: yarn
          cache-key: "yarn.lock"

docker:

    docker:
      - image: cimg/ruby:2.7-node # use a tailored CircleCI docker image.

docker --Set CircleCI --CircleCI Set the Docker image, entry point, command, etc. Similar to docker-compose settings.

steps:

    steps:
      - checkout # pull down our git code.
      - ruby/install-deps # use the ruby orb to install dependencies
      # use the node orb to install our packages
      # specifying that we use `yarn` and to cache dependencies with `yarn.lock`
      # learn more: https://circleci.com/docs/2.0/caching/
      - node/install-packages: 
          pkg-manager: yarn
          cache-key: "yarn.lock"

steps --Set CircleCI --CircleCI

checkout checkout --Set CircleCI --CircleCI Specify the checkout directory. By default working_directory

Behind the scenes, it seems that the Bourne shell script is running to check out the GitHub source code. It will be useful for studying around SSH, so I will check the opportunity again.

ruby/install-deps This command is defined in Orb --circleci / ruby.

description: Install gems with Bundler. (Quote: From source)

Install Gem using Bundler.

test:

  test:  # our next job, called "test"
    # we run "parallel job containers" to enable speeding up our tests;
    # this splits our tests across multiple containers.
    parallelism: 3 
    # here we set TWO docker images.
    docker:
      - image: cimg/ruby:2.7-node # this is our primary docker image, where step commands run.
      - image: circleci/postgres:9.5-alpine 
        environment: # add POSTGRES environment variables.
          POSTGRES_USER: circleci-demo-ruby
          POSTGRES_DB: rails_blog_test
          POSTGRES_PASSWORD: ""
    # environment variables specific to Ruby/Rails, applied to the primary container.
    environment:
      BUNDLE_JOBS: "3"
      BUNDLE_RETRY: "3"
      PGHOST: 127.0.0.1
      PGUSER: circleci-demo-ruby
      PGPASSWORD: ""
      RAILS_ENV: test
    # A series of steps to run, some are similar to those in "build".
    steps:
      - checkout 
      - ruby/install-deps 
      - node/install-packages:
          pkg-manager: yarn
          cache-key: "yarn.lock"
      # Here we make sure that the secondary container boots 
      # up before we run operations on the database.
      - 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 rspec in parallel
      - ruby/rspec-test

parallelism:

parallelism: 3

parallelism --Set CircleCI --CircleCI This is a setting for parallel processing of job steps.

CircleCI has a mechanism for distributing tests across multiple machines and running them in parallel in order to reduce the time it takes to test a project. Specify the number of parallel machines in the parallelism key. I will. About parallel jobs: Parallel execution of tests --CircleCI

docker:

    docker:
      - image: cimg/ruby:2.7-node # this is our primary docker image, where step commands run.
      - image: circleci/postgres:9.5-alpine 
        environment: # add POSTGRES environment variables.
          POSTGRES_USER: circleci-demo-ruby
          POSTGRES_DB: rails_blog_test
          POSTGRES_PASSWORD: ""

Build a test environment.

environment:

    environment:
      BUNDLE_JOBS: "3"
      BUNDLE_RETRY: "3"
      PGHOST: 127.0.0.1
      PGUSER: circleci-demo-ruby
      PGPASSWORD: ""
      RAILS_ENV: test

environment --Set CircleCI --CircleCI Set environment variables for Rails + PostgreSQL.

steps:

    # A series of steps to run, some are similar to those in "build".
    steps:
      - checkout 
      - ruby/install-deps 
      - node/install-packages:
          pkg-manager: yarn
          cache-key: "yarn.lock"
      # Here we make sure that the secondary container boots 
      # up before we run operations on the database.
      - 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 rspec in parallel
      - ruby/rspec-test

run

      - 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 --Set CircleCI --CircleCI This item is for calling a command line program.

dockerize -wait tcp://localhost:5432 -timeout 1m Waits for the DB service to start. [Waiting for dependencies using #Dockerize-Database settings-CircleCI](https://circleci.com/docs/ja/2.0/databases/#dockerize-%E3%82%92%E4%BD%BF% E7% 94% A8% E3% 81% 97% E3% 81% 9F% E4% BE% 9D% E5% AD% 98% E9% 96% A2% E4% BF% 82% E3% 81% AE% E5% BE% 85% E6% A9% 9F) Official dockerize repository: jwilder / dockerize: Utility to simplify running applications in docker containers

bundle exec rails db:schema:load --trace It does not handle migration files and creates a database from db / schema.rb. Create database with schema file --Rake --Rails documentation](https://railsdoc.com/rake#rake_db_schema_load) [6.1 About the meaning of schema files --Active Record migration --Rails guide](https://railsguides.jp/active_record_migrations.html#%E3%82%B9%E3%82%AD%E3%83%BC%E3%83 % 9E% E3% 83% 95% E3% 82% A1% E3% 82% A4% E3% 83% AB% E3% 81% AE% E6% 84% 8F% E5% 91% B3% E3% 81% AB % E3% 81% A4% E3% 81% 84% E3% 81% A6)

workflows:

 We use workflows to orchestrate the jobs that we declared above.
workflows:
  version: 2
  build_and_test:     # The name of our workflow is "build_and_test"
    jobs:             # The list of jobs we run as part of this workflow.
      - build         # Run build first.
      - test:         # Then run test,
          requires:   # Test requires that build passes for it to run.
            - build   # Finally, run the build job.

workflows --Configure CircleCI --CircleCI Settings for automating jobs.

version: version --Set CircleCI --CircleCI

build_and_test: workflow_name --Set CircleCI --CircleCI

jobs: jobs --workflow_name --set CircleCI --CircleCI requires to clarify the job dependencies and specify the jobs that should be completed by the time this job runs. That is, test is executed after build is executed and completed.

Recommended Posts

[Note] About CircleCI / Ruby (minimum configuration of official doc.) Outline of each setting item and reference link
[Ruby] Review about nesting of each