build 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604
  1. #!/usr/bin/env bash
  2. # This script helps to build release artifacts.
  3. # arg1: profile, e.g. emqx | emqx-enterprise
  4. # arg2: artifact, e.g. rel | relup | tgz | pkg
  5. set -euo pipefail
  6. if [ "${DEBUG:-0}" -eq 1 ]; then
  7. set -x
  8. # set this for rebar3
  9. export DIAGNOSTIC=1
  10. fi
  11. log_red() {
  12. local RED='\033[0;31m' # Red
  13. local NC='\033[0m' # No Color
  14. echo -e "${RED}${1}${NC}"
  15. }
  16. PROFILE_ARG="$1"
  17. ARTIFACT="$2"
  18. is_enterprise() {
  19. case "$1" in
  20. *enterprise*)
  21. echo 'yes'
  22. ;;
  23. *)
  24. echo 'no'
  25. ;;
  26. esac
  27. }
  28. PROFILE_ENV="${PROFILE:-${PROFILE_ARG}}"
  29. case "$(is_enterprise "$PROFILE_ARG"),$(is_enterprise "$PROFILE_ENV")" in
  30. 'yes,yes')
  31. true
  32. ;;
  33. 'no,no')
  34. true
  35. ;;
  36. *)
  37. log_red "PROFILE env var is set to '$PROFILE_ENV', but '$0' arg1 is '$PROFILE_ARG'"
  38. exit 1
  39. ;;
  40. esac
  41. # make sure PROFILE is exported, it is needed by rebar.config.erl
  42. PROFILE=$PROFILE_ARG
  43. export PROFILE
  44. # ensure dir
  45. cd -P -- "$(dirname -- "${BASH_SOURCE[0]}")"
  46. PKG_VSN="${PKG_VSN:-$(./pkg-vsn.sh "$PROFILE")}"
  47. export PKG_VSN
  48. SYSTEM="$(./scripts/get-distro.sh)"
  49. ARCH="$(uname -m)"
  50. case "$ARCH" in
  51. x86_64)
  52. ARCH='amd64'
  53. ;;
  54. aarch64)
  55. ARCH='arm64'
  56. ;;
  57. arm*)
  58. ARCH='arm64'
  59. ;;
  60. esac
  61. export ARCH
  62. ##
  63. ## Support RPM and Debian based linux systems
  64. ##
  65. if [ "$(uname -s)" = 'Linux' ]; then
  66. case "${SYSTEM:-}" in
  67. ubuntu*|debian*|raspbian*)
  68. PKGERDIR='deb'
  69. ;;
  70. *)
  71. PKGERDIR='rpm'
  72. ;;
  73. esac
  74. fi
  75. if [ "${SYSTEM}" = 'windows' ]; then
  76. # windows does not like the find
  77. FIND="/usr/bin/find"
  78. TAR="/usr/bin/tar"
  79. export BUILD_WITHOUT_ROCKSDB="on"
  80. else
  81. FIND='find'
  82. TAR='tar'
  83. fi
  84. log() {
  85. local msg="$1"
  86. # rebar3 prints ===>, so we print ===<
  87. echo "===< $msg"
  88. }
  89. prepare_erl_libs() {
  90. local libs_dir="$1"
  91. local erl_libs="${ERL_LIBS:-}"
  92. local sep
  93. if [ "${SYSTEM}" = 'windows' ]; then
  94. sep=';'
  95. else
  96. sep=':'
  97. fi
  98. for app in "${libs_dir}"/*; do
  99. if [ -d "${app}/ebin" ]; then
  100. if [ -n "$erl_libs" ]; then
  101. erl_libs="${erl_libs}${sep}${app}"
  102. else
  103. erl_libs="${app}"
  104. fi
  105. fi
  106. done
  107. export ERL_LIBS="$erl_libs"
  108. }
  109. make_docs() {
  110. case "$(is_enterprise "$PROFILE")" in
  111. 'yes')
  112. SCHEMA_MODULE='emqx_enterprise_schema'
  113. ;;
  114. 'no')
  115. SCHEMA_MODULE='emqx_conf_schema'
  116. ;;
  117. esac
  118. prepare_erl_libs "_build/$PROFILE/checkouts"
  119. prepare_erl_libs "_build/$PROFILE/lib"
  120. local docdir="_build/docgen/$PROFILE"
  121. mkdir -p "$docdir"
  122. # shellcheck disable=SC2086
  123. erl -enable-feature maybe_expr -noshell -eval \
  124. "ok = emqx_conf:dump_schema('$docdir', $SCHEMA_MODULE), \
  125. halt(0)."
  126. local desc="$docdir/desc.en.hocon"
  127. if command -v jq &> /dev/null; then
  128. log "Generating $desc"
  129. scripts/merge-i18n.escript | jq --sort-keys . > "$desc"
  130. else
  131. # it is not a big deal if we cannot generate the desc
  132. log_red "NOT Generated: $desc"
  133. fi
  134. }
  135. ## arg1 is the profile for which the following args (as app names) should be excluded
  136. assert_no_excluded_deps() {
  137. local profile="$1"
  138. shift 1
  139. if [ "$PROFILE" != "$profile" ]; then
  140. # not currently building the profile which has apps to be excluded
  141. return 0
  142. fi
  143. local rel_dir="_build/$PROFILE/rel/emqx/lib"
  144. local excluded_apps=( "$@" )
  145. local found
  146. for app in "${excluded_apps[@]}"; do
  147. found="$($FIND "$rel_dir" -maxdepth 1 -type d -name "$app-*")"
  148. if [ -n "${found}" ]; then
  149. log_red "ERROR: ${app} should not be included in ${PROFILE}"
  150. log_red "ERROR: found ${app} in ${rel_dir}"
  151. exit 1
  152. fi
  153. done
  154. }
  155. just_compile() {
  156. ./scripts/pre-compile.sh "$PROFILE"
  157. # make_elixir_rel always create rebar.lock
  158. # delete it to make git clone + checkout work because we use shallow close for rebar deps
  159. rm -f rebar.lock
  160. # compile all beams
  161. ./rebar3 as "$PROFILE" compile
  162. make_docs
  163. }
  164. just_compile_elixir() {
  165. ./scripts/pre-compile.sh "$PROFILE"
  166. rm -f rebar.lock
  167. env MIX_ENV="$PROFILE" mix local.rebar --if-missing --force
  168. env MIX_ENV="$PROFILE" mix local.rebar rebar3 "${PWD}/rebar3" --if-missing --force
  169. env MIX_ENV="$PROFILE" mix local.hex --if-missing --force
  170. env MIX_ENV="$PROFILE" mix deps.get
  171. env MIX_ENV="$PROFILE" mix compile
  172. }
  173. make_rel() {
  174. local release_or_tar="${1}"
  175. just_compile
  176. # now assemble the release tar
  177. ./rebar3 as "$PROFILE" "$release_or_tar"
  178. assert_no_excluded_deps emqx-enterprise emqx_telemetry
  179. }
  180. make_elixir_rel() {
  181. ./scripts/pre-compile.sh "$PROFILE"
  182. export_elixir_release_vars "$PROFILE"
  183. env MIX_ENV="$PROFILE" mix local.rebar --if-missing --force
  184. env MIX_ENV="$PROFILE" mix local.rebar rebar3 "${PWD}/rebar3" --if-missing --force
  185. env MIX_ENV="$PROFILE" mix local.hex --if-missing --force
  186. env MIX_ENV="$PROFILE" mix deps.get
  187. env MIX_ENV="$PROFILE" mix release --overwrite
  188. assert_no_excluded_deps emqx-enterprise emqx_telemetry
  189. }
  190. ## extract previous version .tar.gz files to _build/$PROFILE/rel/emqx before making relup
  191. make_relup() {
  192. local rel_dir="_build/$PROFILE/rel/emqx"
  193. local name_pattern
  194. name_pattern="${PROFILE}-$(./pkg-vsn.sh "$PROFILE" --vsn_matcher --long)"
  195. local releases=()
  196. mkdir -p _upgrade_base
  197. while read -r tgzfile ; do
  198. local base_vsn
  199. base_vsn="$(echo "$tgzfile" | grep -oE "[0-9]+\.[0-9]+\.[0-9]+(-(alpha|beta|rc)\.[0-9])?(-[0-9a-f]{8})?" | head -1)"
  200. ## we have to create tmp dir to untar old tgz, as `tar --skip-old-files` is not supported on all plantforms
  201. local tmp_dir
  202. tmp_dir="$(mktemp -d -t emqx.XXXXXXX)"
  203. $TAR -C "$tmp_dir" -zxf "$tgzfile"
  204. mkdir -p "${rel_dir}/releases/"
  205. cp -npr "$tmp_dir/releases"/* "${rel_dir}/releases/"
  206. ## There is for some reason a copy of the '$PROFILE.rel' file to releases dir,
  207. ## the content is duplicated to releases/5.0.0/$PROFILE.rel.
  208. ## This file seems to be useless, but yet confusing as it does not change after upgrade/downgrade
  209. ## Hence we force delete this file.
  210. rm -f "${rel_dir}/releases/${PROFILE}.rel"
  211. mkdir -p "${rel_dir}/lib/"
  212. cp -npr "$tmp_dir/lib"/* "${rel_dir}/lib/"
  213. rm -rf "$tmp_dir"
  214. releases+=( "$base_vsn" )
  215. done < <("$FIND" _upgrade_base -maxdepth 1 -name "${name_pattern}.tar.gz" -type f)
  216. if [ ${#releases[@]} -eq 0 ]; then
  217. log "No upgrade base found, relup ignored"
  218. return 0
  219. fi
  220. RELX_BASE_VERSIONS="$(IFS=, ; echo "${releases[*]}")"
  221. export RELX_BASE_VERSIONS
  222. ./rebar3 as "$PROFILE" relup --relname emqx --relvsn "${PKG_VSN}"
  223. }
  224. cp_dyn_libs() {
  225. local rel_dir="$1"
  226. local target_dir="${rel_dir}/dynlibs"
  227. if ! [ "$(uname -s)" = 'Linux' ]; then
  228. return 0;
  229. fi
  230. mkdir -p "$target_dir"
  231. while read -r so_file; do
  232. cp -L "$so_file" "$target_dir/"
  233. done < <("$FIND" "$rel_dir" -type f \( -name "*.so*" -o -name "beam.smp" \) -print0 \
  234. | xargs -0 ldd \
  235. | grep -E '(libcrypto)|(libtinfo)|(libatomic)' \
  236. | awk '{print $3}' \
  237. | sort -u)
  238. }
  239. ## Re-pack the relx assembled .tar.gz to EMQX's package naming scheme
  240. ## It assumes the .tar.gz has been built -- relies on Makefile dependency
  241. make_tgz() {
  242. local pkgpath="_packages/${PROFILE}"
  243. local src_tarball
  244. local target_name
  245. local target
  246. if [ "${IS_ELIXIR:-no}" = "yes" ]
  247. then
  248. # ensure src_tarball exists
  249. ELIXIR_MAKE_TAR=yes make_elixir_rel
  250. local relpath="_build/${PROFILE}"
  251. full_vsn="$(./pkg-vsn.sh "$PROFILE" --long --elixir)"
  252. else
  253. # build the src_tarball again to ensure relup is included
  254. # elixir does not have relup yet.
  255. make_rel tar
  256. local relpath="_build/${PROFILE}/rel/emqx"
  257. full_vsn="$(./pkg-vsn.sh "$PROFILE" --long)"
  258. fi
  259. case "$SYSTEM" in
  260. macos*)
  261. target_name="${PROFILE}-${full_vsn}.zip"
  262. ;;
  263. windows*)
  264. target_name="${PROFILE}-${full_vsn}.zip"
  265. ;;
  266. *)
  267. target_name="${PROFILE}-${full_vsn}.tar.gz"
  268. ;;
  269. esac
  270. target="${pkgpath}/${target_name}"
  271. src_tarball="${relpath}/emqx-${PKG_VSN}.tar.gz"
  272. tard="$(mktemp -d -t emqx.XXXXXXX)"
  273. mkdir -p "${tard}/emqx"
  274. mkdir -p "${pkgpath}"
  275. if [ ! -f "$src_tarball" ]; then
  276. log_red "ERROR: $src_tarball is not found"
  277. fi
  278. $TAR zxf "${src_tarball}" -C "${tard}/emqx"
  279. if [ -f "${tard}/emqx/releases/${PKG_VSN}/relup" ]; then
  280. ./scripts/relup-build/inject-relup.escript "${tard}/emqx/releases/${PKG_VSN}/relup"
  281. fi
  282. ## try to be portable for tar.gz packages.
  283. ## for DEB and RPM packages the dependencies are resoved by yum and apt
  284. cp_dyn_libs "${tard}/emqx"
  285. case "$SYSTEM" in
  286. macos*)
  287. # if the flag to sign macos binaries is set, but developer certificate
  288. # or certificate password is not configured, reset the flag
  289. # could happen, for example, when people submit PR from a fork, in this
  290. # case they cannot access secrets
  291. if [[ "${APPLE_SIGN_BINARIES:-0}" == 1 && \
  292. ( "${APPLE_DEVELOPER_ID_BUNDLE:-0}" == 0 || \
  293. "${APPLE_DEVELOPER_ID_BUNDLE_PASSWORD:-0}" == 0 ) ]]; then
  294. echo "Apple developer certificate is not configured, skip signing"
  295. APPLE_SIGN_BINARIES=0
  296. fi
  297. if [ "${APPLE_SIGN_BINARIES:-0}" = 1 ]; then
  298. ./scripts/macos-sign-binaries.sh "${tard}/emqx"
  299. fi
  300. ## create zip after change dir
  301. ## to avoid creating an extra level of 'emqx' dir in the .zip file
  302. pushd "${tard}/emqx" >/dev/null
  303. zip -r "../${target_name}" -- * >/dev/null
  304. popd >/dev/null
  305. mv "${tard}/${target_name}" "${target}"
  306. if [ "${APPLE_SIGN_BINARIES:-0}" = 1 ]; then
  307. # notarize the package
  308. # if fails, check what went wrong with this command:
  309. # xcrun notarytool log \
  310. # --apple-id <apple id> \
  311. # --password <apple id password>
  312. # --team-id <apple team id> <submission-id>
  313. echo 'Submitting the package for notarization to Apple (normally takes about a minute)'
  314. notarytool_output="$(xcrun notarytool submit \
  315. --apple-id "${APPLE_ID}" \
  316. --password "${APPLE_ID_PASSWORD}" \
  317. --team-id "${APPLE_TEAM_ID}" "${target}" \
  318. --no-progress \
  319. --wait)"
  320. echo "$notarytool_output"
  321. echo "$notarytool_output" | grep -q 'status: Accepted' || {
  322. echo 'Notarization failed';
  323. exit 1;
  324. }
  325. fi
  326. # sha256sum may not be available on macos
  327. openssl dgst -sha256 "${target}" | cut -d ' ' -f 2 > "${target}.sha256"
  328. ;;
  329. windows*)
  330. pushd "${tard}" >/dev/null
  331. 7z a "${target_name}" ./emqx/* >/dev/null
  332. popd >/dev/null
  333. mv "${tard}/${target_name}" "${target}"
  334. sha256sum "${target}" | head -c 64 > "${target}.sha256"
  335. ;;
  336. *)
  337. ## create tar after change dir
  338. ## to avoid creating an extra level of 'emqx' dir in the .tar.gz file
  339. pushd "${tard}/emqx" >/dev/null
  340. $TAR -zcf "../${target_name}" -- *
  341. popd >/dev/null
  342. mv "${tard}/${target_name}" "${target}"
  343. sha256sum "${target}" | head -c 64 > "${target}.sha256"
  344. ;;
  345. esac
  346. log "Archive successfully repacked: ${target}"
  347. log "Archive sha256sum: $(cat "${target}.sha256")"
  348. }
  349. docker_cleanup() {
  350. rm -f ./.dockerignore >/dev/null
  351. # shellcheck disable=SC2015
  352. [ -f ./.dockerignore.bak ] && mv ./.dockerignore.bak ./.dockerignore >/dev/null || true
  353. }
  354. function is_ecr_and_enterprise() {
  355. local registry="$1"
  356. local profile="$2"
  357. if [[ "$registry" == public.ecr.aws* ]] && [[ "$profile" == *enterprise* ]]; then
  358. return 0
  359. else
  360. return 1
  361. fi
  362. }
  363. ## Build the default docker image based on debian 12.
  364. make_docker() {
  365. local EMQX_BUILDER_VERSION="${EMQX_BUILDER_VERSION:-5.3-5}"
  366. local EMQX_BUILDER_PLATFORM="${EMQX_BUILDER_PLATFORM:-debian12}"
  367. local EMQX_BUILDER_OTP="${EMQX_BUILDER_OTP:-25.3.2-2}"
  368. local EMQX_BUILDER_ELIXIR="${EMQX_BUILDER_ELIXIR:-1.15.7}"
  369. local EMQX_BUILDER=${EMQX_BUILDER:-ghcr.io/emqx/emqx-builder/${EMQX_BUILDER_VERSION}:${EMQX_BUILDER_ELIXIR}-${EMQX_BUILDER_OTP}-${EMQX_BUILDER_PLATFORM}}
  370. local EMQX_RUNNER="${EMQX_RUNNER:-${EMQX_DEFAULT_RUNNER}}"
  371. local EMQX_DOCKERFILE="${EMQX_DOCKERFILE:-deploy/docker/Dockerfile}"
  372. local EMQX_SOURCE_TYPE="${EMQX_SOURCE_TYPE:-src}"
  373. # shellcheck disable=SC2155
  374. local VSN_MAJOR="$(scripts/semver.sh "$PKG_VSN" --major)"
  375. # shellcheck disable=SC2155
  376. local VSN_MINOR="$(scripts/semver.sh "$PKG_VSN" --minor)"
  377. # shellcheck disable=SC2155
  378. local VSN_PATCH="$(scripts/semver.sh "$PKG_VSN" --patch)"
  379. local SUFFIX=''
  380. if [[ "$PROFILE" = *-elixir ]]; then
  381. SUFFIX="-elixir"
  382. fi
  383. local DOCKER_REGISTRY="${DOCKER_REGISTRY:-docker.io}"
  384. local DOCKER_REGISTRIES=( )
  385. IFS=',' read -ra DOCKER_REGISTRY_ARR <<< "$DOCKER_REGISTRY"
  386. for r in "${DOCKER_REGISTRY_ARR[@]}"; do
  387. # append to DOCKER_REGISTRIES
  388. DOCKER_REGISTRIES+=("$r")
  389. done
  390. local DOCKER_ORG="${DOCKER_ORG:-emqx}"
  391. local EMQX_BASE_DOCKER_TAG="${DOCKER_ORG}/${PROFILE%%-elixir}"
  392. local default_tag="${EMQX_BASE_DOCKER_TAG}:${PKG_VSN}${SUFFIX}"
  393. local EMQX_IMAGE_TAG="${EMQX_IMAGE_TAG:-$default_tag}"
  394. local EDITION=Opensource
  395. local LICENSE='Apache-2.0'
  396. local PRODUCT_URL='https://www.emqx.io'
  397. local PRODUCT_DESCRIPTION='Official docker image for EMQX, the most scalable open-source MQTT broker for IoT, IIoT, and connected vehicles.'
  398. local DOCUMENTATION_URL='https://www.emqx.io/docs/en/latest/'
  399. ## extra_deps is a comma separated list of debian 12 package names
  400. local EXTRA_DEPS=''
  401. if [[ "$PROFILE" = *enterprise* ]]; then
  402. EXTRA_DEPS='libsasl2-2,libsasl2-modules-gssapi-mit'
  403. EDITION=Enterprise
  404. LICENSE='(Apache-2.0 AND BSL-1.1)'
  405. PRODUCT_URL='https://www.emqx.com/en/products/emqx'
  406. PRODUCT_DESCRIPTION='Official docker image for EMQX Enterprise, an enterprise MQTT platform at scale. '
  407. DOCUMENTATION_URL='https://docs.emqx.com/en/enterprise/latest/'
  408. fi
  409. local ISO_8601_DATE GIT_REVISION
  410. ISO_8601_DATE="$(date -u +"%Y-%m-%dT%H:%M:%SZ")"
  411. GIT_REVISION="$(git rev-parse HEAD)"
  412. export BUILDX_NO_DEFAULT_ATTESTATIONS=1
  413. local DOCKER_BUILDX_ARGS=(
  414. --build-arg BUILD_FROM="${EMQX_BUILDER}" \
  415. --build-arg RUN_FROM="${EMQX_RUNNER}" \
  416. --build-arg SOURCE_TYPE="${EMQX_SOURCE_TYPE}" \
  417. --build-arg PROFILE="${PROFILE%%-elixir}" \
  418. --build-arg IS_ELIXIR="$([[ "$PROFILE" = *-elixir ]] && echo yes || echo no)" \
  419. --build-arg SUFFIX="${SUFFIX}" \
  420. --build-arg EXTRA_DEPS="${EXTRA_DEPS}" \
  421. --build-arg PKG_VSN="${PKG_VSN}" \
  422. --file "${EMQX_DOCKERFILE}" \
  423. --label org.opencontainers.image.title="${PROFILE%%-elixir}" \
  424. --label org.opencontainers.image.edition="${EDITION}" \
  425. --label org.opencontainers.image.version="${PKG_VSN}" \
  426. --label org.opencontainers.image.revision="${GIT_REVISION}" \
  427. --label org.opencontainers.image.created="${ISO_8601_DATE}" \
  428. --label org.opencontainers.image.source='https://github.com/emqx/emqx' \
  429. --label org.opencontainers.image.url="${PRODUCT_URL}" \
  430. --label org.opencontainers.image.description="${PRODUCT_DESCRIPTION}" \
  431. --label org.opencontainers.image.documentation="${DOCUMENTATION_URL}" \
  432. --label org.opencontainers.image.licenses="${LICENSE}" \
  433. --label org.opencontainers.image.otp.version="${EMQX_BUILDER_OTP}" \
  434. --pull
  435. )
  436. :> ./.emqx_docker_image_tags
  437. for r in "${DOCKER_REGISTRIES[@]}"; do
  438. DOCKER_BUILDX_ARGS+=(--tag "$r/${EMQX_IMAGE_TAG}")
  439. echo "$r/${EMQX_IMAGE_TAG}" >> ./.emqx_docker_image_tags
  440. done
  441. if [ "${DOCKER_BUILD_NOCACHE:-false}" = true ]; then
  442. DOCKER_BUILDX_ARGS+=(--no-cache)
  443. fi
  444. if [ "${SUFFIX}" = '-elixir' ]; then
  445. DOCKER_BUILDX_ARGS+=(--label org.opencontainers.image.elixir.version="${EMQX_BUILDER_ELIXIR}")
  446. fi
  447. if [ "${DOCKER_LATEST:-false}" = true ]; then
  448. for r in "${DOCKER_REGISTRIES[@]}"; do
  449. DOCKER_BUILDX_ARGS+=(--tag "$r/${EMQX_BASE_DOCKER_TAG}:latest${SUFFIX}")
  450. echo "$r/${EMQX_BASE_DOCKER_TAG}:latest${SUFFIX}" >> ./.emqx_docker_image_tags
  451. DOCKER_BUILDX_ARGS+=(--tag "$r/${EMQX_BASE_DOCKER_TAG}:${VSN_MAJOR}.${VSN_MINOR}${SUFFIX}")
  452. echo "$r/${EMQX_BASE_DOCKER_TAG}:${VSN_MAJOR}.${VSN_MINOR}${SUFFIX}" >> ./.emqx_docker_image_tags
  453. DOCKER_BUILDX_ARGS+=(--tag "$r/${EMQX_BASE_DOCKER_TAG}:${VSN_MAJOR}.${VSN_MINOR}.${VSN_PATCH}${SUFFIX}")
  454. echo "$r/${EMQX_BASE_DOCKER_TAG}:${VSN_MAJOR}.${VSN_MINOR}.${VSN_PATCH}${SUFFIX}" >> ./.emqx_docker_image_tags
  455. done
  456. fi
  457. if [ "${DOCKER_PLATFORMS:-default}" != 'default' ]; then
  458. DOCKER_BUILDX_ARGS+=(--platform "${DOCKER_PLATFORMS}")
  459. fi
  460. if [ "${DOCKER_PUSH:-false}" = true ]; then
  461. DOCKER_BUILDX_ARGS+=(--push)
  462. fi
  463. if [ "${DOCKER_LOAD:-true}" = true ]; then
  464. DOCKER_BUILDX_ARGS+=(--load)
  465. fi
  466. if [ -d "${REBAR_GIT_CACHE_DIR:-}" ]; then
  467. cache_tar="$(pwd)/rebar-git-cache.tar"
  468. if [ ! -f "${cache_tar}" ]; then
  469. pushd "${REBAR_GIT_CACHE_DIR}" >/dev/null
  470. tar -cf "${cache_tar}" .
  471. popd >/dev/null
  472. fi
  473. fi
  474. if [ -n "${DEBUG:-}" ]; then
  475. DOCKER_BUILDX_ARGS+=(--build-arg DEBUG="${DEBUG}" --progress=plain)
  476. fi
  477. # shellcheck disable=SC2015
  478. [ -f ./.dockerignore ] && mv ./.dockerignore ./.dockerignore.bak || true
  479. trap docker_cleanup EXIT
  480. {
  481. echo '_build/'
  482. echo 'deps/'
  483. echo '*.lock'
  484. echo '_packages/'
  485. echo '.vs/'
  486. echo '.vscode/'
  487. echo 'lux_logs/'
  488. echo '_upgrade_base/'
  489. } >> ./.dockerignore
  490. echo "Docker buildx args: ${DOCKER_BUILDX_ARGS[*]}"
  491. docker buildx build "${DOCKER_BUILDX_ARGS[@]}" .
  492. }
  493. function join {
  494. local IFS="$1"
  495. shift
  496. echo "$*"
  497. }
  498. # used to control the Elixir Mix Release output
  499. # see docstring in `mix.exs`
  500. export_elixir_release_vars() {
  501. local profile="$1"
  502. case "$profile" in
  503. emqx|emqx-enterprise)
  504. export ELIXIR_MAKE_TAR=${ELIXIR_MAKE_TAR:-no}
  505. ;;
  506. emqx-pkg|emqx-enterprise-pkg)
  507. export ELIXIR_MAKE_TAR=${ELIXIR_MAKE_TAR:-yes}
  508. ;;
  509. *)
  510. echo Invalid profile "$profile"
  511. exit 1
  512. esac
  513. export MIX_ENV="$profile"
  514. }
  515. log "building artifact=$ARTIFACT for profile=$PROFILE"
  516. case "$ARTIFACT" in
  517. apps)
  518. if [ "${IS_ELIXIR:-}" = "yes" ]; then
  519. just_compile_elixir
  520. else
  521. just_compile
  522. fi
  523. ;;
  524. doc|docs)
  525. make_docs
  526. ;;
  527. rel)
  528. make_rel release
  529. ;;
  530. relup)
  531. make_relup
  532. ;;
  533. tgz)
  534. make_tgz
  535. ;;
  536. pkg)
  537. # this only affect build artifacts, such as schema doc
  538. export EMQX_ETC_DIR='/etc/emqx/'
  539. if [ -z "${PKGERDIR:-}" ]; then
  540. log "Skipped making deb/rpm package for $SYSTEM"
  541. exit 0
  542. fi
  543. export EMQX_REL_FORM="$PKGERDIR"
  544. if [ "${IS_ELIXIR:-}" = 'yes' ]; then
  545. make_elixir_rel
  546. else
  547. make_rel tar
  548. fi
  549. env EMQX_REL="$(pwd)" \
  550. EMQX_BUILD="${PROFILE}" \
  551. make -C "deploy/packages/${PKGERDIR}" clean
  552. env EMQX_REL="$(pwd)" \
  553. EMQX_BUILD="${PROFILE}" \
  554. make -C "deploy/packages/${PKGERDIR}"
  555. ;;
  556. docker)
  557. make_docker
  558. ;;
  559. elixir)
  560. make_elixir_rel
  561. ;;
  562. *)
  563. log "Unknown artifact $ARTIFACT"
  564. exit 1
  565. ;;
  566. esac