[DOCKER] [Challenge CircleCI from 0] Learn the basics of CircleCI

background

I aim to get a job at an in-house developed company from inexperienced. I decided to study CircleCI to create a good portfolio.

The current level of knowledge is that you can easily develop applications using Ruby on rails, version control using git, and deploy using heroku. I hope it will be of some help to those who are thinking of trying CircleCI in the future at the same level as their own memorandum.

final goals

Understand what CircleCI is. Suppress the basics of writing CircleCI.

【Related article】 [Challenge CircleCI from 0] Learn the basics of CircleCI [Challenge CircleCI from 0] Build an automated test (Rails6.0 / mysql8.0 / Rspec) [Challenge CircleCI from 0] Understand AWS ECR / ECS [Challenge CircleCI from 0] Automatically deploy with CircleCI / AWS (ECR / ECS)

table of contents

① About CI / CD (2) Reasons for choosing CircleCI-Comparison of other tools ③Rough flow of testing using CircleCI (4) How to write the CircleCI configuration file

Let's go fast.

① About CI / CD

Meaning of CI / CD

CI (Continuous Integration) means continuous integration, and CD (Continuous Delivery / Deployment) means continuous delivery or continuous deployment. To be more specific, it is a mechanism that "when you push to a version control system such as git, it will be tested automatically, and if the test is cleared, it will be deployed automatically".

Why CI / CD is attracting attention

This is because the idea of "DevOps" has recently spread to the engineering world. "DevOps" is the idea of breaking down the barrier between the development team and the operation team and growing the business, and CI / CD is attracting attention as one method for practicing "DevOps".

(2) Reasons for choosing CircleCI-Comparison of other tools

There are several well-known CI / CD tools. Let's compare them briefly and see why CircleCI is chosen.

Jekins A typical on-premise CI / CD tool. It's open source and it's great for plug-in extensions.

CircleCI saas type CI / CD tool. It also works well with GitHub and recommends using Docker, which has exploded in recent years. You can also connect via ssh.

Travis CI This is also a saas type CI / CD tool. Its strength is that it supports a wide range of languages and can introduce CI with simple settings.

Gitlab A git CI tool famous for version control software. Apparently, it doesn't have that much share in the industry, but it may grow in the future.

The above are considered to be the main famous tools. Regarding the criteria for choosing, first decide whether it is an on-premise type or a saas type. For personal development, the saas type, which has low operating costs, is definitely better. If it is a saas type, it does not matter which one you use, but personally, I choose CircleCI, which is currently the most popular in the industry and recommends docker, which is a content technology that has been attracting attention in recent years. I think that is the best. (* Of course, if you are using Docker for your development environment)

③Rough flow of testing using CircleCI

The flow itself is very simple.

  1. Create a circleCI account (it is easier to link with a github account at this time)
  2. Link with github after creating an account
  3. Select one repository from github
  4. Create (.circleci / config.yml) in the root directory of the selected repository
  5. Write code for CircleCi
  6. Push to git
  7. Start automatic test
  8. The result is reflected in the pull request

Once you've written the CircleCI code, it's no different from the usual git development process. So I think the neck will be the description part of the file (.circleci / config.yml).

(4) How to write the CircleCI configuration file

About YAML files

