build 18 KB

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