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.
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)
① 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.
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".
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".
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)
The flow itself is very simple.
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).
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.
CircleCI files are made up of several components. Let's check one by one.
It has nothing to do with the file description, but simply put, the github repository is treated as one project by CircleCI.
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.
A group of steps is called a job.
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.
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.
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.
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.
[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