|
1 | | -# Apollo Docker Image Build Process |
| 1 | +# Apollo Docker Image Build Guide |
2 | 2 |
|
3 | | -## Introduction |
| 3 | +## Overview |
4 | 4 |
|
5 | | -As you may already know, Apollo runs inside Docker container. There are |
6 | | -basically two types of Apollo Docker images: CyberRT and Dev. CyberRT images |
7 | | -were for developers who want to play with the CyberRT framework only, while Dev |
8 | | -images were used to build and run the whole Apollo project. |
| 5 | +Apollo runs within Docker containers, with images tailored for development and |
| 6 | +deployment. We currently support `x86_64` and `aarch64` architectures. |
9 | 7 |
|
10 | | -Currently, two CPU architectures are supported: `x86_64` and `aarch64`. |
| 8 | +**Image Types:** |
11 | 9 |
|
12 | | -**Note** |
| 10 | +- **Cyber (Base/Cyber)**: Core CyberRT framework, ideal for CyberRT-focused |
| 11 | + development. |
| 12 | +- **Dev**: Full Apollo project with development toolchain, for building and |
| 13 | + running the entire Apollo stack. |
| 14 | +- **Runtime**: Optimized, minimal image for production deployment. |
13 | 15 |
|
14 | | -> `dev.aarch64` image was still WIP as of today. It is expected to be ready in |
15 | | -> the next few months. |
| 16 | +## Quick Start |
16 | 17 |
|
17 | | -In the section below, I will describe briefly the steps to build these Docker |
18 | | -images. |
| 18 | +Use the `./build_docker.sh` script to build images. |
19 | 19 |
|
20 | | -## Build CyberRT Image |
| 20 | +### 1. Build CyberRT Image |
21 | 21 |
|
22 | | -Type `./build_docker.sh -h` for help message: |
| 22 | +Builds the base development environment including CUDA/CuDNN/TensorRT and the |
| 23 | +CyberRT framework. |
23 | 24 |
|
24 | | -``` |
25 | | -Usage: |
26 | | - build_docker.sh -f <Dockerfile> [Options] |
27 | | -Available options: |
28 | | - -c,--clean Use "--no-cache=true" for docker build |
29 | | - -m,--mode "build" for build everything from source if possible, "download" for using prebuilt ones |
30 | | - -g,--geo Enable geo-specific mirrors to speed up build. Currently "cn" and "us" are supported. |
31 | | - -d,--dist Whether to build stable("stable") or experimental("testing") Docker images |
32 | | - -t,--timestamp Specify Cyber image timestamp to build Dev image from it. Format: yyyymmdd_hhmm (e.g 20210205_1520) |
33 | | - --dry Dry run (for testing purpose) |
34 | | - -h,--help Show this message and exit |
35 | | -E.g., |
36 | | - build_docker.sh -f cyber.x86_64.dockerfile -m build -g cn |
37 | | - build_docker.sh -f dev.aarch64.dockerfile -m download -d testing |
38 | | -``` |
| 25 | +```bash |
| 26 | +cd docker/build |
39 | 27 |
|
40 | | -Here, the `-g/--geo` option is used to enable geo-location based settings (APT & |
41 | | -PYPI mirrors, etc.). Two codes (`us` & `cn`) are supported now, and the default |
42 | | -is `us`. |
| 28 | +# Build x86_64 CyberRT image (default: download pre-built dependencies) |
| 29 | +./build_docker.sh -f cyber.x86_64.dockerfile |
43 | 30 |
|
44 | | -To build the latest CyberRT image, simply run: |
| 31 | +# For users in mainland China (accelerated mirrors) |
| 32 | +./build_docker.sh -f cyber.x86_64.dockerfile -g cn |
45 | 33 |
|
46 | | -``` |
47 | | -./build_docker.sh -f cyber.<TARGET_ARCH>.dockerfile |
| 34 | +# Build all dependencies from source (takes longer) |
| 35 | +./build_docker.sh -f dev.x86_64.cpu.dockerfile -m build |
48 | 36 | ``` |
49 | 37 |
|
50 | | -Users of mainland China can specify `-g cn` to speed up build process: |
| 38 | +### 2. Build Apollo Dev Image |
51 | 39 |
|
52 | | -``` |
53 | | -./build_docker.sh -f cyber.<TARGET_ARCH>.dockerfile -g cn |
54 | | -``` |
55 | | - |
56 | | -## Build Apollo Dev Image |
| 40 | +Builds the full Apollo development image, based on a CyberRT image. |
57 | 41 |
|
58 | | -Run the following command to build Apollo Dev image: |
| 42 | +```bash |
| 43 | +# Build x86_64 Dev image |
| 44 | +./build_docker.sh -f dev.x86_64.dockerfile |
59 | 45 |
|
60 | | -``` |
61 | | -build_docker.sh -f dev.<TARGET_ARCH>.dockerfile |
| 46 | +# Build aarch64 Dev image (ensure qemu-user-static is configured for cross-arch builds) |
| 47 | +./build_docker.sh -f dev.aarch64.dockerfile -m download |
62 | 48 | ``` |
63 | 49 |
|
64 | | -On success, output messages like the following will be shown at the bottom of |
65 | | -your screen. |
| 50 | +### 3. Build Apollo Runtime Image |
66 | 51 |
|
67 | | -``` |
68 | | -Successfully built baca71e567e6 |
69 | | -Successfully tagged apolloauto/apollo:dev-x86_64-18.04-20200824_0339 |
70 | | -Built new image apolloauto/apollo:dev-x86_64-18.04-20200824_0339 |
71 | | -``` |
| 52 | +Used for lightweight production deployments. Requires a prior Apollo Release |
| 53 | +Build. |
72 | 54 |
|
73 | | -## Build Apollo Runtime Docker Image |
74 | | - |
75 | | -Apollo Runtime Docker was used in combination with Release Build output for easy |
76 | | -deployment. You can run the following commands to build Apollo Runtime Docker |
77 | | -image on your own. |
78 | | - |
79 | | -``` |
80 | | -# Generate required APT packages |
| 55 | +```bash |
| 56 | +# 1. Generate required APT packages from Apollo Release Build |
81 | 57 | ./apollo.sh release -c -r |
82 | 58 |
|
| 59 | +# 2. Navigate to the Docker build directory and copy package list |
83 | 60 | cd docker/build |
84 | | -# Copy the generated package list for docker build |
85 | 61 | cp /apollo/output/syspkgs.txt . |
86 | 62 |
|
87 | | -cp runtime.x86_64.dockerfile.sample runtime.x86_64.dockerfile |
| 63 | +# 3. Build the Runtime image (x86_64 only currently) |
| 64 | +# cp runtime.x86_64.dockerfile.sample runtime.x86_64.dockerfile # if file doesn't exist |
88 | 65 | bash build_docker.sh -f runtime.x86_64.dockerfile |
89 | 66 | ``` |
90 | 67 |
|
91 | | -> Note: Apollo Runtime Docker supports x86_64 only as Release Build was not |
92 | | -> ready for Aarch64 yet. |
| 68 | +--- |
93 | 69 |
|
94 | | -## Tips |
| 70 | +## Script Arguments |
95 | 71 |
|
96 | | -### Build Log |
| 72 | +Run `./build_docker.sh --help` for full options: |
97 | 73 |
|
98 | | -The build log for CyberRT and Dev Docker images was located at |
99 | | -`/opt/apollo/build.log`, which contains download links and checksums of |
100 | | -dependent packages during Docker build. |
101 | | - |
102 | | -### Enable Local HTTP Cache to Speed Up Build |
| 74 | +``` |
| 75 | +Usage: |
| 76 | + build_docker.sh -f <Dockerfile> [Options] |
103 | 77 |
|
104 | | -You can enable local HTTP cache to speed up package downloading by performing |
105 | | -the following steps on your **host** running Docker: |
| 78 | +Options: |
| 79 | + -f, --dockerfile Path to the Dockerfile (e.g., 'cyber.x86_64.dockerfile'). |
| 80 | + -c, --clean Disable Docker build cache (--no-cache=true). |
| 81 | + -m, --mode Installation mode: 'download' (default, use pre-built), 'build' (build from source). |
| 82 | + -g, --geo Enable geo-specific mirrors ('cn' or 'us', default 'us'). |
| 83 | + -t, --timestamp Timestamp of the previous stage image (YYYYMMDD_HHMM). |
| 84 | + --dry Dry run (print commands without execution). |
| 85 | + -h, --help Show help message and exit. |
| 86 | +``` |
106 | 87 |
|
107 | | -1. Download all prerequisite packages to a directory (say, `$HOME/archive`) with |
108 | | - URLs listed in the build log. Pay attention to their checksum. |
109 | | -2. Change to that archive directory and start your local HTTP cache server at |
110 | | - port **8388**. |
| 88 | +--- |
111 | 89 |
|
112 | | -``` |
113 | | -cd $HOME/archive |
114 | | -nohup python3 -m http.server 8388 & |
115 | | -``` |
| 90 | +## Advanced Tips |
116 | 91 |
|
117 | | -> Note: Another advantage with the local HTTP cache mechanism is, it has little |
118 | | -> influence on the final image size. Even if the cached package was missing or |
119 | | -> broken, it can still be downloaded from the original URL. |
| 92 | +### Cross-Architecture Builds |
120 | 93 |
|
121 | | -3. Rerun `build_docker.sh`. |
| 94 | +For cross-architecture builds (e.g., building `aarch64` on `x86_64`), ensure |
| 95 | +`qemu-user-static` is configured: |
122 | 96 |
|
123 | | -## Add New Installer |
| 97 | +```bash |
| 98 | +docker run --rm --privileged multiarch/qemu-user-static --reset -p yes |
| 99 | +``` |
124 | 100 |
|
125 | | -The best practice of a new installer would be: |
| 101 | +**Recommendation:** Utilize `docker buildx` for a more robust and efficient |
| 102 | +multi-platform build experience. |
126 | 103 |
|
127 | | -1. Well tested. |
| 104 | +### Optimize Build Speed |
128 | 105 |
|
129 | | - Of course. Make it work, and don't break other installers, such as |
130 | | - incompatible versions of libraries. |
| 106 | +- **Local HTTP Cache:** Setting up a local HTTP server to cache downloaded |
| 107 | + packages can significantly speed up repeated builds without affecting final |
| 108 | + image size. |
131 | 109 |
|
132 | | -1. Standalone. |
| 110 | + **Steps:** |
133 | 111 |
|
134 | | - Have minimum assumption about the basement, which means, you can depend on |
135 | | - the base image and `installers/installer_base.sh`. Other than that, you |
136 | | - should install all the dependencies in your own installer. |
| 112 | + 1. **Download prerequisites:** Identify and download all necessary |
| 113 | + prerequisite packages to a local directory (e.g., `$HOME/apollo_cache`). |
| 114 | + URLs are typically listed in the build log (`/opt/apollo/build.log`). Pay |
| 115 | + attention to checksums for integrity. |
| 116 | + 2. **Start local HTTP server:** Navigate to your cache directory and start a |
| 117 | + simple HTTP server on port **8388**: |
| 118 | + ```bash |
| 119 | + mkdir -p "$HOME/apollo_cache" && cd "$_" |
| 120 | + nohup python3 -m http.server 8388 & |
| 121 | + ``` |
| 122 | + 3. **Rerun build:** Execute `build_docker.sh` as usual. The Docker build |
| 123 | + process will attempt to fetch packages from |
| 124 | + `http://host.docker.internal:8388` (or directly from |
| 125 | + `http://<your_host_ip>:8388` if `host.docker.internal` is not available), |
| 126 | + greatly reducing download times. |
137 | 127 |
|
138 | | -1. Thin. |
| 128 | + - **Benefit:** Even if a cached package is missing or broken, the build |
| 129 | + process will fall back to downloading from the original URL. |
139 | 130 |
|
140 | | - It will generate a new layer in the final image, so please keep it as thin as |
141 | | - possible. For example, clean up all intermediate files: |
| 131 | +- **Avoid `--no-cache` (`-c`):** Only use when strictly necessary, as it forces |
| 132 | + re-downloading and re-building all layers, significantly increasing build |
| 133 | + time. |
142 | 134 |
|
143 | | - ```bash |
144 | | - wget xxx.zip |
145 | | - # Unzip, make, make install |
146 | | - rm -fr xxx.zip xxx |
147 | | - ``` |
| 135 | +### Debugging Builds |
148 | 136 |
|
149 | | -1. Cross-architecture. |
| 137 | +Build logs are located at `/opt/apollo/build.log` inside the container, |
| 138 | +providing detailed information on downloads and installation steps. |
150 | 139 |
|
151 | | - It would be awesome to work perfectly for different architectures such as |
152 | | - `x86_64` and `aarch64`. |
| 140 | +--- |
0 commit comments