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