From 391e4808242d886c9ddef695d0f6866b149b2d65 Mon Sep 17 00:00:00 2001 From: "Zaiming (Stone) Shi" Date: Tue, 25 Jan 2022 10:12:01 +0100 Subject: [PATCH] build: parameterise package version so that community and enterprise edition can be built from the same branch --- .github/workflows/build_slim_packages.yaml | 2 +- .github/workflows/run_fvt_tests.yaml | 2 +- .github/workflows/run_relup_tests.yaml | 2 +- Makefile | 1 - apps/emqx/include/emqx_release.hrl | 8 ++- apps/emqx/src/emqx_release.erl | 12 +++- build | 2 +- pkg-vsn.sh | 15 +++- rebar.config.erl | 83 ++++++++++++---------- scripts/buildx.sh | 2 +- 10 files changed, 78 insertions(+), 51 deletions(-) diff --git a/.github/workflows/build_slim_packages.yaml b/.github/workflows/build_slim_packages.yaml index 1694c177a..fc4a2d8f5 100644 --- a/.github/workflows/build_slim_packages.yaml +++ b/.github/workflows/build_slim_packages.yaml @@ -47,7 +47,7 @@ jobs: run: | echo "EMQX_NAME=${{ matrix.profile }}" >> $GITHUB_ENV echo "CODE_PATH=$GITHUB_WORKSPACE" >> $GITHUB_ENV - echo "EMQX_PKG_NAME=${{ matrix.profile }}-$(./pkg-vsn.sh)-otp${{ matrix.otp }}-${{ matrix.os }}-amd64" >> $GITHUB_ENV + echo "EMQX_PKG_NAME=${{ matrix.profile }}-$(./pkg-vsn.sh ${{ matrix.profile }})-otp${{ matrix.otp }}-${{ matrix.os }}-amd64" >> $GITHUB_ENV - name: Get deps git refs for cache id: deps-refs run: | diff --git a/.github/workflows/run_fvt_tests.yaml b/.github/workflows/run_fvt_tests.yaml index 9b04ffd7b..9c7ee7184 100644 --- a/.github/workflows/run_fvt_tests.yaml +++ b/.github/workflows/run_fvt_tests.yaml @@ -90,7 +90,7 @@ jobs: working-directory: source run: | set -x - IMAGE=emqx/${{ matrix.profile }}:$(./pkg-vsn.sh) + IMAGE=emqx/${{ matrix.profile }}:$(./pkg-vsn.sh ${{ matrix.profile }}) ./.ci/docker-compose-file/scripts/run-emqx.sh $IMAGE ${{ matrix.cluster_db_backend }} - name: make paho tests run: | diff --git a/.github/workflows/run_relup_tests.yaml b/.github/workflows/run_relup_tests.yaml index 630130156..0af50f599 100644 --- a/.github/workflows/run_relup_tests.yaml +++ b/.github/workflows/run_relup_tests.yaml @@ -76,7 +76,7 @@ jobs: fi echo "BROKER=$broker" >> $GITHUB_ENV - vsn="$(./pkg-vsn.sh)" + vsn="$(./pkg-vsn.sh $PROFILE)" echo "VSN=$vsn" >> $GITHUB_ENV pre_vsn="$(echo $vsn | grep -oE '^[0-9]+.[0-9]')" diff --git a/Makefile b/Makefile index d82bcdb7c..07a9ff419 100644 --- a/Makefile +++ b/Makefile @@ -6,7 +6,6 @@ SCRIPTS = $(CURDIR)/scripts export EMQX_DEFAULT_BUILDER = ghcr.io/emqx/emqx-builder/4.4-2:23.3.4.9-3-alpine3.14 export EMQX_DEFAULT_RUNNER = alpine:3.14 export OTP_VSN ?= $(shell $(CURDIR)/scripts/get-otp-vsn.sh) -export PKG_VSN ?= $(shell $(CURDIR)/pkg-vsn.sh) export EMQX_DASHBOARD_VERSION ?= v0.18.0 export DOCKERFILE := deploy/docker/Dockerfile export DOCKERFILE_TESTING := deploy/docker/Dockerfile.testing diff --git a/apps/emqx/include/emqx_release.hrl b/apps/emqx/include/emqx_release.hrl index ce70cc172..54db4ea73 100644 --- a/apps/emqx/include/emqx_release.hrl +++ b/apps/emqx/include/emqx_release.hrl @@ -17,7 +17,7 @@ %% NOTE: this is the release version which is not always the same %% as the emqx app version defined in emqx.app.src %% App (plugin) versions are bumped independently. -%% e.g. EMQX_RELEASE being 4.3.1 does no always imply emqx app +%% e.g. EMQX_RELEASE_CE being 4.3.1 does no always imply emqx app %% should be 4.3.1, as it might be the case that only one of the %% plugins had a bug to fix. So for a hot beam upgrade, only the app %% with beam files changed needs an upgrade. @@ -28,4 +28,8 @@ %% (Major.Minor.Patch), and extra info can be added after a final %% hyphen. --define(EMQX_RELEASE, "5.0.0-beta.3"). +%% Community edition +-define(EMQX_RELEASE_CE, "5.0.0-beta.3"). + +%% Enterprise edition +-define(EMQX_RELEASE_EE, "5.0.0-alpha.1"). diff --git a/apps/emqx/src/emqx_release.erl b/apps/emqx/src/emqx_release.erl index 31466dc8f..e09decde9 100644 --- a/apps/emqx/src/emqx_release.erl +++ b/apps/emqx/src/emqx_release.erl @@ -70,10 +70,10 @@ edition(Desc) -> %% @doc Return the release version. version() -> case lists:keyfind(emqx_vsn, 1, ?MODULE:module_info(compile)) of - false -> %% For TEST build or depedency build. - ?EMQX_RELEASE; + false -> %% For TEST build or depedency build. + build_vsn(); {_, Vsn} -> %% For emqx release build - VsnStr = ?EMQX_RELEASE, + VsnStr = build_vsn(), case string:str(Vsn, VsnStr) of 1 -> ok; _ -> @@ -84,3 +84,9 @@ version() -> end, Vsn end. + +build_vsn() -> + case edition() of + ee -> ?EMQX_RELEASE_EE; + _ -> ?EMQX_RELEASE_CE + end. diff --git a/build b/build index b6bd62cbc..6a0a2dc7d 100755 --- a/build +++ b/build @@ -12,7 +12,7 @@ ARTIFACT="$2" # ensure dir cd -P -- "$(dirname -- "${BASH_SOURCE[0]}")" -PKG_VSN="${PKG_VSN:-$(./pkg-vsn.sh)}" +PKG_VSN="${PKG_VSN:-$(./pkg-vsn.sh $PROFILE)}" export PKG_VSN SYSTEM="$(./scripts/get-distro.sh)" diff --git a/pkg-vsn.sh b/pkg-vsn.sh index 0f16c7809..2ba9fc606 100755 --- a/pkg-vsn.sh +++ b/pkg-vsn.sh @@ -6,12 +6,23 @@ set -euo pipefail # ensure dir cd -P -- "$(dirname -- "$0")" +case "${1:-}" in + *enterprise*) + RELEASE_EDITION="EMQX_RELEASE_EE" + GIT_TAG_PREFIX="e" + ;; + *) + RELEASE_EDITION="EMQX_RELEASE_CE" + GIT_TAG_PREFIX="v" + ;; +esac + ## emqx_release.hrl is the single source of truth for release version -RELEASE="$(grep -E "define.+EMQX_RELEASE" apps/emqx/include/emqx_release.hrl | cut -d '"' -f2)" +RELEASE="$(grep -E "define.+${RELEASE_EDITION}" apps/emqx/include/emqx_release.hrl | cut -d '"' -f2)" git_exact_vsn() { local tag - tag="$(git describe --tags --match "[e|v]*" --exact 2>/dev/null)" + tag="$(git describe --tags --match "${GIT_TAG_PREFIX}*" --exact 2>/dev/null)" echo "${tag//^[v|e]/}" } diff --git a/rebar.config.erl b/rebar.config.erl index e0f5c38a5..7eb416922 100644 --- a/rebar.config.erl +++ b/rebar.config.erl @@ -25,8 +25,7 @@ deps(Config) -> lists:keystore(deps, 1, Config, {deps, OldDeps ++ MoreDeps}). overrides() -> - [ {add, [ {extra_src_dirs, [{"etc", [{recursive,true}]}]} - , {erl_opts, [{compile_info, [{emqx_vsn, get_vsn()}]}]} + [ {add, [ {extra_src_dirs, [{"etc", [{recursive, true}]}]} ]} ] ++ snabbkaffe_overrides(). @@ -99,75 +98,87 @@ test_deps() -> , {proper, "1.4.0"} ]. -common_compile_opts() -> +common_compile_opts(Vsn) -> [ debug_info % alwyas include debug_info - , {compile_info, [{emqx_vsn, get_vsn()}]} + , {compile_info, [{emqx_vsn, Vsn}]} ] ++ [{d, 'EMQX_BENCHMARK'} || os:getenv("EMQX_BENCHMARK") =:= "1" ]. -prod_compile_opts() -> +prod_compile_opts(Vsn) -> [ compressed , deterministic , warnings_as_errors - | common_compile_opts() + | common_compile_opts(Vsn) ]. prod_overrides() -> [{add, [ {erl_opts, [deterministic]}]}]. profiles() -> - Vsn = get_vsn(), + profiles_ce() ++ profiles_ee() ++ profiles_dev(). + +profiles_ce() -> + Vsn = get_vsn(emqx), [ {'emqx', - [ {erl_opts, prod_compile_opts()} + [ {erl_opts, prod_compile_opts(Vsn)} , {relx, relx(Vsn, cloud, bin, ce)} , {overrides, prod_overrides()} , {project_app_dirs, project_app_dirs(ce)} , {post_hooks, [{compile, "bash build emqx doc"}]} ]} , {'emqx-pkg', - [ {erl_opts, prod_compile_opts()} + [ {erl_opts, prod_compile_opts(Vsn)} , {relx, relx(Vsn, cloud, pkg, ce)} , {overrides, prod_overrides()} , {project_app_dirs, project_app_dirs(ce)} , {post_hooks, [{compile, "bash build emqx-pkg doc"}]} ]} - , {'emqx-enterprise', - [ {erl_opts, prod_compile_opts()} - , {relx, relx(Vsn, cloud, bin, ee)} - , {overrides, prod_overrides()} - , {project_app_dirs, project_app_dirs(ee)} - , {post_hooks, [{compile, "bash build emqx-enterprise doc"}]} - ]} - , {'emqx-enterprise-pkg', - [ {erl_opts, prod_compile_opts()} - , {relx, relx(Vsn, cloud, pkg, ee)} - , {overrides, prod_overrides()} - , {project_app_dirs, project_app_dirs(ee)} - , {post_hooks, [{compile, "bash build emqx-enterprise-pkg doc"}]} - ]} , {'emqx-edge', - [ {erl_opts, prod_compile_opts()} + [ {erl_opts, prod_compile_opts(Vsn)} , {relx, relx(Vsn, edge, bin, ce)} , {overrides, prod_overrides()} , {project_app_dirs, project_app_dirs(ce)} , {post_hooks, [{compile, "bash build emqx-edge doc"}]} ]} , {'emqx-edge-pkg', - [ {erl_opts, prod_compile_opts()} + [ {erl_opts, prod_compile_opts(Vsn)} , {relx, relx(Vsn, edge, pkg, ce)} , {overrides, prod_overrides()} , {project_app_dirs, project_app_dirs(ce)} , {post_hooks, [{compile, "bash build emqx-edge-pkg doc"}]} ]} - , {check, - [ {erl_opts, common_compile_opts()} - , {project_app_dirs, project_app_dirs(ce)} + ]. + +profiles_ee() -> + Vsn = get_vsn('emqx-enterprise'), + [ {'emqx-enterprise', + [ {erl_opts, prod_compile_opts(Vsn)} + , {relx, relx(Vsn, cloud, bin, ee)} + , {overrides, prod_overrides()} + , {project_app_dirs, project_app_dirs(ee)} + , {post_hooks, [{compile, "bash build emqx-enterprise doc"}]} + ]} + , {'emqx-enterprise-pkg', + [ {erl_opts, prod_compile_opts(Vsn)} + , {relx, relx(Vsn, cloud, pkg, ee)} + , {overrides, prod_overrides()} + , {project_app_dirs, project_app_dirs(ee)} + , {post_hooks, [{compile, "bash build emqx-enterprise-pkg doc"}]} + ]} + ]. + +%% EE has more files than CE, always test/check with EE options. +profiles_dev() -> + Vsn = get_vsn('emqx-enterprise'), + [ {check, + [ {erl_opts, common_compile_opts(Vsn)} + , {project_app_dirs, project_app_dirs(ee)} ]} , {test, [ {deps, test_deps()} - , {erl_opts, common_compile_opts() ++ erl_opts_i(ce) } + , {erl_opts, common_compile_opts(Vsn) ++ erl_opts_i()} , {extra_src_dirs, [{"test", [{recursive, true}]}]} - , {project_app_dirs, project_app_dirs(ce)} + , {project_app_dirs, project_app_dirs(ee)} ]} ]. @@ -373,11 +384,11 @@ emqx_etc_overlay_common() -> , {"{{base_dir}}/lib/emqx/etc/ssl_dist.conf", "etc/ssl_dist.conf"} ]. -get_vsn() -> +get_vsn(Profile) -> %% to make it compatible to Linux and Windows, %% we must use bash to execute the bash file %% because "./" will not be recognized as an internal or external command - PkgVsn = os:cmd("bash pkg-vsn.sh"), + PkgVsn = os:cmd("bash pkg-vsn.sh " ++ atom_to_list(Profile)), re:replace(PkgVsn, "\n", "", [{return ,list}]). maybe_dump(Config) -> @@ -399,14 +410,10 @@ provide_bcrypt_dep() -> provide_bcrypt_release(ReleaseType) -> provide_bcrypt_dep() andalso ReleaseType =:= cloud. -erl_opts_i(Edition) -> +erl_opts_i() -> [{i, "apps"}] ++ [{i, Dir} || Dir <- filelib:wildcard(filename:join(["apps", "*", "include"]))] ++ - case is_enterprise(Edition) of - true -> - [{i, Dir} || Dir <- filelib:wildcard(filename:join(["lib-ee", "*", "include"]))]; - false -> [] - end. + [{i, Dir} || Dir <- filelib:wildcard(filename:join(["lib-ee", "*", "include"]))]. dialyzer(Config) -> {dialyzer, OldDialyzerConfig} = lists:keyfind(dialyzer, 1, Config), diff --git a/scripts/buildx.sh b/scripts/buildx.sh index 1ed0fd56d..3c71426c4 100755 --- a/scripts/buildx.sh +++ b/scripts/buildx.sh @@ -70,7 +70,7 @@ fi cd "${SRC_DIR:-.}" -PKG_VSN="${PKG_VSN:-$(./pkg-vsn.sh)}" +PKG_VSN="${PKG_VSN:-$(./pkg-vsn.sh $PROFILE)}" OTP_VSN_SYSTEM=$(echo "$BUILDER" | cut -d ':' -f2) PKG_NAME="${PROFILE}-${PKG_VSN}-otp${OTP_VSN_SYSTEM}-${ARCH}"