| Patrick Williams | 02871c9 | 2021-02-01 20:57:19 -0600 | [diff] [blame] | 1 | #!/usr/bin/env python3 | 
|  | 2 | # | 
|  | 3 | # Build the required docker image to run package unit tests | 
|  | 4 | # | 
|  | 5 | # Script Variables: | 
|  | 6 | #   DOCKER_IMG_NAME:  <optional, the name of the docker image to generate> | 
|  | 7 | #                     default is openbmc/ubuntu-unit-test | 
|  | 8 | #   DISTRO:           <optional, the distro to build a docker image against> | 
| Patrick Williams | 5083743 | 2021-02-06 12:24:05 -0600 | [diff] [blame] | 9 | #   FORCE_DOCKER_BUILD: <optional, a non-zero value with force all Docker | 
|  | 10 | #                     images to be rebuilt rather than reusing caches.> | 
|  | 11 | #   BUILD_URL:        <optional, used to detect running under CI context | 
|  | 12 | #                     (ex. Jenkins)> | 
| Patrick Williams | 02871c9 | 2021-02-01 20:57:19 -0600 | [diff] [blame] | 13 | #   BRANCH:           <optional, branch to build from each of the openbmc/ | 
|  | 14 | #                     repositories> | 
|  | 15 | #                     default is master, which will be used if input branch not | 
|  | 16 | #                     provided or not found | 
|  | 17 | #   UBUNTU_MIRROR:    <optional, the URL of a mirror of Ubuntu to override the | 
|  | 18 | #                     default ones in /etc/apt/sources.list> | 
|  | 19 | #                     default is empty, and no mirror is used. | 
|  | 20 | #   http_proxy        The HTTP address of the proxy server to connect to. | 
|  | 21 | #                     Default: "", proxy is not setup if this is not set | 
|  | 22 |  | 
|  | 23 | import os | 
|  | 24 | import sys | 
| Patrick Williams | b16f3e2 | 2021-02-06 08:16:47 -0600 | [diff] [blame] | 25 | import threading | 
| Patrick Williams | a18d9c5 | 2021-02-05 09:52:26 -0600 | [diff] [blame] | 26 | from datetime import date | 
|  | 27 | from hashlib import sha256 | 
| Patrick Williams | ee3c9ee | 2021-02-12 20:56:01 -0600 | [diff] [blame] | 28 | from sh import docker, git, nproc, uname  # type: ignore | 
|  | 29 | from typing import Any, Callable, Dict, Iterable, Optional | 
| Patrick Williams | 02871c9 | 2021-02-01 20:57:19 -0600 | [diff] [blame] | 30 |  | 
| Patrick Williams | ee3c9ee | 2021-02-12 20:56:01 -0600 | [diff] [blame] | 31 | try: | 
|  | 32 | # Python before 3.8 doesn't have TypedDict, so reroute to standard 'dict'. | 
|  | 33 | from typing import TypedDict | 
|  | 34 | except: | 
|  | 35 |  | 
|  | 36 | class TypedDict(dict):  # type: ignore | 
|  | 37 | # We need to do this to eat the 'total' argument. | 
|  | 38 | def __init_subclass__(cls, **kwargs): | 
|  | 39 | super().__init_subclass__() | 
|  | 40 |  | 
|  | 41 |  | 
|  | 42 | # Declare some variables used in package definitions. | 
| Patrick Williams | aae36d1 | 2021-02-04 16:30:04 -0600 | [diff] [blame] | 43 | prefix = "/usr/local" | 
| Patrick Williams | 02871c9 | 2021-02-01 20:57:19 -0600 | [diff] [blame] | 44 | proc_count = nproc().strip() | 
| Patrick Williams | 02871c9 | 2021-02-01 20:57:19 -0600 | [diff] [blame] | 45 |  | 
| Patrick Williams | ee3c9ee | 2021-02-12 20:56:01 -0600 | [diff] [blame] | 46 |  | 
|  | 47 | class PackageDef(TypedDict, total=False): | 
|  | 48 | """ Package Definition for packages dictionary. """ | 
|  | 49 |  | 
|  | 50 | # rev [optional]: Revision of package to use. | 
|  | 51 | rev: str | 
|  | 52 | # url [optional]: lambda function to create URL: (package, rev) -> url. | 
|  | 53 | url: Callable[[str, str], str] | 
|  | 54 | # depends [optional]: List of package dependencies. | 
|  | 55 | depends: Iterable[str] | 
|  | 56 | # build_type [required]: Build type used for package. | 
|  | 57 | #   Currently supported: autoconf, cmake, custom, make, meson | 
|  | 58 | build_type: str | 
|  | 59 | # build_steps [optional]: Steps to run for 'custom' build_type. | 
|  | 60 | build_steps: Iterable[str] | 
|  | 61 | # config_flags [optional]: List of options to pass configuration tool. | 
|  | 62 | config_flags: Iterable[str] | 
|  | 63 | # config_env [optional]: List of environment variables to set for config. | 
|  | 64 | config_env: Iterable[str] | 
|  | 65 | # custom_post_dl [optional]: List of steps to run after download, but | 
|  | 66 | #   before config / build / install. | 
|  | 67 | custom_post_dl: Iterable[str] | 
| Patrick Williams | 6bce2ca | 2021-02-12 21:13:37 -0600 | [diff] [blame] | 68 | # custom_post_install [optional]: List of steps to run after install. | 
|  | 69 | custom_post_install: Iterable[str] | 
| Patrick Williams | ee3c9ee | 2021-02-12 20:56:01 -0600 | [diff] [blame] | 70 |  | 
|  | 71 | # __tag [private]: Generated Docker tag name for package stage. | 
|  | 72 | __tag: str | 
|  | 73 | # __package [private]: Package object associated with this package. | 
|  | 74 | __package: Any  # Type is Package, but not defined yet. | 
|  | 75 |  | 
| Patrick Williams | 02871c9 | 2021-02-01 20:57:19 -0600 | [diff] [blame] | 76 |  | 
| Patrick Williams | 7204324 | 2021-02-02 10:31:45 -0600 | [diff] [blame] | 77 | # Packages to include in image. | 
|  | 78 | packages = { | 
| Patrick Williams | ee3c9ee | 2021-02-12 20:56:01 -0600 | [diff] [blame] | 79 | "boost": PackageDef( | 
| Ed Tanous | ef7bca4 | 2022-02-04 09:13:20 -0800 | [diff] [blame] | 80 | rev="1.78.0", | 
| Patrick Williams | ee3c9ee | 2021-02-12 20:56:01 -0600 | [diff] [blame] | 81 | url=( | 
| Patrick Williams | 5f2549e | 2021-04-12 12:05:10 -0500 | [diff] [blame] | 82 | lambda pkg, rev: f"https://downloads.yoctoproject.org/mirror/sources/{pkg}_{rev.replace('.', '_')}.tar.bz2" | 
| Patrick Williams | 2abc4a4 | 2021-02-03 06:11:40 -0600 | [diff] [blame] | 83 | ), | 
| Patrick Williams | ee3c9ee | 2021-02-12 20:56:01 -0600 | [diff] [blame] | 84 | build_type="custom", | 
|  | 85 | build_steps=[ | 
| Patrick Williams | aae36d1 | 2021-02-04 16:30:04 -0600 | [diff] [blame] | 86 | f"./bootstrap.sh --prefix={prefix} --with-libraries=context,coroutine", | 
|  | 87 | "./b2", | 
|  | 88 | f"./b2 install --prefix={prefix}", | 
|  | 89 | ], | 
| Patrick Williams | ee3c9ee | 2021-02-12 20:56:01 -0600 | [diff] [blame] | 90 | ), | 
|  | 91 | "USCiLab/cereal": PackageDef( | 
| Patrick Williams | 3f8b529 | 2021-04-30 10:30:05 -0500 | [diff] [blame] | 92 | rev="3e4d1b84cab4891368d2179a61a7ba06a5693e7f", | 
| Patrick Williams | ee3c9ee | 2021-02-12 20:56:01 -0600 | [diff] [blame] | 93 | build_type="custom", | 
|  | 94 | build_steps=[f"cp -a include/cereal/ {prefix}/include/"], | 
|  | 95 | ), | 
|  | 96 | "catchorg/Catch2": PackageDef( | 
| William A. Kennington III | 96b4345 | 2021-05-15 03:35:12 -0700 | [diff] [blame] | 97 | rev="v2.13.6", | 
| Patrick Williams | ee3c9ee | 2021-02-12 20:56:01 -0600 | [diff] [blame] | 98 | build_type="cmake", | 
|  | 99 | config_flags=["-DBUILD_TESTING=OFF", "-DCATCH_INSTALL_DOCS=OFF"], | 
|  | 100 | ), | 
|  | 101 | "CLIUtils/CLI11": PackageDef( | 
|  | 102 | rev="v1.9.1", | 
|  | 103 | build_type="cmake", | 
|  | 104 | config_flags=[ | 
| Patrick Williams | aae36d1 | 2021-02-04 16:30:04 -0600 | [diff] [blame] | 105 | "-DBUILD_TESTING=OFF", | 
|  | 106 | "-DCLI11_BUILD_DOCS=OFF", | 
|  | 107 | "-DCLI11_BUILD_EXAMPLES=OFF", | 
|  | 108 | ], | 
| Patrick Williams | ee3c9ee | 2021-02-12 20:56:01 -0600 | [diff] [blame] | 109 | ), | 
|  | 110 | "fmtlib/fmt": PackageDef( | 
| Willy Tu | 6307501 | 2022-02-08 11:20:25 -0800 | [diff] [blame] | 111 | rev="8.1.1", | 
| Patrick Williams | ee3c9ee | 2021-02-12 20:56:01 -0600 | [diff] [blame] | 112 | build_type="cmake", | 
|  | 113 | config_flags=[ | 
| Patrick Williams | aae36d1 | 2021-02-04 16:30:04 -0600 | [diff] [blame] | 114 | "-DFMT_DOC=OFF", | 
|  | 115 | "-DFMT_TEST=OFF", | 
|  | 116 | ], | 
| Patrick Williams | ee3c9ee | 2021-02-12 20:56:01 -0600 | [diff] [blame] | 117 | ), | 
| Patrick Williams | ee3c9ee | 2021-02-12 20:56:01 -0600 | [diff] [blame] | 118 | "Naios/function2": PackageDef( | 
| William A. Kennington III | 96b4345 | 2021-05-15 03:35:12 -0700 | [diff] [blame] | 119 | rev="4.1.0", | 
| Patrick Williams | ee3c9ee | 2021-02-12 20:56:01 -0600 | [diff] [blame] | 120 | build_type="custom", | 
|  | 121 | build_steps=[ | 
| Patrick Williams | aae36d1 | 2021-02-04 16:30:04 -0600 | [diff] [blame] | 122 | f"mkdir {prefix}/include/function2", | 
|  | 123 | f"cp include/function2/function2.hpp {prefix}/include/function2/", | 
|  | 124 | ], | 
| Patrick Williams | ee3c9ee | 2021-02-12 20:56:01 -0600 | [diff] [blame] | 125 | ), | 
| Michael Shen | 5202d8e | 2022-03-02 21:50:09 +0800 | [diff] [blame] | 126 | # Release 2021-06-12 | 
| Patrick Williams | ee3c9ee | 2021-02-12 20:56:01 -0600 | [diff] [blame] | 127 | "google/googletest": PackageDef( | 
| Willy Tu | acfdee5 | 2022-04-07 11:35:51 -0700 | [diff] [blame] | 128 | rev="9e712372214d75bb30ec2847a44bf124d48096f3", | 
| Patrick Williams | ee3c9ee | 2021-02-12 20:56:01 -0600 | [diff] [blame] | 129 | build_type="cmake", | 
| William A. Kennington III | 4dd32c0 | 2021-05-28 01:58:13 -0700 | [diff] [blame] | 130 | config_env=["CXXFLAGS=-std=c++20"], | 
| Patrick Williams | ee3c9ee | 2021-02-12 20:56:01 -0600 | [diff] [blame] | 131 | config_flags=["-DTHREADS_PREFER_PTHREAD_FLAG=ON"], | 
|  | 132 | ), | 
| Patrick Williams | 02871c9 | 2021-02-01 20:57:19 -0600 | [diff] [blame] | 133 | # Release 2020-08-06 | 
| Patrick Williams | ee3c9ee | 2021-02-12 20:56:01 -0600 | [diff] [blame] | 134 | "nlohmann/json": PackageDef( | 
| Ed Tanous | 7d1b2a1 | 2021-11-03 09:13:57 -0700 | [diff] [blame] | 135 | rev="v3.10.4", | 
| Patrick Williams | 6bce2ca | 2021-02-12 21:13:37 -0600 | [diff] [blame] | 136 | build_type="cmake", | 
|  | 137 | config_flags=["-DJSON_BuildTests=OFF"], | 
|  | 138 | custom_post_install=[ | 
| Patrick Williams | aae36d1 | 2021-02-04 16:30:04 -0600 | [diff] [blame] | 139 | f"ln -s {prefix}/include/nlohmann/json.hpp {prefix}/include/json.hpp", | 
|  | 140 | ], | 
| Patrick Williams | ee3c9ee | 2021-02-12 20:56:01 -0600 | [diff] [blame] | 141 | ), | 
| Patrick Williams | 02871c9 | 2021-02-01 20:57:19 -0600 | [diff] [blame] | 142 | # Snapshot from 2019-05-24 | 
| Patrick Williams | ee3c9ee | 2021-02-12 20:56:01 -0600 | [diff] [blame] | 143 | "linux-test-project/lcov": PackageDef( | 
|  | 144 | rev="v1.15", | 
|  | 145 | build_type="make", | 
|  | 146 | ), | 
| Patrick Williams | 0eedeed | 2021-02-06 19:06:09 -0600 | [diff] [blame] | 147 | # dev-5.8 2021-01-11 | 
| Patrick Williams | ee3c9ee | 2021-02-12 20:56:01 -0600 | [diff] [blame] | 148 | "openbmc/linux": PackageDef( | 
|  | 149 | rev="3cc95ae40716e56f81b69615781f54c78079042d", | 
|  | 150 | build_type="custom", | 
|  | 151 | build_steps=[ | 
| Patrick Williams | aae36d1 | 2021-02-04 16:30:04 -0600 | [diff] [blame] | 152 | f"make -j{proc_count} defconfig", | 
|  | 153 | f"make INSTALL_HDR_PATH={prefix} headers_install", | 
|  | 154 | ], | 
| Patrick Williams | ee3c9ee | 2021-02-12 20:56:01 -0600 | [diff] [blame] | 155 | ), | 
| Patrick Williams | 0eedeed | 2021-02-06 19:06:09 -0600 | [diff] [blame] | 156 | # Snapshot from 2020-06-13 | 
| Patrick Williams | ee3c9ee | 2021-02-12 20:56:01 -0600 | [diff] [blame] | 157 | "LibVNC/libvncserver": PackageDef( | 
|  | 158 | rev="LibVNCServer-0.9.13", | 
|  | 159 | build_type="cmake", | 
|  | 160 | ), | 
| Patrick Williams | 0eedeed | 2021-02-06 19:06:09 -0600 | [diff] [blame] | 161 | # version from meta-openembedded/meta-oe/recipes-support/libtinyxml2/libtinyxml2_8.0.0.bb | 
| Patrick Williams | ee3c9ee | 2021-02-12 20:56:01 -0600 | [diff] [blame] | 162 | "leethomason/tinyxml2": PackageDef( | 
|  | 163 | rev="8.0.0", | 
|  | 164 | build_type="cmake", | 
|  | 165 | ), | 
| Patrick Williams | 02871c9 | 2021-02-01 20:57:19 -0600 | [diff] [blame] | 166 | # version from /meta-openembedded/meta-oe/recipes-devtools/boost-url/boost-url_git.bb | 
| Patrick Williams | ee3c9ee | 2021-02-12 20:56:01 -0600 | [diff] [blame] | 167 | "CPPAlliance/url": PackageDef( | 
| Ed Tanous | ab640cd | 2022-02-03 16:33:27 -0800 | [diff] [blame] | 168 | rev="d740a92d38e3a8f4d5b2153f53b82f1c98e312ab", | 
| Ed Tanous | eed466e | 2021-09-20 10:04:55 -0700 | [diff] [blame] | 169 | build_type="custom", | 
|  | 170 | build_steps=[f"cp -a include/** {prefix}/include/"], | 
| Patrick Williams | ee3c9ee | 2021-02-12 20:56:01 -0600 | [diff] [blame] | 171 | ), | 
| Patrick Williams | 6899289 | 2021-10-06 16:25:12 -0500 | [diff] [blame] | 172 | # version from meta-openembedded/meta-oe/dynamic-layers/networking-layer/recipes-devools/valijson/valijson_0.6.bb | 
| Patrick Williams | ee3c9ee | 2021-02-12 20:56:01 -0600 | [diff] [blame] | 173 | "tristanpenman/valijson": PackageDef( | 
| Patrick Williams | 6899289 | 2021-10-06 16:25:12 -0500 | [diff] [blame] | 174 | rev="v0.6", | 
| Patrick Williams | ee3c9ee | 2021-02-12 20:56:01 -0600 | [diff] [blame] | 175 | build_type="cmake", | 
|  | 176 | config_flags=[ | 
| Patrick Williams | 0eedeed | 2021-02-06 19:06:09 -0600 | [diff] [blame] | 177 | "-Dvalijson_BUILD_TESTS=0", | 
|  | 178 | "-Dvalijson_INSTALL_HEADERS=1", | 
| Patrick Williams | aae36d1 | 2021-02-04 16:30:04 -0600 | [diff] [blame] | 179 | ], | 
| Patrick Williams | ee3c9ee | 2021-02-12 20:56:01 -0600 | [diff] [blame] | 180 | ), | 
| Patrick Williams | 5122416 | 2021-12-08 11:09:24 -0600 | [diff] [blame] | 181 | # version from meta-openembedded/meta-oe/recipes-devtools/unifex/unifex_git.bb | 
|  | 182 | "facebookexperimental/libunifex": PackageDef( | 
|  | 183 | rev="9df21c58d34ce8a1cd3b15c3a7347495e29417a0", | 
|  | 184 | build_type="cmake", | 
|  | 185 | config_flags=[ | 
|  | 186 | "-DBUILD_SHARED_LIBS=ON", | 
|  | 187 | "-DBUILD_TESTING=OFF", | 
|  | 188 | "-DCMAKE_CXX_STANDARD=20", | 
|  | 189 | "-DUNIFEX_BUILD_EXAMPLES=OFF", | 
|  | 190 | ], | 
|  | 191 | ), | 
| Patrick Williams | ee3c9ee | 2021-02-12 20:56:01 -0600 | [diff] [blame] | 192 | "open-power/pdbg": PackageDef(build_type="autoconf"), | 
|  | 193 | "openbmc/gpioplus": PackageDef( | 
|  | 194 | depends=["openbmc/stdplus"], | 
|  | 195 | build_type="meson", | 
|  | 196 | config_flags=[ | 
| Patrick Williams | aae36d1 | 2021-02-04 16:30:04 -0600 | [diff] [blame] | 197 | "-Dexamples=false", | 
|  | 198 | "-Dtests=disabled", | 
|  | 199 | ], | 
| Patrick Williams | ee3c9ee | 2021-02-12 20:56:01 -0600 | [diff] [blame] | 200 | ), | 
|  | 201 | "openbmc/phosphor-dbus-interfaces": PackageDef( | 
|  | 202 | depends=["openbmc/sdbusplus"], | 
|  | 203 | build_type="meson", | 
| Patrick Williams | ee3c9ee | 2021-02-12 20:56:01 -0600 | [diff] [blame] | 204 | ), | 
|  | 205 | "openbmc/phosphor-logging": PackageDef( | 
|  | 206 | depends=[ | 
| Patrick Williams | 8339461 | 2021-02-03 07:12:50 -0600 | [diff] [blame] | 207 | "USCiLab/cereal", | 
| Patrick Williams | 8339461 | 2021-02-03 07:12:50 -0600 | [diff] [blame] | 208 | "openbmc/phosphor-dbus-interfaces", | 
|  | 209 | "openbmc/sdbusplus", | 
|  | 210 | "openbmc/sdeventplus", | 
| Patrick Williams | aae36d1 | 2021-02-04 16:30:04 -0600 | [diff] [blame] | 211 | ], | 
| Patrick Williams | f79ce4c | 2021-04-30 16:00:49 -0500 | [diff] [blame] | 212 | build_type="meson", | 
| Patrick Williams | ee3c9ee | 2021-02-12 20:56:01 -0600 | [diff] [blame] | 213 | config_flags=[ | 
| Patrick Williams | 5eabdae | 2022-04-14 14:34:34 -0500 | [diff] [blame] | 214 | f"-Dyamldir={prefix}/share/phosphor-dbus-yaml/yaml", | 
| Patrick Williams | aae36d1 | 2021-02-04 16:30:04 -0600 | [diff] [blame] | 215 | ], | 
| Patrick Williams | ee3c9ee | 2021-02-12 20:56:01 -0600 | [diff] [blame] | 216 | ), | 
|  | 217 | "openbmc/phosphor-objmgr": PackageDef( | 
|  | 218 | depends=[ | 
| Patrick Williams | 8339461 | 2021-02-03 07:12:50 -0600 | [diff] [blame] | 219 | "boost", | 
|  | 220 | "leethomason/tinyxml2", | 
|  | 221 | "openbmc/phosphor-logging", | 
|  | 222 | "openbmc/sdbusplus", | 
| Patrick Williams | aae36d1 | 2021-02-04 16:30:04 -0600 | [diff] [blame] | 223 | ], | 
| Brad Bishop | 1197e35 | 2021-08-03 19:25:46 -0400 | [diff] [blame] | 224 | build_type="meson", | 
|  | 225 | config_flags=[ | 
|  | 226 | "-Dtests=disabled", | 
|  | 227 | ], | 
| Patrick Williams | ee3c9ee | 2021-02-12 20:56:01 -0600 | [diff] [blame] | 228 | ), | 
|  | 229 | "openbmc/pldm": PackageDef( | 
|  | 230 | depends=[ | 
| Patrick Williams | 8339461 | 2021-02-03 07:12:50 -0600 | [diff] [blame] | 231 | "CLIUtils/CLI11", | 
|  | 232 | "boost", | 
|  | 233 | "nlohmann/json", | 
|  | 234 | "openbmc/phosphor-dbus-interfaces", | 
|  | 235 | "openbmc/phosphor-logging", | 
|  | 236 | "openbmc/sdbusplus", | 
|  | 237 | "openbmc/sdeventplus", | 
| Patrick Williams | aae36d1 | 2021-02-04 16:30:04 -0600 | [diff] [blame] | 238 | ], | 
| Patrick Williams | ee3c9ee | 2021-02-12 20:56:01 -0600 | [diff] [blame] | 239 | build_type="meson", | 
|  | 240 | config_flags=[ | 
| Patrick Williams | aae36d1 | 2021-02-04 16:30:04 -0600 | [diff] [blame] | 241 | "-Dlibpldm-only=enabled", | 
|  | 242 | "-Doem-ibm=enabled", | 
|  | 243 | "-Dtests=disabled", | 
|  | 244 | ], | 
| Patrick Williams | ee3c9ee | 2021-02-12 20:56:01 -0600 | [diff] [blame] | 245 | ), | 
|  | 246 | "openbmc/sdbusplus": PackageDef( | 
| Patrick Williams | 5122416 | 2021-12-08 11:09:24 -0600 | [diff] [blame] | 247 | depends=[ | 
|  | 248 | "facebookexperimental/libunifex", | 
|  | 249 | ], | 
| Patrick Williams | ee3c9ee | 2021-02-12 20:56:01 -0600 | [diff] [blame] | 250 | build_type="meson", | 
|  | 251 | custom_post_dl=[ | 
| Patrick Williams | aae36d1 | 2021-02-04 16:30:04 -0600 | [diff] [blame] | 252 | "cd tools", | 
|  | 253 | f"./setup.py install --root=/ --prefix={prefix}", | 
|  | 254 | "cd ..", | 
|  | 255 | ], | 
| Patrick Williams | ee3c9ee | 2021-02-12 20:56:01 -0600 | [diff] [blame] | 256 | config_flags=[ | 
| Patrick Williams | aae36d1 | 2021-02-04 16:30:04 -0600 | [diff] [blame] | 257 | "-Dexamples=disabled", | 
|  | 258 | "-Dtests=disabled", | 
|  | 259 | ], | 
| Patrick Williams | ee3c9ee | 2021-02-12 20:56:01 -0600 | [diff] [blame] | 260 | ), | 
|  | 261 | "openbmc/sdeventplus": PackageDef( | 
|  | 262 | depends=["Naios/function2", "openbmc/stdplus"], | 
|  | 263 | build_type="meson", | 
|  | 264 | config_flags=[ | 
| Patrick Williams | aae36d1 | 2021-02-04 16:30:04 -0600 | [diff] [blame] | 265 | "-Dexamples=false", | 
|  | 266 | "-Dtests=disabled", | 
|  | 267 | ], | 
| Patrick Williams | ee3c9ee | 2021-02-12 20:56:01 -0600 | [diff] [blame] | 268 | ), | 
|  | 269 | "openbmc/stdplus": PackageDef( | 
| Patrick Williams | b58bf15 | 2022-04-29 16:01:07 -0500 | [diff] [blame] | 270 | depends=["fmtlib/fmt"], | 
| Patrick Williams | ee3c9ee | 2021-02-12 20:56:01 -0600 | [diff] [blame] | 271 | build_type="meson", | 
|  | 272 | config_flags=[ | 
| Patrick Williams | aae36d1 | 2021-02-04 16:30:04 -0600 | [diff] [blame] | 273 | "-Dexamples=false", | 
|  | 274 | "-Dtests=disabled", | 
|  | 275 | ], | 
| Patrick Williams | ee3c9ee | 2021-02-12 20:56:01 -0600 | [diff] [blame] | 276 | ), | 
|  | 277 | }  # type: Dict[str, PackageDef] | 
| Patrick Williams | 02871c9 | 2021-02-01 20:57:19 -0600 | [diff] [blame] | 278 |  | 
|  | 279 | # Define common flags used for builds | 
| Patrick Williams | 02871c9 | 2021-02-01 20:57:19 -0600 | [diff] [blame] | 280 | configure_flags = " ".join( | 
|  | 281 | [ | 
|  | 282 | f"--prefix={prefix}", | 
|  | 283 | ] | 
|  | 284 | ) | 
|  | 285 | cmake_flags = " ".join( | 
|  | 286 | [ | 
| Patrick Williams | 02871c9 | 2021-02-01 20:57:19 -0600 | [diff] [blame] | 287 | "-DBUILD_SHARED_LIBS=ON", | 
| Patrick Williams | 0f2086b | 2021-02-05 06:49:49 -0600 | [diff] [blame] | 288 | "-DCMAKE_BUILD_TYPE=RelWithDebInfo", | 
| Patrick Williams | 02871c9 | 2021-02-01 20:57:19 -0600 | [diff] [blame] | 289 | f"-DCMAKE_INSTALL_PREFIX:PATH={prefix}", | 
| Patrick Williams | 0f2086b | 2021-02-05 06:49:49 -0600 | [diff] [blame] | 290 | "-GNinja", | 
|  | 291 | "-DCMAKE_MAKE_PROGRAM=ninja", | 
| Patrick Williams | 02871c9 | 2021-02-01 20:57:19 -0600 | [diff] [blame] | 292 | ] | 
|  | 293 | ) | 
|  | 294 | meson_flags = " ".join( | 
|  | 295 | [ | 
|  | 296 | "--wrap-mode=nodownload", | 
|  | 297 | f"-Dprefix={prefix}", | 
|  | 298 | ] | 
|  | 299 | ) | 
|  | 300 |  | 
| Patrick Williams | ee3c9ee | 2021-02-12 20:56:01 -0600 | [diff] [blame] | 301 |  | 
|  | 302 | class Package(threading.Thread): | 
|  | 303 | """Class used to build the Docker stages for each package. | 
|  | 304 |  | 
|  | 305 | Generally, this class should not be instantiated directly but through | 
|  | 306 | Package.generate_all(). | 
|  | 307 | """ | 
|  | 308 |  | 
|  | 309 | # Copy the packages dictionary. | 
|  | 310 | packages = packages.copy() | 
|  | 311 |  | 
|  | 312 | # Lock used for thread-safety. | 
|  | 313 | lock = threading.Lock() | 
|  | 314 |  | 
|  | 315 | def __init__(self, pkg: str): | 
|  | 316 | """ pkg - The name of this package (ex. foo/bar ) """ | 
|  | 317 | super(Package, self).__init__() | 
|  | 318 |  | 
|  | 319 | self.package = pkg | 
|  | 320 | self.exception = None  # type: Optional[Exception] | 
|  | 321 |  | 
|  | 322 | # Reference to this package's | 
|  | 323 | self.pkg_def = Package.packages[pkg] | 
|  | 324 | self.pkg_def["__package"] = self | 
|  | 325 |  | 
|  | 326 | def run(self) -> None: | 
|  | 327 | """ Thread 'run' function.  Builds the Docker stage. """ | 
|  | 328 |  | 
|  | 329 | # In case this package has no rev, fetch it from Github. | 
|  | 330 | self._update_rev() | 
|  | 331 |  | 
|  | 332 | # Find all the Package objects that this package depends on. | 
|  | 333 | #   This section is locked because we are looking into another | 
|  | 334 | #   package's PackageDef dict, which could be being modified. | 
|  | 335 | Package.lock.acquire() | 
|  | 336 | deps: Iterable[Package] = [ | 
|  | 337 | Package.packages[deppkg]["__package"] | 
|  | 338 | for deppkg in self.pkg_def.get("depends", []) | 
|  | 339 | ] | 
|  | 340 | Package.lock.release() | 
|  | 341 |  | 
|  | 342 | # Wait until all the depends finish building.  We need them complete | 
|  | 343 | # for the "COPY" commands. | 
|  | 344 | for deppkg in deps: | 
|  | 345 | deppkg.join() | 
|  | 346 |  | 
|  | 347 | # Generate this package's Dockerfile. | 
|  | 348 | dockerfile = f""" | 
|  | 349 | FROM {docker_base_img_name} | 
|  | 350 | {self._df_copycmds()} | 
|  | 351 | {self._df_build()} | 
|  | 352 | """ | 
|  | 353 |  | 
|  | 354 | # Generate the resulting tag name and save it to the PackageDef. | 
|  | 355 | #   This section is locked because we are modifying the PackageDef, | 
|  | 356 | #   which can be accessed by other threads. | 
|  | 357 | Package.lock.acquire() | 
|  | 358 | tag = Docker.tagname(self._stagename(), dockerfile) | 
|  | 359 | self.pkg_def["__tag"] = tag | 
|  | 360 | Package.lock.release() | 
|  | 361 |  | 
|  | 362 | # Do the build / save any exceptions. | 
|  | 363 | try: | 
|  | 364 | Docker.build(self.package, tag, dockerfile) | 
|  | 365 | except Exception as e: | 
|  | 366 | self.exception = e | 
|  | 367 |  | 
|  | 368 | @classmethod | 
|  | 369 | def generate_all(cls) -> None: | 
|  | 370 | """Ensure a Docker stage is created for all defined packages. | 
|  | 371 |  | 
|  | 372 | These are done in parallel but with appropriate blocking per | 
|  | 373 | package 'depends' specifications. | 
|  | 374 | """ | 
|  | 375 |  | 
|  | 376 | # Create a Package for each defined package. | 
|  | 377 | pkg_threads = [Package(p) for p in cls.packages.keys()] | 
|  | 378 |  | 
|  | 379 | # Start building them all. | 
| Patrick Williams | 6dbd780 | 2021-02-20 08:34:10 -0600 | [diff] [blame] | 380 | #   This section is locked because threads depend on each other, | 
|  | 381 | #   based on the packages, and they cannot 'join' on a thread | 
|  | 382 | #   which is not yet started.  Adding a lock here allows all the | 
|  | 383 | #   threads to start before they 'join' their dependencies. | 
|  | 384 | Package.lock.acquire() | 
| Patrick Williams | ee3c9ee | 2021-02-12 20:56:01 -0600 | [diff] [blame] | 385 | for t in pkg_threads: | 
|  | 386 | t.start() | 
| Patrick Williams | 6dbd780 | 2021-02-20 08:34:10 -0600 | [diff] [blame] | 387 | Package.lock.release() | 
| Patrick Williams | ee3c9ee | 2021-02-12 20:56:01 -0600 | [diff] [blame] | 388 |  | 
|  | 389 | # Wait for completion. | 
|  | 390 | for t in pkg_threads: | 
|  | 391 | t.join() | 
|  | 392 | # Check if the thread saved off its own exception. | 
|  | 393 | if t.exception: | 
|  | 394 | print(f"Package {t.package} failed!", file=sys.stderr) | 
|  | 395 | raise t.exception | 
|  | 396 |  | 
|  | 397 | @staticmethod | 
|  | 398 | def df_all_copycmds() -> str: | 
|  | 399 | """Formulate the Dockerfile snippet necessary to copy all packages | 
|  | 400 | into the final image. | 
|  | 401 | """ | 
|  | 402 | return Package.df_copycmds_set(Package.packages.keys()) | 
|  | 403 |  | 
|  | 404 | @classmethod | 
|  | 405 | def depcache(cls) -> str: | 
|  | 406 | """Create the contents of the '/tmp/depcache'. | 
|  | 407 | This file is a comma-separated list of "<pkg>:<rev>". | 
|  | 408 | """ | 
|  | 409 |  | 
|  | 410 | # This needs to be sorted for consistency. | 
|  | 411 | depcache = "" | 
|  | 412 | for pkg in sorted(cls.packages.keys()): | 
|  | 413 | depcache += "%s:%s," % (pkg, cls.packages[pkg]["rev"]) | 
|  | 414 | return depcache | 
|  | 415 |  | 
|  | 416 | def _update_rev(self) -> None: | 
|  | 417 | """ Look up the HEAD for missing a static rev. """ | 
|  | 418 |  | 
|  | 419 | if "rev" in self.pkg_def: | 
|  | 420 | return | 
|  | 421 |  | 
| Patrick Williams | 65b21fb | 2021-02-12 21:21:14 -0600 | [diff] [blame] | 422 | # Check if Jenkins/Gerrit gave us a revision and use it. | 
|  | 423 | if gerrit_project == self.package and gerrit_rev: | 
|  | 424 | print( | 
|  | 425 | f"Found Gerrit revision for {self.package}: {gerrit_rev}", | 
|  | 426 | file=sys.stderr, | 
|  | 427 | ) | 
|  | 428 | self.pkg_def["rev"] = gerrit_rev | 
|  | 429 | return | 
|  | 430 |  | 
| Patrick Williams | ee3c9ee | 2021-02-12 20:56:01 -0600 | [diff] [blame] | 431 | # Ask Github for all the branches. | 
|  | 432 | lookup = git("ls-remote", "--heads", f"https://github.com/{self.package}") | 
|  | 433 |  | 
|  | 434 | # Find the branch matching {branch} (or fallback to master). | 
|  | 435 | #   This section is locked because we are modifying the PackageDef. | 
|  | 436 | Package.lock.acquire() | 
|  | 437 | for line in lookup.split("\n"): | 
|  | 438 | if f"refs/heads/{branch}" in line: | 
|  | 439 | self.pkg_def["rev"] = line.split()[0] | 
|  | 440 | elif f"refs/heads/master" in line and "rev" not in self.pkg_def: | 
|  | 441 | self.pkg_def["rev"] = line.split()[0] | 
|  | 442 | Package.lock.release() | 
|  | 443 |  | 
|  | 444 | def _stagename(self) -> str: | 
|  | 445 | """ Create a name for the Docker stage associated with this pkg. """ | 
|  | 446 | return self.package.replace("/", "-").lower() | 
|  | 447 |  | 
|  | 448 | def _url(self) -> str: | 
|  | 449 | """ Get the URL for this package. """ | 
|  | 450 | rev = self.pkg_def["rev"] | 
|  | 451 |  | 
|  | 452 | # If the lambda exists, call it. | 
|  | 453 | if "url" in self.pkg_def: | 
|  | 454 | return self.pkg_def["url"](self.package, rev) | 
|  | 455 |  | 
|  | 456 | # Default to the github archive URL. | 
|  | 457 | return f"https://github.com/{self.package}/archive/{rev}.tar.gz" | 
|  | 458 |  | 
|  | 459 | def _cmd_download(self) -> str: | 
|  | 460 | """Formulate the command necessary to download and unpack to source.""" | 
|  | 461 |  | 
|  | 462 | url = self._url() | 
|  | 463 | if ".tar." not in url: | 
|  | 464 | raise NotImplementedError( | 
|  | 465 | f"Unhandled download type for {self.package}: {url}" | 
|  | 466 | ) | 
|  | 467 |  | 
|  | 468 | cmd = f"curl -L {url} | tar -x" | 
|  | 469 |  | 
|  | 470 | if url.endswith(".bz2"): | 
|  | 471 | cmd += "j" | 
|  | 472 | elif url.endswith(".gz"): | 
|  | 473 | cmd += "z" | 
|  | 474 | else: | 
|  | 475 | raise NotImplementedError( | 
|  | 476 | f"Unknown tar flags needed for {self.package}: {url}" | 
|  | 477 | ) | 
|  | 478 |  | 
|  | 479 | return cmd | 
|  | 480 |  | 
|  | 481 | def _cmd_cd_srcdir(self) -> str: | 
|  | 482 | """ Formulate the command necessary to 'cd' into the source dir. """ | 
|  | 483 | return f"cd {self.package.split('/')[-1]}*" | 
|  | 484 |  | 
|  | 485 | def _df_copycmds(self) -> str: | 
|  | 486 | """ Formulate the dockerfile snippet necessary to COPY all depends. """ | 
|  | 487 |  | 
|  | 488 | if "depends" not in self.pkg_def: | 
|  | 489 | return "" | 
|  | 490 | return Package.df_copycmds_set(self.pkg_def["depends"]) | 
|  | 491 |  | 
|  | 492 | @staticmethod | 
|  | 493 | def df_copycmds_set(pkgs: Iterable[str]) -> str: | 
|  | 494 | """Formulate the Dockerfile snippet necessary to COPY a set of | 
|  | 495 | packages into a Docker stage. | 
|  | 496 | """ | 
|  | 497 |  | 
|  | 498 | copy_cmds = "" | 
|  | 499 |  | 
|  | 500 | # Sort the packages for consistency. | 
|  | 501 | for p in sorted(pkgs): | 
|  | 502 | tag = Package.packages[p]["__tag"] | 
|  | 503 | copy_cmds += f"COPY --from={tag} {prefix} {prefix}\n" | 
|  | 504 | # Workaround for upstream docker bug and multiple COPY cmds | 
|  | 505 | # https://github.com/moby/moby/issues/37965 | 
|  | 506 | copy_cmds += "RUN true\n" | 
|  | 507 |  | 
|  | 508 | return copy_cmds | 
|  | 509 |  | 
|  | 510 | def _df_build(self) -> str: | 
|  | 511 | """Formulate the Dockerfile snippet necessary to download, build, and | 
|  | 512 | install a package into a Docker stage. | 
|  | 513 | """ | 
|  | 514 |  | 
|  | 515 | # Download and extract source. | 
|  | 516 | result = f"RUN {self._cmd_download()} && {self._cmd_cd_srcdir()} && " | 
|  | 517 |  | 
|  | 518 | # Handle 'custom_post_dl' commands. | 
|  | 519 | custom_post_dl = self.pkg_def.get("custom_post_dl") | 
|  | 520 | if custom_post_dl: | 
|  | 521 | result += " && ".join(custom_post_dl) + " && " | 
|  | 522 |  | 
|  | 523 | # Build and install package based on 'build_type'. | 
|  | 524 | build_type = self.pkg_def["build_type"] | 
|  | 525 | if build_type == "autoconf": | 
|  | 526 | result += self._cmd_build_autoconf() | 
|  | 527 | elif build_type == "cmake": | 
|  | 528 | result += self._cmd_build_cmake() | 
|  | 529 | elif build_type == "custom": | 
|  | 530 | result += self._cmd_build_custom() | 
|  | 531 | elif build_type == "make": | 
|  | 532 | result += self._cmd_build_make() | 
|  | 533 | elif build_type == "meson": | 
|  | 534 | result += self._cmd_build_meson() | 
|  | 535 | else: | 
|  | 536 | raise NotImplementedError( | 
|  | 537 | f"Unhandled build type for {self.package}: {build_type}" | 
|  | 538 | ) | 
|  | 539 |  | 
| Patrick Williams | 6bce2ca | 2021-02-12 21:13:37 -0600 | [diff] [blame] | 540 | # Handle 'custom_post_install' commands. | 
|  | 541 | custom_post_install = self.pkg_def.get("custom_post_install") | 
|  | 542 | if custom_post_install: | 
|  | 543 | result += " && " + " && ".join(custom_post_install) | 
|  | 544 |  | 
| Patrick Williams | ee3c9ee | 2021-02-12 20:56:01 -0600 | [diff] [blame] | 545 | return result | 
|  | 546 |  | 
|  | 547 | def _cmd_build_autoconf(self) -> str: | 
|  | 548 | options = " ".join(self.pkg_def.get("config_flags", [])) | 
|  | 549 | env = " ".join(self.pkg_def.get("config_env", [])) | 
|  | 550 | result = "./bootstrap.sh && " | 
|  | 551 | result += f"{env} ./configure {configure_flags} {options} && " | 
|  | 552 | result += f"make -j{proc_count} && make install" | 
|  | 553 | return result | 
|  | 554 |  | 
|  | 555 | def _cmd_build_cmake(self) -> str: | 
|  | 556 | options = " ".join(self.pkg_def.get("config_flags", [])) | 
|  | 557 | env = " ".join(self.pkg_def.get("config_env", [])) | 
|  | 558 | result = "mkdir builddir && cd builddir && " | 
|  | 559 | result += f"{env} cmake {cmake_flags} {options} .. && " | 
|  | 560 | result += "cmake --build . --target all && " | 
|  | 561 | result += "cmake --build . --target install && " | 
|  | 562 | result += "cd .." | 
|  | 563 | return result | 
|  | 564 |  | 
|  | 565 | def _cmd_build_custom(self) -> str: | 
|  | 566 | return " && ".join(self.pkg_def.get("build_steps", [])) | 
|  | 567 |  | 
|  | 568 | def _cmd_build_make(self) -> str: | 
|  | 569 | return f"make -j{proc_count} && make install" | 
|  | 570 |  | 
|  | 571 | def _cmd_build_meson(self) -> str: | 
|  | 572 | options = " ".join(self.pkg_def.get("config_flags", [])) | 
|  | 573 | env = " ".join(self.pkg_def.get("config_env", [])) | 
|  | 574 | result = f"{env} meson builddir {meson_flags} {options} && " | 
|  | 575 | result += "ninja -C builddir && ninja -C builddir install" | 
|  | 576 | return result | 
|  | 577 |  | 
|  | 578 |  | 
|  | 579 | class Docker: | 
|  | 580 | """Class to assist with Docker interactions.  All methods are static.""" | 
|  | 581 |  | 
|  | 582 | @staticmethod | 
|  | 583 | def timestamp() -> str: | 
|  | 584 | """ Generate a timestamp for today using the ISO week. """ | 
|  | 585 | today = date.today().isocalendar() | 
|  | 586 | return f"{today[0]}-W{today[1]:02}" | 
|  | 587 |  | 
|  | 588 | @staticmethod | 
|  | 589 | def tagname(pkgname: str, dockerfile: str) -> str: | 
|  | 590 | """ Generate a tag name for a package using a hash of the Dockerfile. """ | 
|  | 591 | result = docker_image_name | 
|  | 592 | if pkgname: | 
|  | 593 | result += "-" + pkgname | 
|  | 594 |  | 
|  | 595 | result += ":" + Docker.timestamp() | 
|  | 596 | result += "-" + sha256(dockerfile.encode()).hexdigest()[0:16] | 
|  | 597 |  | 
|  | 598 | return result | 
|  | 599 |  | 
|  | 600 | @staticmethod | 
|  | 601 | def build(pkg: str, tag: str, dockerfile: str) -> None: | 
|  | 602 | """Build a docker image using the Dockerfile and tagging it with 'tag'.""" | 
|  | 603 |  | 
|  | 604 | # If we're not forcing builds, check if it already exists and skip. | 
|  | 605 | if not force_build: | 
|  | 606 | if docker.image.ls(tag, "--format", '"{{.Repository}}:{{.Tag}}"'): | 
|  | 607 | print(f"Image {tag} already exists.  Skipping.", file=sys.stderr) | 
|  | 608 | return | 
|  | 609 |  | 
|  | 610 | # Build it. | 
|  | 611 | #   Capture the output of the 'docker build' command and send it to | 
|  | 612 | #   stderr (prefixed with the package name).  This allows us to see | 
|  | 613 | #   progress but not polute stdout.  Later on we output the final | 
|  | 614 | #   docker tag to stdout and we want to keep that pristine. | 
|  | 615 | # | 
|  | 616 | #   Other unusual flags: | 
|  | 617 | #       --no-cache: Bypass the Docker cache if 'force_build'. | 
|  | 618 | #       --force-rm: Clean up Docker processes if they fail. | 
|  | 619 | docker.build( | 
|  | 620 | proxy_args, | 
|  | 621 | "--network=host", | 
|  | 622 | "--force-rm", | 
|  | 623 | "--no-cache=true" if force_build else "--no-cache=false", | 
|  | 624 | "-t", | 
|  | 625 | tag, | 
|  | 626 | "-", | 
|  | 627 | _in=dockerfile, | 
|  | 628 | _out=( | 
|  | 629 | lambda line: print( | 
|  | 630 | pkg + ":", line, end="", file=sys.stderr, flush=True | 
|  | 631 | ) | 
|  | 632 | ), | 
|  | 633 | ) | 
|  | 634 |  | 
|  | 635 |  | 
|  | 636 | # Read a bunch of environment variables. | 
|  | 637 | docker_image_name = os.environ.get("DOCKER_IMAGE_NAME", "openbmc/ubuntu-unit-test") | 
|  | 638 | force_build = os.environ.get("FORCE_DOCKER_BUILD") | 
|  | 639 | is_automated_ci_build = os.environ.get("BUILD_URL", False) | 
| Patrick Williams | 8949d3c | 2022-04-27 16:41:27 -0500 | [diff] [blame] | 640 | distro = os.environ.get("DISTRO", "ubuntu:jammy") | 
| Patrick Williams | ee3c9ee | 2021-02-12 20:56:01 -0600 | [diff] [blame] | 641 | branch = os.environ.get("BRANCH", "master") | 
|  | 642 | ubuntu_mirror = os.environ.get("UBUNTU_MIRROR") | 
|  | 643 | http_proxy = os.environ.get("http_proxy") | 
|  | 644 |  | 
| Patrick Williams | 65b21fb | 2021-02-12 21:21:14 -0600 | [diff] [blame] | 645 | gerrit_project = os.environ.get("GERRIT_PROJECT") | 
|  | 646 | gerrit_rev = os.environ.get("GERRIT_PATCHSET_REVISION") | 
|  | 647 |  | 
| Patrick Williams | ee3c9ee | 2021-02-12 20:56:01 -0600 | [diff] [blame] | 648 | # Set up some common variables. | 
|  | 649 | username = os.environ.get("USER", "root") | 
|  | 650 | homedir = os.environ.get("HOME", "/root") | 
|  | 651 | gid = os.getgid() | 
|  | 652 | uid = os.getuid() | 
|  | 653 |  | 
| Josh Lehan | 6825a01 | 2022-03-17 18:31:39 -0700 | [diff] [blame] | 654 | # Use well-known constants if user is root | 
|  | 655 | if username == "root": | 
|  | 656 | homedir = "/root" | 
|  | 657 | gid = 0 | 
|  | 658 | uid = 0 | 
|  | 659 |  | 
| Patrick Williams | ee3c9ee | 2021-02-12 20:56:01 -0600 | [diff] [blame] | 660 | # Determine the architecture for Docker. | 
|  | 661 | arch = uname("-m").strip() | 
|  | 662 | if arch == "ppc64le": | 
|  | 663 | docker_base = "ppc64le/" | 
|  | 664 | elif arch == "x86_64": | 
|  | 665 | docker_base = "" | 
| Thang Q. Nguyen | 051b05b | 2021-12-10 08:30:35 +0000 | [diff] [blame] | 666 | elif arch == "aarch64": | 
| Thang Q. Nguyen | f98f1a8 | 2021-12-22 01:59:19 +0000 | [diff] [blame] | 667 | docker_base = "arm64v8/" | 
| Patrick Williams | ee3c9ee | 2021-02-12 20:56:01 -0600 | [diff] [blame] | 668 | else: | 
|  | 669 | print( | 
|  | 670 | f"Unsupported system architecture({arch}) found for docker image", | 
|  | 671 | file=sys.stderr, | 
|  | 672 | ) | 
|  | 673 | sys.exit(1) | 
|  | 674 |  | 
| Patrick Williams | 02871c9 | 2021-02-01 20:57:19 -0600 | [diff] [blame] | 675 | # Special flags if setting up a deb mirror. | 
|  | 676 | mirror = "" | 
|  | 677 | if "ubuntu" in distro and ubuntu_mirror: | 
|  | 678 | mirror = f""" | 
|  | 679 | RUN echo "deb {ubuntu_mirror} $(. /etc/os-release && echo $VERSION_CODENAME) main restricted universe multiverse" > /etc/apt/sources.list && \\ | 
|  | 680 | echo "deb {ubuntu_mirror} $(. /etc/os-release && echo $VERSION_CODENAME)-updates main restricted universe multiverse" >> /etc/apt/sources.list && \\ | 
|  | 681 | echo "deb {ubuntu_mirror} $(. /etc/os-release && echo $VERSION_CODENAME)-security main restricted universe multiverse" >> /etc/apt/sources.list && \\ | 
|  | 682 | echo "deb {ubuntu_mirror} $(. /etc/os-release && echo $VERSION_CODENAME)-proposed main restricted universe multiverse" >> /etc/apt/sources.list && \\ | 
|  | 683 | echo "deb {ubuntu_mirror} $(. /etc/os-release && echo $VERSION_CODENAME)-backports main restricted universe multiverse" >> /etc/apt/sources.list | 
|  | 684 | """ | 
|  | 685 |  | 
|  | 686 | # Special flags for proxying. | 
|  | 687 | proxy_cmd = "" | 
| Adrian Ambrożewicz | 34ec77e | 2021-06-02 10:23:38 +0200 | [diff] [blame] | 688 | proxy_keyserver = "" | 
| Patrick Williams | 02871c9 | 2021-02-01 20:57:19 -0600 | [diff] [blame] | 689 | proxy_args = [] | 
|  | 690 | if http_proxy: | 
|  | 691 | proxy_cmd = f""" | 
|  | 692 | RUN echo "[http]" >> {homedir}/.gitconfig && \ | 
|  | 693 | echo "proxy = {http_proxy}" >> {homedir}/.gitconfig | 
|  | 694 | """ | 
| Adrian Ambrożewicz | 34ec77e | 2021-06-02 10:23:38 +0200 | [diff] [blame] | 695 | proxy_keyserver = f"--keyserver-options http-proxy={http_proxy}" | 
|  | 696 |  | 
| Patrick Williams | 02871c9 | 2021-02-01 20:57:19 -0600 | [diff] [blame] | 697 | proxy_args.extend( | 
|  | 698 | [ | 
|  | 699 | "--build-arg", | 
|  | 700 | f"http_proxy={http_proxy}", | 
|  | 701 | "--build-arg", | 
| Lei YU | d461cd6 | 2021-02-18 14:25:49 +0800 | [diff] [blame] | 702 | f"https_proxy={http_proxy}", | 
| Patrick Williams | 02871c9 | 2021-02-01 20:57:19 -0600 | [diff] [blame] | 703 | ] | 
|  | 704 | ) | 
|  | 705 |  | 
| Patrick Williams | ee3c9ee | 2021-02-12 20:56:01 -0600 | [diff] [blame] | 706 | # Create base Dockerfile. | 
| Patrick Williams | a18d9c5 | 2021-02-05 09:52:26 -0600 | [diff] [blame] | 707 | dockerfile_base = f""" | 
|  | 708 | FROM {docker_base}{distro} | 
| Patrick Williams | 02871c9 | 2021-02-01 20:57:19 -0600 | [diff] [blame] | 709 |  | 
|  | 710 | {mirror} | 
|  | 711 |  | 
|  | 712 | ENV DEBIAN_FRONTEND noninteractive | 
|  | 713 |  | 
| Patrick Williams | 8949d3c | 2022-04-27 16:41:27 -0500 | [diff] [blame] | 714 | ENV PYTHONPATH "/usr/local/lib/python3.10/site-packages/" | 
| Patrick Williams | 02871c9 | 2021-02-01 20:57:19 -0600 | [diff] [blame] | 715 |  | 
| Patrick Williams | bb16ac1 | 2021-04-12 12:23:51 -0500 | [diff] [blame] | 716 | # Sometimes the ubuntu key expires and we need a way to force an execution | 
|  | 717 | # of the apt-get commands for the dbgsym-keyring.  When this happens we see | 
|  | 718 | # an error like: "Release: The following signatures were invalid:" | 
|  | 719 | # Insert a bogus echo that we can change here when we get this error to force | 
|  | 720 | # the update. | 
|  | 721 | RUN echo "ubuntu keyserver rev as of 2021-04-21" | 
|  | 722 |  | 
| Patrick Williams | 02871c9 | 2021-02-01 20:57:19 -0600 | [diff] [blame] | 723 | # We need the keys to be imported for dbgsym repos | 
|  | 724 | # New releases have a package, older ones fall back to manual fetching | 
|  | 725 | # https://wiki.ubuntu.com/Debug%20Symbol%20Packages | 
| Patrick Williams | 5083743 | 2021-02-06 12:24:05 -0600 | [diff] [blame] | 726 | RUN apt-get update && apt-get dist-upgrade -yy && \ | 
| Patrick Williams | f79ce4c | 2021-04-30 16:00:49 -0500 | [diff] [blame] | 727 | ( apt-get install gpgv ubuntu-dbgsym-keyring || \ | 
| Patrick Williams | 5083743 | 2021-02-06 12:24:05 -0600 | [diff] [blame] | 728 | ( apt-get install -yy dirmngr && \ | 
|  | 729 | apt-key adv --keyserver keyserver.ubuntu.com \ | 
| Adrian Ambrożewicz | 34ec77e | 2021-06-02 10:23:38 +0200 | [diff] [blame] | 730 | {proxy_keyserver} \ | 
| Patrick Williams | 5083743 | 2021-02-06 12:24:05 -0600 | [diff] [blame] | 731 | --recv-keys F2EDC64DC5AEE1F6B9C621F0C8CAB6595FDFF622 ) ) | 
| Patrick Williams | 02871c9 | 2021-02-01 20:57:19 -0600 | [diff] [blame] | 732 |  | 
|  | 733 | # Parse the current repo list into a debug repo list | 
|  | 734 | RUN sed -n '/^deb /s,^deb [^ ]* ,deb http://ddebs.ubuntu.com ,p' /etc/apt/sources.list >/etc/apt/sources.list.d/debug.list | 
|  | 735 |  | 
|  | 736 | # Remove non-existent debug repos | 
|  | 737 | RUN sed -i '/-\(backports\|security\) /d' /etc/apt/sources.list.d/debug.list | 
|  | 738 |  | 
|  | 739 | RUN cat /etc/apt/sources.list.d/debug.list | 
|  | 740 |  | 
|  | 741 | RUN apt-get update && apt-get dist-upgrade -yy && apt-get install -yy \ | 
| William A. Kennington III | b84d59d | 2021-05-15 03:23:58 -0700 | [diff] [blame] | 742 | gcc-11 \ | 
|  | 743 | g++-11 \ | 
| Patrick Williams | 02871c9 | 2021-02-01 20:57:19 -0600 | [diff] [blame] | 744 | libc6-dbg \ | 
|  | 745 | libc6-dev \ | 
|  | 746 | libtool \ | 
|  | 747 | bison \ | 
|  | 748 | libdbus-1-dev \ | 
|  | 749 | flex \ | 
|  | 750 | cmake \ | 
|  | 751 | python3 \ | 
|  | 752 | python3-dev\ | 
|  | 753 | python3-yaml \ | 
|  | 754 | python3-mako \ | 
|  | 755 | python3-pip \ | 
|  | 756 | python3-setuptools \ | 
|  | 757 | python3-git \ | 
|  | 758 | python3-socks \ | 
|  | 759 | pkg-config \ | 
|  | 760 | autoconf \ | 
|  | 761 | autoconf-archive \ | 
|  | 762 | libsystemd-dev \ | 
|  | 763 | systemd \ | 
|  | 764 | libssl-dev \ | 
|  | 765 | libevdev-dev \ | 
| Patrick Williams | 02871c9 | 2021-02-01 20:57:19 -0600 | [diff] [blame] | 766 | libjpeg-dev \ | 
|  | 767 | libpng-dev \ | 
|  | 768 | ninja-build \ | 
|  | 769 | sudo \ | 
|  | 770 | curl \ | 
|  | 771 | git \ | 
|  | 772 | dbus \ | 
|  | 773 | iputils-ping \ | 
| Patrick Williams | f89c850 | 2021-10-01 11:50:09 -0500 | [diff] [blame] | 774 | clang-13 \ | 
|  | 775 | clang-format-13 \ | 
|  | 776 | clang-tidy-13 \ | 
|  | 777 | clang-tools-13 \ | 
| Patrick Williams | 02871c9 | 2021-02-01 20:57:19 -0600 | [diff] [blame] | 778 | shellcheck \ | 
|  | 779 | npm \ | 
|  | 780 | iproute2 \ | 
|  | 781 | libnl-3-dev \ | 
|  | 782 | libnl-genl-3-dev \ | 
|  | 783 | libconfig++-dev \ | 
|  | 784 | libsnmp-dev \ | 
|  | 785 | valgrind \ | 
|  | 786 | valgrind-dbg \ | 
|  | 787 | libpam0g-dev \ | 
|  | 788 | xxd \ | 
|  | 789 | libi2c-dev \ | 
|  | 790 | wget \ | 
|  | 791 | libldap2-dev \ | 
|  | 792 | libprotobuf-dev \ | 
| William A. Kennington III | dafe752 | 2021-05-28 01:51:06 -0700 | [diff] [blame] | 793 | liburing-dev \ | 
| Patrick Williams | 8949d3c | 2022-04-27 16:41:27 -0500 | [diff] [blame] | 794 | liburing2-dbgsym \ | 
| Patrick Williams | 02871c9 | 2021-02-01 20:57:19 -0600 | [diff] [blame] | 795 | libperlio-gzip-perl \ | 
|  | 796 | libjson-perl \ | 
|  | 797 | protobuf-compiler \ | 
|  | 798 | libgpiod-dev \ | 
|  | 799 | device-tree-compiler \ | 
|  | 800 | cppcheck \ | 
|  | 801 | libpciaccess-dev \ | 
|  | 802 | libmimetic-dev \ | 
|  | 803 | libxml2-utils \ | 
| Patrick Williams | 0eedeed | 2021-02-06 19:06:09 -0600 | [diff] [blame] | 804 | libxml-simple-perl \ | 
| John Wedig | 9adf68d | 2021-11-16 14:00:39 -0800 | [diff] [blame] | 805 | rsync \ | 
|  | 806 | libcryptsetup-dev | 
| Patrick Williams | 02871c9 | 2021-02-01 20:57:19 -0600 | [diff] [blame] | 807 |  | 
| Patrick Williams | 3ea4cd7 | 2022-04-14 13:53:08 -0500 | [diff] [blame] | 808 | # Apply autoconf-archive-v2022.02.11 file ax_cxx_compile_stdcxx for C++20. | 
|  | 809 | RUN curl "http://git.savannah.gnu.org/gitweb/?p=autoconf-archive.git;a=blob_plain;f=m4/ax_cxx_compile_stdcxx.m4;hb=3311b6bdeff883c6a13952594a9dcb60bce6ba80" \ | 
|  | 810 | > /usr/share/aclocal/ax_cxx_compile_stdcxx.m4 | 
|  | 811 |  | 
| Manojkiran Eda | 87111bb | 2021-08-14 11:26:16 +0530 | [diff] [blame] | 812 | RUN npm install -g eslint@latest eslint-plugin-json@latest | 
|  | 813 |  | 
| William A. Kennington III | b84d59d | 2021-05-15 03:23:58 -0700 | [diff] [blame] | 814 | RUN update-alternatives --install /usr/bin/gcc gcc /usr/bin/gcc-11 11 \ | 
|  | 815 | --slave /usr/bin/g++ g++ /usr/bin/g++-11 \ | 
|  | 816 | --slave /usr/bin/gcov gcov /usr/bin/gcov-11 \ | 
|  | 817 | --slave /usr/bin/gcov-dump gcov-dump /usr/bin/gcov-dump-11 \ | 
|  | 818 | --slave /usr/bin/gcov-tool gcov-tool /usr/bin/gcov-tool-11 | 
| Patrick Williams | 02871c9 | 2021-02-01 20:57:19 -0600 | [diff] [blame] | 819 |  | 
| Patrick Williams | f89c850 | 2021-10-01 11:50:09 -0500 | [diff] [blame] | 820 | RUN update-alternatives --install /usr/bin/clang clang /usr/bin/clang-13 1000 \ | 
|  | 821 | --slave /usr/bin/clang++ clang++ /usr/bin/clang++-13 \ | 
|  | 822 | --slave /usr/bin/clang-tidy clang-tidy /usr/bin/clang-tidy-13 \ | 
|  | 823 | --slave /usr/bin/clang-format clang-format /usr/bin/clang-format-13 \ | 
|  | 824 | --slave /usr/bin/run-clang-tidy run-clang-tidy.py /usr/bin/run-clang-tidy-13 \ | 
|  | 825 | --slave /usr/bin/scan-build scan-build /usr/bin/scan-build-13 | 
| Patrick Williams | 02871c9 | 2021-02-01 20:57:19 -0600 | [diff] [blame] | 826 |  | 
| Patrick Williams | 5083743 | 2021-02-06 12:24:05 -0600 | [diff] [blame] | 827 | """ | 
|  | 828 |  | 
|  | 829 | if is_automated_ci_build: | 
|  | 830 | dockerfile_base += f""" | 
|  | 831 | # Run an arbitrary command to polute the docker cache regularly force us | 
|  | 832 | # to re-run `apt-get update` daily. | 
| Patrick Williams | ee3c9ee | 2021-02-12 20:56:01 -0600 | [diff] [blame] | 833 | RUN echo {Docker.timestamp()} | 
| Patrick Williams | 5083743 | 2021-02-06 12:24:05 -0600 | [diff] [blame] | 834 | RUN apt-get update && apt-get dist-upgrade -yy | 
|  | 835 |  | 
|  | 836 | """ | 
|  | 837 |  | 
|  | 838 | dockerfile_base += f""" | 
| Patrick Williams | 02871c9 | 2021-02-01 20:57:19 -0600 | [diff] [blame] | 839 | RUN pip3 install inflection | 
|  | 840 | RUN pip3 install pycodestyle | 
|  | 841 | RUN pip3 install jsonschema | 
| Patrick Williams | e86aa1e | 2022-04-14 13:55:00 -0500 | [diff] [blame] | 842 | RUN pip3 install meson==0.61.3 | 
| Patrick Williams | 02871c9 | 2021-02-01 20:57:19 -0600 | [diff] [blame] | 843 | RUN pip3 install protobuf | 
| Manojkiran Eda | e6f120a | 2021-03-20 11:13:43 +0530 | [diff] [blame] | 844 | RUN pip3 install codespell | 
| Ed Tanous | ca8c4a8 | 2022-02-08 13:58:22 -0800 | [diff] [blame] | 845 | RUN pip3 install requests | 
| Patrick Williams | a18d9c5 | 2021-02-05 09:52:26 -0600 | [diff] [blame] | 846 | """ | 
| Patrick Williams | 02871c9 | 2021-02-01 20:57:19 -0600 | [diff] [blame] | 847 |  | 
| Patrick Williams | ee3c9ee | 2021-02-12 20:56:01 -0600 | [diff] [blame] | 848 | # Build the base and stage docker images. | 
|  | 849 | docker_base_img_name = Docker.tagname("base", dockerfile_base) | 
|  | 850 | Docker.build("base", docker_base_img_name, dockerfile_base) | 
|  | 851 | Package.generate_all() | 
| Patrick Williams | 02871c9 | 2021-02-01 20:57:19 -0600 | [diff] [blame] | 852 |  | 
| Patrick Williams | ee3c9ee | 2021-02-12 20:56:01 -0600 | [diff] [blame] | 853 | # Create the final Dockerfile. | 
| Patrick Williams | a18d9c5 | 2021-02-05 09:52:26 -0600 | [diff] [blame] | 854 | dockerfile = f""" | 
| Patrick Williams | 02871c9 | 2021-02-01 20:57:19 -0600 | [diff] [blame] | 855 | # Build the final output image | 
| Patrick Williams | a18d9c5 | 2021-02-05 09:52:26 -0600 | [diff] [blame] | 856 | FROM {docker_base_img_name} | 
| Patrick Williams | ee3c9ee | 2021-02-12 20:56:01 -0600 | [diff] [blame] | 857 | {Package.df_all_copycmds()} | 
| Patrick Williams | 02871c9 | 2021-02-01 20:57:19 -0600 | [diff] [blame] | 858 |  | 
|  | 859 | # Some of our infrastructure still relies on the presence of this file | 
|  | 860 | # even though it is no longer needed to rebuild the docker environment | 
|  | 861 | # NOTE: The file is sorted to ensure the ordering is stable. | 
| Patrick Williams | ee3c9ee | 2021-02-12 20:56:01 -0600 | [diff] [blame] | 862 | RUN echo '{Package.depcache()}' > /tmp/depcache | 
| Patrick Williams | 02871c9 | 2021-02-01 20:57:19 -0600 | [diff] [blame] | 863 |  | 
|  | 864 | # Final configuration for the workspace | 
| Josh Lehan | 6825a01 | 2022-03-17 18:31:39 -0700 | [diff] [blame] | 865 | RUN grep -q {gid} /etc/group || groupadd -f -g {gid} {username} | 
| Patrick Williams | 02871c9 | 2021-02-01 20:57:19 -0600 | [diff] [blame] | 866 | RUN mkdir -p "{os.path.dirname(homedir)}" | 
|  | 867 | RUN grep -q {uid} /etc/passwd || useradd -d {homedir} -m -u {uid} -g {gid} {username} | 
|  | 868 | RUN sed -i '1iDefaults umask=000' /etc/sudoers | 
|  | 869 | RUN echo "{username} ALL=(ALL) NOPASSWD: ALL" >>/etc/sudoers | 
|  | 870 |  | 
| Andrew Geissler | 305a9a5 | 2021-04-07 11:08:40 -0500 | [diff] [blame] | 871 | # Ensure user has ability to write to /usr/local for different tool | 
|  | 872 | # and data installs | 
| Andrew Geissler | 7bb00b1 | 2021-05-10 15:12:08 -0500 | [diff] [blame] | 873 | RUN chown -R {username}:{username} /usr/local/share | 
| Andrew Geissler | 305a9a5 | 2021-04-07 11:08:40 -0500 | [diff] [blame] | 874 |  | 
| Patrick Williams | 02871c9 | 2021-02-01 20:57:19 -0600 | [diff] [blame] | 875 | {proxy_cmd} | 
|  | 876 |  | 
|  | 877 | RUN /bin/bash | 
|  | 878 | """ | 
|  | 879 |  | 
| Patrick Williams | a18d9c5 | 2021-02-05 09:52:26 -0600 | [diff] [blame] | 880 | # Do the final docker build | 
| Patrick Williams | ee3c9ee | 2021-02-12 20:56:01 -0600 | [diff] [blame] | 881 | docker_final_img_name = Docker.tagname(None, dockerfile) | 
|  | 882 | Docker.build("final", docker_final_img_name, dockerfile) | 
|  | 883 |  | 
| Patrick Williams | 00536fb | 2021-02-11 14:28:49 -0600 | [diff] [blame] | 884 | # Print the tag of the final image. | 
|  | 885 | print(docker_final_img_name) |