Building a Platform-Agnostic Container Image
- 1 Process
- 2 Example using a Python Micro-Service
- 2.1.1 Main steps
- 2.1.2 Manifest List and Image Layers
- 2.1.3 Source code
- 2.1.3.1 Code structure
- 2.1.3.2 Python App
- 2.1.3.3 Requirements
- 2.1.3.4 Dockerfile
- 2.2 Build arm image (A)
- 2.3 Push arm image to the registry
- 2.4 Build Intel image (B)
- 2.5 Push Intel image to the registry
- 2.6 Create a manifest list for image A and image B
- 2.7 Verify that the manifest describes a platform-agnostic container image.
- 2.8 Push the manifest list to the registry
- 3 Building Multi-CPU container images using CI/CD pipelines
- 4 Intermediate Image Naming Convention
Process
In general, the process to build a platform-agnostic container image follows the flow depicted on the following figure.
The commands needed to implement the flow are described, using an example, in the next section.
Example using a Python Micro-Service
Main steps
The following diagram captures the main steps we need to take to enable platform-agnostic containers:
(1) and (2) Build and push container images for each platform.
(3) Create and push a manifest list for the images above
(4) Pull and run the exact same image/tag on different platforms.
Manifest List and Image Layers
Digging a little bit deeper into step (4), the following diagram shows the relationship between a manifest list and image manifests for our platform-agnostic image (tag).
The following sections describe the commands needed to create a multi-cpu architecture container image. Let's call the image onap/py-app.
Note that this flow could be used by ONAP developers during the development-test-debug process.
For the release process, the flow will implemented using CI/CD pipelines as shown in the next section.
Source code
Code structure
.
├── app
│ ├── main.py
│ └── requirements.txt
└── Dockerfile
Python App
from flask import Flask
import platform
app = Flask(__name__)
@app.route("/")
def hello():
return "Hello ONAP. I am a Python service running on " + platform.machine()
if __name__ == "__main__":
app.run(host='0.0.0.0', debug=True, port=5000)
Requirements
Flask==0.10.1
Dockerfile
Build arm image (A)
Log into an arm server, copy the code into the structure depicted above.
cd to the root of the code tree above, then execute
Push arm image to the registry
Once the image has been successfully built, push it to the repository.
Note that if you are using a private repository, you might need to "docker tag" the image before executing the next command.
Build Intel image (B)
Log into an intel server, setup the code structure as before.
Let's now repeat the process for the intel layers of the multi-cpu container image.
Push Intel image to the registry
Create a manifest list for image A and image B
Now that we have built and pushed layers for each cpu architecture, we can create the manifest list to put the final container image together with
Verify that the manifest describes a platform-agnostic container image.
Verify that the manifest actually represents a multi-cpu architecture by looking at the different "platform" entries.
Notice how, in this case, the manifest shows layers for both arm and Intel cpu architectures.
Push the manifest list to the registry
Building Multi-CPU container images using CI/CD pipelines
The following diagram depicts a CI/CD flow that implements the production of multi-cpu architecture container images.
Although the flow shows a pipeline for two branches: arm-linux and intel-linux, the model can be extended --given the hardware and software resources-- to any number of platforms.
The following view illustrates intermediate step of building and storing executable and sequence of image processing
Intermediate Image Naming Convention
As described above, platform-agnostic support requires platform specific images that are put together to expose a multi-platform image. Platform architectures include, among others, arm,intel
, mips
, ppc64le
, and s390x
These platform-specific image names are typically used only by developers that build the images. ONAP end users should only use the aggregate tag but can still inspect the image using docker manifest.
The following is the recommended naming convention for ONAP platform-specific images that will be produced by the different pipelines (<onap-image-name>). This convention is aligned with existing industry standards and naming conventions (amd64, arm64v8).
Architecture | OS | Variant | Image Name |
---|---|---|---|
amd64 | Linux | <onap-image-name>-amd64 | |
arm64 | Linux | v8 | <onap-image-name>-arm64v8 |
mips | Linux | <onap-image-name>-mips |
Note: This table does not contain a exhaustive list of options and must only be used as an image naming guide. Because ONAP is vendor-agnostic, the list is not a statement of what architectures or OSs ONAP must support.