build 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580
  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 due to jq command missing."
  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 local.hex 2.0.6 --if-missing --force
  171. env MIX_ENV="$PROFILE" mix deps.get
  172. env MIX_ENV="$PROFILE" mix compile
  173. }
  174. make_rel() {
  175. local release_or_tar="${1}"
  176. just_compile
  177. # now assemble the release tar
  178. ./rebar3 as "$PROFILE" "$release_or_tar"
  179. assert_no_excluded_deps emqx-enterprise emqx_telemetry
  180. }
  181. make_elixir_rel() {
  182. ./scripts/pre-compile.sh "$PROFILE"
  183. export_elixir_release_vars "$PROFILE"
  184. env MIX_ENV="$PROFILE" mix local.rebar --if-missing --force
  185. env MIX_ENV="$PROFILE" mix local.rebar rebar3 "${PWD}/rebar3" --if-missing --force
  186. # env MIX_ENV="$PROFILE" mix local.hex --if-missing --force
  187. env MIX_ENV="$PROFILE" mix local.hex 2.0.6 --if-missing --force
  188. env MIX_ENV="$PROFILE" mix deps.get
  189. env MIX_ENV="$PROFILE" mix release --overwrite
  190. assert_no_excluded_deps emqx-enterprise emqx_telemetry
  191. }
  192. make_relup() {
  193. RELUP_TARGET_VSN="$(./pkg-vsn.sh "$PROFILE" --long)"
  194. export RELUP_TARGET_VSN
  195. ./rebar3 emqx relup_gen --relup-dir=./rel/relup
  196. make rel -C _build/default/plugins/emqx_relup
  197. }
  198. cp_dyn_libs() {
  199. local rel_dir="$1"
  200. local target_dir="${rel_dir}/dynlibs"
  201. if ! [ "$(uname -s)" = 'Linux' ]; then
  202. return 0;
  203. fi
  204. mkdir -p "$target_dir"
  205. while read -r so_file; do
  206. cp -L "$so_file" "$target_dir/"
  207. done < <("$FIND" "$rel_dir" -type f \( -name "*.so*" -o -name "beam.smp" \) -print0 \
  208. | xargs -0 ldd \
  209. | grep -E '(libcrypto)|(libtinfo)|(libatomic)' \
  210. | awk '{print $3}' \
  211. | sort -u)
  212. }
  213. ## Re-pack the relx assembled .tar.gz to EMQX's package naming scheme
  214. ## It assumes the .tar.gz has been built -- relies on Makefile dependency
  215. make_tgz() {
  216. local pkgpath="_packages/${PROFILE}"
  217. local src_tarball
  218. local target_name
  219. local target
  220. if [ "${IS_ELIXIR:-no}" = "yes" ]
  221. then
  222. # ensure src_tarball exists
  223. ELIXIR_MAKE_TAR=yes make_elixir_rel
  224. local relpath="_build/${PROFILE}"
  225. full_vsn="$(./pkg-vsn.sh "$PROFILE" --long --elixir)"
  226. else
  227. # build the src_tarball again to ensure relup is included
  228. # elixir does not have relup yet.
  229. make_rel tar
  230. local relpath="_build/${PROFILE}/rel/emqx"
  231. full_vsn="$(./pkg-vsn.sh "$PROFILE" --long)"
  232. fi
  233. case "$SYSTEM" in
  234. macos*)
  235. target_name="${PROFILE}-${full_vsn}.zip"
  236. ;;
  237. windows*)
  238. target_name="${PROFILE}-${full_vsn}.zip"
  239. ;;
  240. *)
  241. target_name="${PROFILE}-${full_vsn}.tar.gz"
  242. ;;
  243. esac
  244. target="${pkgpath}/${target_name}"
  245. src_tarball="${relpath}/emqx-${PKG_VSN}.tar.gz"
  246. tard="$(mktemp -d -t emqx.XXXXXXX)"
  247. mkdir -p "${tard}/emqx"
  248. mkdir -p "${pkgpath}"
  249. if [ ! -f "$src_tarball" ]; then
  250. log_red "ERROR: $src_tarball is not found"
  251. fi
  252. $TAR zxf "${src_tarball}" -C "${tard}/emqx"
  253. if [ -f "${tard}/emqx/releases/${PKG_VSN}/relup" ]; then
  254. ./scripts/relup-build/inject-relup.escript "${tard}/emqx/releases/${PKG_VSN}/relup"
  255. fi
  256. ## try to be portable for tar.gz packages.
  257. ## for DEB and RPM packages the dependencies are resoved by yum and apt
  258. cp_dyn_libs "${tard}/emqx"
  259. case "$SYSTEM" in
  260. macos*)
  261. # if the flag to sign macos binaries is set, but developer certificate
  262. # or certificate password is not configured, reset the flag
  263. # could happen, for example, when people submit PR from a fork, in this
  264. # case they cannot access secrets
  265. if [[ "${APPLE_SIGN_BINARIES:-0}" == 1 && \
  266. ( "${APPLE_DEVELOPER_ID_BUNDLE:-0}" == 0 || \
  267. "${APPLE_DEVELOPER_ID_BUNDLE_PASSWORD:-0}" == 0 ) ]]; then
  268. echo "Apple developer certificate is not configured, skip signing"
  269. APPLE_SIGN_BINARIES=0
  270. fi
  271. if [ "${APPLE_SIGN_BINARIES:-0}" = 1 ]; then
  272. ./scripts/macos-sign-binaries.sh "${tard}/emqx"
  273. fi
  274. ## create zip after change dir
  275. ## to avoid creating an extra level of 'emqx' dir in the .zip file
  276. pushd "${tard}/emqx" >/dev/null
  277. zip -r "../${target_name}" -- * >/dev/null
  278. popd >/dev/null
  279. mv "${tard}/${target_name}" "${target}"
  280. if [ "${APPLE_SIGN_BINARIES:-0}" = 1 ]; then
  281. # notarize the package
  282. # if fails, check what went wrong with this command:
  283. # xcrun notarytool log \
  284. # --apple-id <apple id> \
  285. # --password <apple id password>
  286. # --team-id <apple team id> <submission-id>
  287. echo 'Submitting the package for notarization to Apple (normally takes about a minute)'
  288. notarytool_output="$(xcrun notarytool submit \
  289. --apple-id "${APPLE_ID}" \
  290. --password "${APPLE_ID_PASSWORD}" \
  291. --team-id "${APPLE_TEAM_ID}" "${target}" \
  292. --no-progress \
  293. --wait)"
  294. echo "$notarytool_output"
  295. echo "$notarytool_output" | grep -q 'status: Accepted' || {
  296. echo 'Notarization failed';
  297. exit 1;
  298. }
  299. fi
  300. # sha256sum may not be available on macos
  301. openssl dgst -sha256 "${target}" | cut -d ' ' -f 2 > "${target}.sha256"
  302. ;;
  303. windows*)
  304. pushd "${tard}" >/dev/null
  305. 7z a "${target_name}" ./emqx/* >/dev/null
  306. popd >/dev/null
  307. mv "${tard}/${target_name}" "${target}"
  308. sha256sum "${target}" | head -c 64 > "${target}.sha256"
  309. ;;
  310. *)
  311. ## create tar after change dir
  312. ## to avoid creating an extra level of 'emqx' dir in the .tar.gz file
  313. pushd "${tard}/emqx" >/dev/null
  314. $TAR -zcf "../${target_name}" -- *
  315. popd >/dev/null
  316. mv "${tard}/${target_name}" "${target}"
  317. sha256sum "${target}" | head -c 64 > "${target}.sha256"
  318. ;;
  319. esac
  320. log "Archive successfully repacked: ${target}"
  321. log "Archive sha256sum: $(cat "${target}.sha256")"
  322. }
  323. docker_cleanup() {
  324. rm -f ./.dockerignore >/dev/null
  325. # shellcheck disable=SC2015
  326. [ -f ./.dockerignore.bak ] && mv ./.dockerignore.bak ./.dockerignore >/dev/null || true
  327. }
  328. function is_ecr_and_enterprise() {
  329. local registry="$1"
  330. local profile="$2"
  331. if [[ "$registry" == public.ecr.aws* ]] && [[ "$profile" == *enterprise* ]]; then
  332. return 0
  333. else
  334. return 1
  335. fi
  336. }
  337. ## Build the default docker image based on debian 12.
  338. make_docker() {
  339. # shellcheck disable=SC1091
  340. source ./env.sh
  341. local BUILD_FROM="${BUILD_FROM:-${EMQX_DOCKER_BUILD_FROM}}"
  342. # shellcheck disable=SC2155
  343. local OTP_VSN="$(docker run --rm "${BUILD_FROM}" erl -eval '{ok, Version} = file:read_file(filename:join([code:root_dir(), "releases", erlang:system_info(otp_release), "OTP_VERSION"])), io:fwrite(Version), halt().' -noshell)"
  344. # shellcheck disable=SC2155
  345. local ELIXIR_VSN="$(docker run --rm "${BUILD_FROM}" elixir --short-version)"
  346. local RUN_FROM="${RUN_FROM:-${EMQX_DOCKER_RUN_FROM}}"
  347. local EMQX_DOCKERFILE="${EMQX_DOCKERFILE:-deploy/docker/Dockerfile}"
  348. local EMQX_SOURCE_TYPE="${EMQX_SOURCE_TYPE:-src}"
  349. # shellcheck disable=SC2155
  350. local VSN_MAJOR="$(scripts/semver.sh "$PKG_VSN" --major)"
  351. # shellcheck disable=SC2155
  352. local VSN_MINOR="$(scripts/semver.sh "$PKG_VSN" --minor)"
  353. # shellcheck disable=SC2155
  354. local VSN_PATCH="$(scripts/semver.sh "$PKG_VSN" --patch)"
  355. local SUFFIX=''
  356. if [[ "$PROFILE" = *-elixir ]]; then
  357. SUFFIX="-elixir"
  358. fi
  359. local DOCKER_REGISTRY="${DOCKER_REGISTRY:-docker.io}"
  360. local DOCKER_REGISTRIES=( )
  361. IFS=',' read -ra DOCKER_REGISTRY_ARR <<< "$DOCKER_REGISTRY"
  362. for r in "${DOCKER_REGISTRY_ARR[@]}"; do
  363. # append to DOCKER_REGISTRIES
  364. DOCKER_REGISTRIES+=("$r")
  365. done
  366. local DOCKER_ORG="${DOCKER_ORG:-emqx}"
  367. local EMQX_BASE_DOCKER_TAG="${DOCKER_ORG}/${PROFILE%%-elixir}"
  368. local default_tag="${EMQX_BASE_DOCKER_TAG}:${PKG_VSN}${SUFFIX}"
  369. local EMQX_IMAGE_TAG="${EMQX_IMAGE_TAG:-$default_tag}"
  370. local EDITION=Opensource
  371. local LICENSE='Apache-2.0'
  372. local PRODUCT_URL='https://www.emqx.io'
  373. local PRODUCT_DESCRIPTION='Official docker image for EMQX, the most scalable open-source MQTT broker for IoT, IIoT, and connected vehicles.'
  374. local DOCUMENTATION_URL='https://www.emqx.io/docs/en/latest/'
  375. ## extra_deps is a comma separated list of debian 12 package names
  376. local EXTRA_DEPS=''
  377. if [[ "$PROFILE" = *enterprise* ]]; then
  378. EXTRA_DEPS='libsasl2-2,libsasl2-modules-gssapi-mit'
  379. EDITION=Enterprise
  380. LICENSE='(Apache-2.0 AND BSL-1.1)'
  381. PRODUCT_URL='https://www.emqx.com/en/products/emqx'
  382. PRODUCT_DESCRIPTION='Official docker image for EMQX Enterprise, an enterprise MQTT platform at scale. '
  383. DOCUMENTATION_URL='https://docs.emqx.com/en/enterprise/latest/'
  384. fi
  385. local ISO_8601_DATE GIT_REVISION
  386. ISO_8601_DATE="$(date -u +"%Y-%m-%dT%H:%M:%SZ")"
  387. GIT_REVISION="$(git rev-parse HEAD)"
  388. export BUILDX_NO_DEFAULT_ATTESTATIONS=1
  389. local DOCKER_BUILDX_ARGS=(
  390. --build-arg BUILD_FROM="${BUILD_FROM}" \
  391. --build-arg RUN_FROM="${RUN_FROM}" \
  392. --build-arg SOURCE_TYPE="${EMQX_SOURCE_TYPE}" \
  393. --build-arg PROFILE="${PROFILE%%-elixir}" \
  394. --build-arg IS_ELIXIR="$([[ "$PROFILE" = *-elixir ]] && echo yes || echo no)" \
  395. --build-arg SUFFIX="${SUFFIX}" \
  396. --build-arg EXTRA_DEPS="${EXTRA_DEPS}" \
  397. --build-arg PKG_VSN="${PKG_VSN}" \
  398. --file "${EMQX_DOCKERFILE}" \
  399. --label org.opencontainers.image.title="${PROFILE%%-elixir}" \
  400. --label org.opencontainers.image.edition="${EDITION}" \
  401. --label org.opencontainers.image.version="${PKG_VSN}" \
  402. --label org.opencontainers.image.revision="${GIT_REVISION}" \
  403. --label org.opencontainers.image.created="${ISO_8601_DATE}" \
  404. --label org.opencontainers.image.source='https://github.com/emqx/emqx' \
  405. --label org.opencontainers.image.url="${PRODUCT_URL}" \
  406. --label org.opencontainers.image.description="${PRODUCT_DESCRIPTION}" \
  407. --label org.opencontainers.image.documentation="${DOCUMENTATION_URL}" \
  408. --label org.opencontainers.image.licenses="${LICENSE}" \
  409. --label org.opencontainers.image.otp.version="${OTP_VSN}" \
  410. --pull
  411. )
  412. :> ./.emqx_docker_image_tags
  413. for r in "${DOCKER_REGISTRIES[@]}"; do
  414. DOCKER_BUILDX_ARGS+=(--tag "$r/${EMQX_IMAGE_TAG}")
  415. echo "$r/${EMQX_IMAGE_TAG}" >> ./.emqx_docker_image_tags
  416. done
  417. if [ "${DOCKER_BUILD_NOCACHE:-false}" = true ]; then
  418. DOCKER_BUILDX_ARGS+=(--no-cache)
  419. fi
  420. if [ "${SUFFIX}" = '-elixir' ]; then
  421. DOCKER_BUILDX_ARGS+=(--label org.opencontainers.image.elixir.version="${ELIXIR_VSN}")
  422. fi
  423. if [ "${DOCKER_LATEST:-false}" = true ]; then
  424. for r in "${DOCKER_REGISTRIES[@]}"; do
  425. DOCKER_BUILDX_ARGS+=(--tag "$r/${EMQX_BASE_DOCKER_TAG}:latest${SUFFIX}")
  426. echo "$r/${EMQX_BASE_DOCKER_TAG}:latest${SUFFIX}" >> ./.emqx_docker_image_tags
  427. DOCKER_BUILDX_ARGS+=(--tag "$r/${EMQX_BASE_DOCKER_TAG}:${VSN_MAJOR}.${VSN_MINOR}${SUFFIX}")
  428. echo "$r/${EMQX_BASE_DOCKER_TAG}:${VSN_MAJOR}.${VSN_MINOR}${SUFFIX}" >> ./.emqx_docker_image_tags
  429. DOCKER_BUILDX_ARGS+=(--tag "$r/${EMQX_BASE_DOCKER_TAG}:${VSN_MAJOR}.${VSN_MINOR}.${VSN_PATCH}${SUFFIX}")
  430. echo "$r/${EMQX_BASE_DOCKER_TAG}:${VSN_MAJOR}.${VSN_MINOR}.${VSN_PATCH}${SUFFIX}" >> ./.emqx_docker_image_tags
  431. done
  432. fi
  433. if [ "${DOCKER_PLATFORMS:-default}" != 'default' ]; then
  434. DOCKER_BUILDX_ARGS+=(--platform "${DOCKER_PLATFORMS}")
  435. fi
  436. if [ "${DOCKER_PUSH:-false}" = true ]; then
  437. DOCKER_BUILDX_ARGS+=(--push)
  438. fi
  439. if [ "${DOCKER_LOAD:-true}" = true ]; then
  440. DOCKER_BUILDX_ARGS+=(--load)
  441. fi
  442. if [ -d "${REBAR_GIT_CACHE_DIR:-}" ]; then
  443. cache_tar="$(pwd)/rebar-git-cache.tar"
  444. if [ ! -f "${cache_tar}" ]; then
  445. pushd "${REBAR_GIT_CACHE_DIR}" >/dev/null
  446. tar -cf "${cache_tar}" .
  447. popd >/dev/null
  448. fi
  449. fi
  450. if [ -n "${DEBUG:-}" ]; then
  451. DOCKER_BUILDX_ARGS+=(--build-arg DEBUG="${DEBUG}" --progress=plain)
  452. fi
  453. # shellcheck disable=SC2015
  454. [ -f ./.dockerignore ] && mv ./.dockerignore ./.dockerignore.bak || true
  455. trap docker_cleanup EXIT
  456. {
  457. echo '_build/'
  458. echo 'deps/'
  459. echo '*.lock'
  460. echo '_packages/'
  461. echo '.vs/'
  462. echo '.vscode/'
  463. echo 'lux_logs/'
  464. echo '_upgrade_base/'
  465. } >> ./.dockerignore
  466. echo "Docker buildx args: ${DOCKER_BUILDX_ARGS[*]}"
  467. docker buildx build "${DOCKER_BUILDX_ARGS[@]}" .
  468. }
  469. function join {
  470. local IFS="$1"
  471. shift
  472. echo "$*"
  473. }
  474. # used to control the Elixir Mix Release output
  475. # see docstring in `mix.exs`
  476. export_elixir_release_vars() {
  477. local profile="$1"
  478. case "$profile" in
  479. emqx|emqx-enterprise)
  480. export ELIXIR_MAKE_TAR=${ELIXIR_MAKE_TAR:-no}
  481. ;;
  482. emqx-pkg|emqx-enterprise-pkg)
  483. export ELIXIR_MAKE_TAR=${ELIXIR_MAKE_TAR:-yes}
  484. ;;
  485. *)
  486. echo Invalid profile "$profile"
  487. exit 1
  488. esac
  489. export MIX_ENV="$profile"
  490. }
  491. log "building artifact=$ARTIFACT for profile=$PROFILE"
  492. case "$ARTIFACT" in
  493. apps)
  494. if [ "${IS_ELIXIR:-}" = "yes" ]; then
  495. just_compile_elixir
  496. else
  497. just_compile
  498. fi
  499. ;;
  500. doc|docs)
  501. make_docs
  502. ;;
  503. rel)
  504. make_rel release
  505. ;;
  506. relup)
  507. make_relup
  508. ;;
  509. tgz)
  510. make_tgz
  511. ;;
  512. pkg)
  513. # this only affect build artifacts, such as schema doc
  514. export EMQX_ETC_DIR='/etc/emqx/'
  515. if [ -z "${PKGERDIR:-}" ]; then
  516. log "Skipped making deb/rpm package for $SYSTEM"
  517. exit 0
  518. fi
  519. export EMQX_REL_FORM="$PKGERDIR"
  520. if [ "${IS_ELIXIR:-}" = 'yes' ]; then
  521. make_elixir_rel
  522. else
  523. make_rel tar
  524. fi
  525. env EMQX_REL="$(pwd)" \
  526. EMQX_BUILD="${PROFILE}" \
  527. make -C "deploy/packages/${PKGERDIR}" clean
  528. env EMQX_REL="$(pwd)" \
  529. EMQX_BUILD="${PROFILE}" \
  530. make -C "deploy/packages/${PKGERDIR}"
  531. ;;
  532. docker)
  533. make_docker
  534. ;;
  535. elixir)
  536. make_elixir_rel
  537. ;;
  538. *)
  539. log "Unknown artifact $ARTIFACT"
  540. exit 1
  541. ;;
  542. esac