Write all CircleCI settings in a YAML file. What is a YAML file? It is a format that describes data in the same way as XML and JSON. By the way, YAML is an abbreviation for (yaml ain't markup language). I feel a sense of defining myself.

And the feature of YAML is that it is intuitive and easy to understand. It is mainly made up of the following three description methods.

yaml


#① List → Array
- 1
- 2
- 3

#② Map → Hash
name: a
id :  1
text: ccc

#③ Scalar → Other than list and map
true false
null
123

Of course, the actual file is a bit more complicated as the above is written over multiple lines. However, there are only three basics, so keep this in mind.

About the basic structure of the file

CircleCI files are made up of several components. Let's check one by one.

I. Project

It has nothing to do with the file description, but simply put, the github repository is treated as one project by CircleCI.

Ii. Step

The smallest unit on a file. Specifically, it is a command list to be executed by CircleCI. (Although it is the smallest unit in the concept on CircleCI, the steps are just a list, so they may span multiple lines). By the way, there are two types of steps, run step and build-in step. The former is defined by the user, and the latter is a special one prepared by CircleCI.

Iii. Job

A group of steps is called a job.

Ⅳ. Executor

Refers to the job step environment. For example, if it is "Docker Executor", execute the steps in the Docker environment. In addition to Docker, there are "macOS Executor", "Machine Executor", "windows Executor", etc., and you can freely set the environment.

Ⅴ. Workflow

It is a rule of job execution order. Basically, there are multiple jobs in one file, and the workflow defines the order in which they will be executed. It can also be executed in parallel. Workflows also have caches, workspaces, and artifacts as data persistence mechanisms. Let's take a concrete example.

For example, suppose you have files in the order "A job-> B job-> C job". When the "A job" is finished, suppose you want to take over the contents of the "A job" and perform the "B job". This method of sharing data from "A job" to "B job" is called *** workspace ***. Next, suppose that an error occurs in "C job" when executing the file in the above procedure. In such a case, it is necessary to execute from 1 again after modifying the file, that is, from "A job". If "A job" or "B job" contains a step to read a heavy file, it will take time. In such a case, the method of taking over the file that was done the first time and sharing the data so that it can be done smoothly from the second time onward is called *** cache ***. And if you execute the file as above, a lot of data about the job execution result will be generated. The storage that stores the execution results of this job is called *** artifact ***. It may be a little confusing, but let's remember.

Ⅵ. Pipeline

Actually, you can create multiple workflows, and there is a pipeline to put them together. Basically, CircleCI can only have one (.circleci / config.yml) for one project. In other words, there is only one pipeline for a project, which is the largest concept in the file that organizes workflows. * By the way, CircleCI will implement new functions based on the concept of this pipeline.

ⅶ. Orbs Orbs is a package of a series of processes such as steps and jobs that can be used in various places. You can create Orbs yourself, but you can use the ones published on CircleCI orb Registry.


This article will be cut here. In the next article, I will write a specific file and run an automated test.

Summary / impression

Basically, unlike Docker, it was easy to understand the general flow and roles. However, when it comes to writing files in the future, it's a bit of a pain. Also, CircleCI has a little difficulty because there are few Japanese materials. I will continue to do my best.

reference

[Book] "Introduction to CircleCI Practice: Balancing Development Speed and Quality Brought by CI / CD Masato Urai (Author), Tomoya Otake (Author), Hirokuni Kim (Author)"

【qiita】 "I've just started CircleCI, so I've summarized it in an easy-to-understand manner"

Recommended Posts

[Challenge CircleCI from 0] Learn the basics of CircleCI
[Summary of technical books] Summary of reading "Learn Docker from the basics"
Docker monitoring-explaining the basics of basics-
Understand the basics of docker
The basics of Swift's TableView
About the basics of Android development
The basics of SpringBoot + MyBatis + MySQL
Understand the basics of Android Audio Record
[Challenge CircleCI from 0] Understand AWS ECR / ECS
[Ruby] From the basics to the inject method
Now, I've summarized the basics of RecyclerView
[Challenge Docker from 0] Overview and terms of Docker
The story of RxJava suffering from NoSuchElementException
[day: 5] I summarized the basics of Java
Ruby from the perspective of other languages
Looking back on the basics of Java
Find the difference from a multiple of 10
What is JSP? ~ Let's know the basics of JSP !! ~
[Ruby] Summary of class definitions. Master the basics.
Has the content of useBodyEncodingForURI changed from Tomcat8?
I understood the very basics of character input
The basics of the App Store "automatic renewal subscription"
A fledgling engineer learned JUnit from the basics
Basics of Ruby
Learn the rudimentary mechanism and usage of Gradle 4.4
Learn while making a WEB server Introduction to WEB application development from the basics
[SPA development with Rails x Vue] Learn the basics of Vue.js (Overview of vue.js, template syntax)
ArrayList and the role of the interface seen from List
From the introduction of devise to the creation of the users table
Volume 3 types of Docker Compose considered from the purpose
How to write Scala from the perspective of Java
[For beginners] DI ~ The basics of DI and DI in Spring ~
[For beginners] Quickly understand the basics of Java 8 Lambda
About the usefulness of monads from an object-oriented perspective
The story of migrating from Paperclip to Active Storage
Java language from the perspective of Kotlin and C #
I summarized the types and basics of Java exceptions
Extract a specific element from the list of objects
[Ruby] Class nesting, inheritance, and the basics of self
A record of studying the Spring Framework from scratch
The world of clara-rules (2)
Judgment of the calendar
The world of clara-rules (4)
The world of clara-rules (1)
The world of clara-rules (3)
Basics of try-with-resources statement
The world of clara-rules (5)
The idea of quicksort
The idea of jQuery
The story of raising Spring Boot from 1.5 series to 2.1 series part2
I tried to summarize the basics of kotlin and java
Learning from the basics Artificial intelligence textbook Chapter 3 End-of-chapter problems
Get to the abbreviations from 5 examples of iterating Java lists
A story packed with the basics of Spring Boot (solved)
The story of throwing BLOB data from EXCEL in DBUnit
How to get the longest information from Twitter as of 12/12/2016
Learning from the basics Artificial intelligence textbook Chapter 4 Chapter end problems
From the habit of creating Value Objects for object-oriented understanding
Aggregate the number of people every 10 years from List <Person>
Learn how to customize the Navigation Bar from the sample app
Learning from the basics Artificial intelligence textbook Chapter 2 Chapter end problems