preface
When using CI tools for continuous integration, it is inevitable to define a configuration file in which the project workflow is defined. Circle is a CI tool friendly to open source projects. This paper will start with CircleCI to parse the configuration item: image field that defines Docker image in the configuration file.
For most users who try to use CircleCI for the first time, the most difficult thing to deal with is the definition of image under the docker field in the configuration when using the Docker image. This article describes how to configure the image option – using CircleCI Convenience Image – and best practices for configuring it.
The two types of Convenience Image
Language mirror
Service Image
Language mirror
The language class image has some language-specific dependencies and tools built in.
The language class image needs to be defined in the first image field under the Docker field as the primary container for execution.
List of languages supported by the language class image:
- Android
- Clojure
- Elixir
- Go (Golang)
- JRuby
- Node.js
- OpenJDK (Java)
- PHP
- Python
- Ruby
- Rust
format
docker:
-image: circleci/language:version[-tag]
Copy the code
Configuration of the sample
Docker: - image: circleci/golang: 1.9Copy the code
Language mirroring variants
CircleCI also provides a variant of the language-class mirror, in which one language dependency is added with more dependencies, pre-loaded with other languages and tools
By adding the following suffixes, you can use a preset Image with more dependencies on a particular Convenience Image
-
-node
- Added Nodejs dependencies
-
-browsers
- Added browser-dependent dependencies
- includes Chrome, Firefox, Java 8, and Geckodriver
-
-browsers-legacy
- Roughly the same, slightly different
- includes Chrome, Firefox, Java 8, and PhantomJS
-
-node-browsers
- Added dependencies provided by the -node variant and the -browser mirror variant
-
-node-browsers-legacy
- Also added are the dependencies provided by the -Node variant and the -Browsers – Legacy mirroring variant
Configuration of the sample
- image: circleci/node:10-jessie-browsers
Copy the code
Service Image
Service class mirroring is primarily used when providing services to a project, such as database services.
They must be defined after the language class image as a secondary image.
CircleCI provides service class mirrors for the following services
- buildpack-deps
- DynamoDB
- MariaDB
- MongoDB
- MySQL
- PostgreSQL
- Redis
Configuration of the sample
- image: circleci/mongo: 4.1.7 - xenialCopy the code
Service class mirror variant
CircleCI provides only one variant, -ram, for service class mirroring
Configuration of the sample
- image: circleci/postgres: 9.5 - postgis - ramCopy the code
Best Practices for configuring mirroring
Define the most accurate version of the mirror
This is because CircleCI Convenience Image is based on the latest version of the upstream Image, for example CircleCI/Ruby: 2.4-Node is based on the latest Ruby 2.4-node container Image.
By using the most accurate Image, the instability caused by the update of the Convenience Image caused by the update of the upstream Image can be avoided, thus ensuring the stability of the project operation environment.
The best practice for configuring an Image is to fix the version of the Image with an extra label.
That is, instead of using circleci/ Ruby: 2.4-Node images, add a tag -Jessie or -stretch to fix the operating system used for the image, To ensure that the project is using images based on a particular Debian system (e.g. Circleci/Ruby :2.3.7- Jessie)
We can also use the most accurate mirror by specifying the SHA version of the mirror.
There are two ways to use accurate mirroring:
- Use a label to fix the system type of the image
- Use an explicit Docker image ID
# Best practice examples
Example # 1
# Use fixed system mirroring- image: circleci/ruby: 2.4.2 - Jessie - nodeExample # 2
# Use fixed version mirroring
- image:circleci/ruby@sha256:df1808e61a9c32d0ec110960fed213ab2339451ca88941e9be01a03adc98396e
Copy the code
The suffixes available for all Convenience images
Please check the file: circleci.com/docs/2.0/do…
Sample configuration
A CircleCI project configuration file with node. js language image and MongDB service image
# .circleci/config.ymlVersion: 2.1jobs: Build: docker: -image: Circleci /node: 10.13-Jef-Browsers - image: Circleci/Mongo :4.0.4- Xenial-ram Steps: -run: Fecho "A first hello"
Copy the code