Pai-build responsible for building all services and pushing images.
We have two parts of Pai-build: build script
and build context
.
- build script: responsible for build logic implementation all scripts are put under
build/
. It consistspai_build.py
,core
andmodel
.- pai_build.py: entrance of build system.
- core: all build logic implementation scripts are put under
build/core/
folder.build_center.py
contains main execution process.build_handler.py
is used to define single component build process.build_utility.py
contains the utility methods like docker client. - model:
dependency_graph.py
andconfig_model.py
are put underbuild/model/
folder.dependency_graph.py
defines ServiceNode and ServiceGraph to help construct component dependency graph.config_model.py
defines build configuration model.
- build context: All components’ source code, build context and deployment related code will be put under
src
folder.- Each component's build context will be put under
src/${componentName}/build
folder. Component owner should put correspondingdockerfiles
here, and define its dependency incomponents.dep
. if component needs define customize actions before or after image build, he can preparebuild-pre.sh
andbuild-post.sh
file.- dockerfiles: All public dockerfiles current component provides. Pai-build will execute docker build with all files which extension is .dockerfile and the image name will be same as filename.
- components.dep: Dependency list to determine components build sequence. Dependency wrote in
components.dep
should just be component name and make sure it can be found under src folder. Pai-build will copy the item’s whole folder tosrc/${componentName}/dependency/
. - build-pre.sh: Define customize action before build. If component needs to do preparation before image build, component owner can implement in
build-pre.sh
file. - build-post.sh: Define customize action after build. By default, we only build docker image, but for some service it may need to expose more than image. Component owner can implement in
build-post.sh
file.
- generated and dependency folder are temp folder put under
src/${componenName}/
, it will be cleaned automatically after each build round.- generated/: Temp folder to store all the generated things after build. If component needs to expose more than image, the owner should put all the exposed things under
src/${componenName}/generated
. - dependency/: Temp folder to store all dependency the component needs. Pai-build will copy all dependencies component to
src/${componenName}/dependency
.
- generated/: Temp folder to store all the generated things after build. If component needs to expose more than image, the owner should put all the exposed things under
- Each component's build context will be put under
Build image by using pai_build.py
which put under build/
. for the configuration please refers to how-to-write-pai-configuration.
./pai_build.py build -c /path/to/configuration-dir/ [ -s component-list ]
- Build the corresponding component.
- If the option
-s
is added, only the specified component will be built. By default will build all components undersrc/
./pai_build.py push -c /path/to/configuration-dir/ [ -i image-list ]
- tag and push image to the docker registry which is configured in the
cluster-configuration
. - If the option
-i
is added, only the specified image will be pushed. By default will push all images which.dockerfile
can be found under{src/${componentName}/build/
- Parse command to figure out component lists which need to build.
- Flatten all components folder, then get image to component map.
- Resolve component dependency according to
components.de
and DockerfileFROM
statement to construct dependency graph then get topological build sequence. - Build each single component accoding to toplogical sequence :
- Copy dependencies into temp
src/${componentName}/dependency
. - Run build-pre.sh if it exists.
- Check whether
*.dockerfile
exists if so call “docker build” command to build docker image. - Run build-post.sh if it exists.
- Copy dependencies into temp
- Clean all temp folders.
pai_build.py
will be executed under pai root folder.*.dockerfile
which put undersrc/${componentName}/build
means it can become public, component owners should obey the principle.- dockerfile build will be executed under
src/${componentName}/
, please pay attention when writing dockerfile. - All the dependencies will be copied to
src/${componentName}/dependency/
, please pay attention when writing dockerfile. - Dependency wrote in
components.dep
should just be component name and make sure it can be found under src folder. - For the dependency wrote in components.dep, the dependency’s whole folder will be copied into current component dependency folder.
This chapter will teach you how to add your customized component to pai. After everything is done, pai_build will build component and push image to the target docker registry.
Assuming you want to add componentB which only depends on componentA, and its image build needs files from /test-build/
.
If your component image could be pulled from a public docker registry, you could skip this step.
Create componentB folder under src
, then create build
folder to store build context.
There is no special restrictions on how to write the dockerfile. If you a new developer of docker, please refer to this tutorial and learn how to dockerfile. The file should be named with componentB.dockerfile
FROM ubuntu:16.04
COPY dependency/componentA/ /usr/local/
COPY dependency/test-build/ /usr/local/
RUN chmod a+x /usr/local/test-build/start.sh
CMD ["/usr/local/test-build/start.sh"]
Create a component.dep file under src/componentB/build
to define the dependency of other component.
componentA
Implement build-pre.sh to copy test-build.sh to src/componentB/dependency
.
#!/bin/bash
pushd $(dirname "$0") > /dev/null
testPath="/test-build/"
testDestDir="../dependency/"
if [[ ! -d ${testDestDir} ]]; then
mkdir ${testDestDir}
fi
cp -arf ${testPath} ${testDestDir}
popd > /dev/null
./pai_build.py build -c /path/to/configuration-dir/ -s componentB
./pai_build.py push -c /path/to/configuration-dir/ -i componentB
- Incremental build implementation.