-
Notifications
You must be signed in to change notification settings - Fork 0
/
mix.exs
1348 lines (1146 loc) · 36.7 KB
/
mix.exs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
defmodule EMQXUmbrella.MixProject do
use Mix.Project
@moduledoc """
The purpose of this file is to configure the release of EMQX under
Mix. Since EMQX uses its own configuration conventions and startup
procedures, one cannot simply use `iex -S mix`. Instead, it's
recommended to build and use the release.
## Profiles
To control the profile and edition to build, we case split on the
MIX_ENV value.
The following profiles are valid:
* `emqx`
* `emqx-enterprise`
* `emqx-pkg`
* `emqx-enterprise-pkg`
* `dev` -> same as `emqx`, for convenience
## Release Environment Variables
The release build is controlled by a few environment variables.
* `ELIXIR_MAKE_TAR` - If set to `yes`, will produce a `.tar.gz`
tarball along with the release.
"""
# TODO: remove once we switch to the new mix build
def new_mix_build?() do
System.get_env("NEW_MIX_BUILD") == "1"
end
def project() do
profile_info = check_profile!()
version = pkg_vsn()
if new_mix_build?() do
[
apps_path: "apps",
erlc_options: erlc_options(profile_info, version),
version: version,
deps: deps(profile_info, version),
releases: releases(),
aliases: aliases()
]
else
# TODO: this check and clause will be removed when we switch to using mix as the
# manager for all umbrella apps.
[
app: :emqx_mix,
erlc_options: erlc_options(profile_info, version),
version: version,
deps: deps(profile_info, version),
releases: releases(),
aliases: aliases()
]
end
end
@doc """
Please try to add dependencies that used by a single umbrella application in the
application's own `mix.exs` file, if possible. If it's shared by more than one
application, or if the dependency requires an `override: true` option, add a new clause
to `common_dep/1` so that we centralize versions in this root `mix.exs` file as much as
possible.
Here, transitive dependencies from our app dependencies should be placed when there's a
need to override them. For example, since `jsone` is a dependency to `rocketmq` and to
`erlavro`, which are both dependencies and not umbrella apps, we need to add the
override here. Also, there are cases where adding `override: true` to the umbrella
application dependency simply won't satisfy mix. In such cases, it's fine to add it
here.
"""
def deps(profile_info, version) do
# we need several overrides here because dependencies specify
# other exact versions, and not ranges.
if new_mix_build?() do
new_deps()
else
old_deps(profile_info, version)
end
end
def new_deps() do
common_deps() ++
quicer_dep() ++
jq_dep() ++
extra_release_apps() ++
overridden_deps()
end
## TODO: this should be removed once we migrate the release build to mix
defp old_deps(profile_info, version) do
rebar3_umbrella_apps = emqx_apps(profile_info, version) ++ enterprise_deps(profile_info)
common_deps() ++
extra_release_apps() ++
overridden_deps() ++
jq_dep() ++
quicer_dep() ++ rebar3_umbrella_apps
end
def overridden_deps() do
[
common_dep(:lc),
common_dep(:covertool),
common_dep(:typerefl),
common_dep(:ehttpc),
common_dep(:gproc),
common_dep(:jiffy),
common_dep(:cowboy),
common_dep(:esockd),
common_dep(:rocksdb),
common_dep(:ekka),
common_dep(:gen_rpc),
common_dep(:grpc),
common_dep(:minirest),
common_dep(:ecpool),
common_dep(:replayq),
common_dep(:pbkdf2),
# maybe forbid to fetch quicer
common_dep(:emqtt),
common_dep(:rulesql),
common_dep(:telemetry),
# in conflict by emqtt and hocon
common_dep(:getopt),
common_dep(:snabbkaffe),
common_dep(:hocon),
common_dep(:emqx_http_lib),
common_dep(:esasl),
common_dep(:jose),
# in conflict by ehttpc and emqtt
common_dep(:gun),
# in conflict by emqx_connector and system_monitor
common_dep(:epgsql),
# in conflict by emqx and observer_cli
{:recon, github: "ferd/recon", tag: "2.5.1", override: true},
common_dep(:jsx),
# in conflict by erlavro and rocketmq
common_dep(:jsone),
# dependencies of dependencies; we choose specific refs to match
# what rebar3 chooses.
# in conflict by gun and emqtt
common_dep(:cowlib),
# in conflict by cowboy_swagger and cowboy
common_dep(:ranch),
# in conflict by grpc and eetcd
common_dep(:gpb),
{:hackney, github: "emqx/hackney", tag: "1.18.1-1", override: true},
# set by hackney (dependency)
{:ssl_verify_fun, "1.1.7", override: true},
common_dep(:rfc3339),
common_dep(:bcrypt),
common_dep(:uuid),
{:quickrand, github: "okeuday/quickrand", tag: "v2.0.6", override: true},
common_dep(:ra),
{:mimerl, "1.2.0", override: true}
]
end
def extra_release_apps() do
[
common_dep(:redbug),
common_dep(:observer_cli),
common_dep(:system_monitor)
]
end
def common_dep(dep_name, overrides) do
case common_dep(dep_name) do
{^dep_name, opts} ->
{dep_name, Keyword.merge(opts, overrides)}
{^dep_name, tag, opts} when is_binary(tag) ->
{dep_name, tag, Keyword.merge(opts, overrides)}
end
end
def common_dep(:ekka), do: {:ekka, github: "emqx/ekka", tag: "0.19.5", override: true}
def common_dep(:esockd), do: {:esockd, github: "emqx/esockd", tag: "5.11.3", override: true}
def common_dep(:gproc), do: {:gproc, github: "emqx/gproc", tag: "0.9.0.1", override: true}
def common_dep(:hocon), do: {:hocon, github: "emqx/hocon", tag: "0.43.2", override: true}
def common_dep(:lc), do: {:lc, github: "emqx/lc", tag: "0.3.2", override: true}
# in conflict by ehttpc and emqtt
def common_dep(:gun), do: {:gun, github: "emqx/gun", tag: "1.3.11", override: true}
# in conflict by cowboy_swagger and cowboy
def common_dep(:ranch), do: {:ranch, github: "emqx/ranch", tag: "1.8.1-emqx", override: true}
def common_dep(:ehttpc), do: {:ehttpc, github: "emqx/ehttpc", tag: "0.4.14", override: true}
def common_dep(:jiffy), do: {:jiffy, github: "emqx/jiffy", tag: "1.0.6", override: true}
def common_dep(:grpc),
do:
{:grpc,
github: "emqx/grpc-erl", tag: "0.6.12", override: true, system_env: emqx_app_system_env()}
def common_dep(:cowboy), do: {:cowboy, github: "emqx/cowboy", tag: "2.9.2", override: true}
def common_dep(:jsone), do: {:jsone, github: "emqx/jsone", tag: "1.7.1", override: true}
def common_dep(:ecpool), do: {:ecpool, github: "emqx/ecpool", tag: "0.5.7", override: true}
def common_dep(:replayq), do: {:replayq, github: "emqx/replayq", tag: "0.3.8", override: true}
def common_dep(:jsx), do: {:jsx, github: "talentdeficit/jsx", tag: "v3.1.0", override: true}
# in conflict by emqtt and hocon
def common_dep(:getopt), do: {:getopt, "1.0.2", override: true}
def common_dep(:telemetry), do: {:telemetry, "1.1.0", override: true}
# in conflict by grpc and eetcd
def common_dep(:gpb), do: {:gpb, "4.19.9", override: true, runtime: false}
def common_dep(:ra), do: {:ra, "2.7.3", override: true}
def common_dep(:covertool),
do: {:covertool, github: "zmstone/covertool", tag: "2.0.4.1", override: true}
# in conflict by emqx_connector and system_monitor
def common_dep(:epgsql), do: {:epgsql, github: "emqx/epgsql", tag: "4.7.1.2", override: true}
def common_dep(:esasl), do: {:esasl, github: "emqx/esasl", tag: "0.2.1"}
def common_dep(:gen_rpc), do: {:gen_rpc, github: "emqx/gen_rpc", tag: "3.3.1", override: true}
def common_dep(:system_monitor),
do: {:system_monitor, github: "ieQu1/system_monitor", tag: "3.0.5"}
def common_dep(:uuid), do: {:uuid, github: "okeuday/uuid", tag: "v2.0.6", override: true}
def common_dep(:redbug), do: {:redbug, github: "emqx/redbug", tag: "2.0.10"}
def common_dep(:observer_cli), do: {:observer_cli, "1.7.1"}
def common_dep(:jose),
do: {:jose, github: "potatosalad/erlang-jose", tag: "1.11.2", override: true}
def common_dep(:rulesql), do: {:rulesql, github: "emqx/rulesql", tag: "0.2.1"}
def common_dep(:pbkdf2),
do: {:pbkdf2, github: "emqx/erlang-pbkdf2", tag: "2.0.4", override: true}
def common_dep(:bcrypt),
do: {:bcrypt, github: "emqx/erlang-bcrypt", tag: "0.6.2", override: true}
# hex version 0.2.2 used by `jesse` has buggy mix.exs
def common_dep(:rfc3339), do: {:rfc3339, github: "emqx/rfc3339", tag: "0.2.3", override: true}
def common_dep(:minirest),
do: {:minirest, github: "emqx/minirest", tag: "1.4.3", override: true}
# maybe forbid to fetch quicer
def common_dep(:emqtt),
do:
{:emqtt,
github: "emqx/emqtt", tag: "1.10.1", override: true, system_env: maybe_no_quic_env()}
def common_dep(:typerefl),
do: {:typerefl, github: "ieQu1/typerefl", tag: "0.9.1", override: true}
def common_dep(:rocksdb),
do: {:rocksdb, github: "emqx/erlang-rocksdb", tag: "1.8.0-emqx-6", override: true}
def common_dep(:emqx_http_lib),
do: {:emqx_http_lib, github: "emqx/emqx_http_lib", tag: "0.5.3", override: true}
def common_dep(:cowlib),
do:
{:cowlib,
github: "ninenines/cowlib", ref: "c6553f8308a2ca5dcd69d845f0a7d098c40c3363", override: true}
def common_dep(:snabbkaffe),
do: {
:snabbkaffe,
## without this, snabbkaffe is compiled with `-define(snk_kind, '$kind')`, which
## will basically make events in tests never match any predicates.
github: "kafka4beam/snabbkaffe",
tag: "1.0.10",
override: true,
system_env: emqx_app_system_env()
}
###############################################################################################
# BEGIN DEPRECATED FOR MIX BLOCK
# These should be removed once we fully migrate to mix
###############################################################################################
defp emqx_apps(profile_info, version) do
apps = umbrella_apps(profile_info) ++ enterprise_apps(profile_info)
set_emqx_app_system_env(apps, profile_info, version)
end
defp umbrella_apps(profile_info = %{release_type: release_type}) do
enterprise_apps = enterprise_umbrella_apps(release_type)
excluded_apps = excluded_apps(release_type)
"apps/*"
|> Path.wildcard()
|> Enum.map(fn path ->
app =
path
|> Path.basename()
|> String.to_atom()
{app, path: path, manager: :rebar3, override: true}
end)
|> Enum.reject(fn dep_spec ->
dep_spec
|> elem(0)
|> then(&MapSet.member?(enterprise_apps, &1))
end)
|> Enum.reject(fn {app, _} ->
case profile_info do
%{edition_type: :enterprise} ->
app == :emqx_telemetry
_ ->
false
end
end)
|> Enum.reject(fn {app, _} -> app == :emqx_mix_utils end)
|> Enum.reject(fn {app, _} -> app in excluded_apps end)
end
defp enterprise_apps(_profile_info = %{release_type: release_type, edition_type: :enterprise}) do
Enum.map(enterprise_umbrella_apps(release_type), fn app_name ->
path = "apps/#{app_name}"
{app_name, path: path, manager: :rebar3, override: true}
end)
end
defp enterprise_apps(_profile_info) do
[]
end
# need to remove those when listing `/apps/`...
defp enterprise_umbrella_apps(_release_type) do
MapSet.new([
:emqx_connector_aggregator,
:emqx_bridge_kafka,
:emqx_bridge_confluent,
:emqx_bridge_gcp_pubsub,
:emqx_bridge_cassandra,
:emqx_bridge_opents,
:emqx_bridge_dynamo,
:emqx_bridge_greptimedb,
:emqx_bridge_hstreamdb,
:emqx_bridge_influxdb,
:emqx_bridge_iotdb,
:emqx_bridge_es,
:emqx_bridge_matrix,
:emqx_bridge_mongodb,
:emqx_bridge_mysql,
:emqx_bridge_pgsql,
:emqx_bridge_redis,
:emqx_bridge_rocketmq,
:emqx_bridge_tdengine,
:emqx_bridge_timescale,
:emqx_bridge_sqlserver,
:emqx_bridge_pulsar,
:emqx_oracle,
:emqx_bridge_oracle,
:emqx_bridge_rabbitmq,
:emqx_bridge_clickhouse,
:emqx_ft,
:emqx_license,
:emqx_s3,
:emqx_bridge_s3,
:emqx_bridge_azure_blob_storage,
:emqx_bridge_couchbase,
:emqx_schema_registry,
:emqx_schema_validation,
:emqx_message_transformation,
:emqx_enterprise,
:emqx_bridge_kinesis,
:emqx_bridge_azure_event_hub,
:emqx_gcp_device,
:emqx_dashboard_rbac,
:emqx_dashboard_sso,
:emqx_audit,
:emqx_gateway_gbt32960,
:emqx_gateway_ocpp,
:emqx_gateway_jt808,
:emqx_bridge_syskeeper,
:emqx_ds_shared_sub,
:emqx_auth_ext,
:emqx_cluster_link,
:emqx_ds_builtin_raft
])
end
defp enterprise_deps(_profile_info = %{edition_type: :enterprise}) do
[
{:hstreamdb_erl,
github: "hstreamdb/hstreamdb_erl", tag: "0.5.18+v0.18.1+ezstd-v1.0.5-emqx1"},
{:influxdb, github: "emqx/influxdb-client-erl", tag: "1.1.13", override: true},
{:wolff, github: "kafka4beam/wolff", tag: "3.0.2"},
{:kafka_protocol, github: "kafka4beam/kafka_protocol", tag: "4.1.5", override: true},
{:brod_gssapi, github: "kafka4beam/brod_gssapi", tag: "v0.1.1"},
{:brod, github: "kafka4beam/brod", tag: "3.18.0"},
{:snappyer, "1.2.9", override: true},
{:crc32cer, "0.1.8", override: true},
{:opentsdb, github: "emqx/opentsdb-client-erl", tag: "v0.5.1", override: true},
{:greptimedb,
github: "GreptimeTeam/greptimedb-ingester-erl", tag: "v0.1.8", override: true},
# The following two are dependencies of rabbit_common. They are needed here to
# make mix not complain about conflicting versions
{:thoas, github: "emqx/thoas", tag: "v1.0.0", override: true},
{:credentials_obfuscation,
github: "emqx/credentials-obfuscation", tag: "v3.2.0", override: true},
{:rabbit_common,
github: "emqx/rabbitmq-server",
tag: "v3.11.13.2",
sparse: "deps/rabbit_common",
override: true},
{:amqp_client,
github: "emqx/rabbitmq-server",
tag: "v3.11.13.2",
sparse: "deps/amqp_client",
override: true}
]
end
defp enterprise_deps(_profile_info) do
[]
end
defp set_emqx_app_system_env(apps, profile_info, version) do
system_env = emqx_app_system_env(profile_info, version) ++ maybe_no_quic_env()
Enum.map(
apps,
fn {app, opts} ->
{app,
Keyword.update(
opts,
:system_env,
system_env,
&Keyword.merge(&1, system_env)
)}
end
)
end
def emqx_app_system_env(profile_info, version) do
erlc_options(profile_info, version)
|> dump_as_erl()
|> then(&[{"ERL_COMPILER_OPTIONS", &1}])
end
def emqx_app_system_env() do
k = {__MODULE__, :emqx_app_system_env}
get_memoized(k, fn ->
emqx_app_system_env(profile_info(), pkg_vsn())
end)
end
###############################################################################################
# END DEPRECATED FOR MIX BLOCK
###############################################################################################
defp erlc_options(%{edition_type: edition_type}, version) do
[
:debug_info,
{:compile_info, [{:emqx_vsn, String.to_charlist(version)}]},
{:d, :EMQX_RELEASE_EDITION, erlang_edition(edition_type)},
{:d, :EMQX_ELIXIR},
{:d, :snk_kind, :msg}
] ++
singleton(test_env?(), {:d, :TEST}) ++
singleton(not enable_quicer?(), {:d, :BUILD_WITHOUT_QUIC})
end
defp singleton(false, _value), do: []
defp singleton(true, value), do: [value]
def profile_info() do
k = {__MODULE__, :profile_info}
get_memoized(k, &check_profile!/0)
end
def pkg_vsn() do
k = {__MODULE__, :pkg_vsn}
get_memoized(k, &do_pkg_vsn/0)
end
def common_deps() do
if test_env?() do
[
{:bbmustache, "1.10.0"},
{:cth_readable, "1.5.1"},
{:proper, "1.4.0"},
{:meck, "0.9.2"}
]
else
[]
end
end
def extra_applications() do
k = {__MODULE__, :extra_applications}
get_memoized(k, fn ->
if test_env?() do
[:eunit, :common_test, :dialyzer, :mnesia]
else
[]
end
end)
end
def erlc_paths() do
k = {__MODULE__, :erlc_paths}
get_memoized(k, fn ->
if test_env?() do
["src", "test"]
else
["src"]
end
end)
end
def erlc_options() do
k = {__MODULE__, :erlc_options}
get_memoized(k, fn ->
profile_info = profile_info()
version = pkg_vsn()
erlc_options(profile_info, version)
end)
end
def test_env?() do
k = {__MODULE__, :test_env?}
get_memoized(k, fn ->
env = to_string(Mix.env())
System.get_env("TEST") == "1" || env =~ ~r/-test$/
end)
end
defp set_test_env!(test_env?) do
k = {__MODULE__, :test_env?}
:persistent_term.put(k, test_env?)
end
defp get_memoized(k, compute_fn) do
case :persistent_term.get(k, :undefined) do
:undefined ->
res = compute_fn.()
:persistent_term.put(k, res)
res
res ->
res
end
end
def maybe_no_quic_env() do
if not enable_quicer?() do
[{"BUILD_WITHOUT_QUIC", "true"}]
else
[]
end
end
defp releases() do
[
emqx: fn ->
%{
release_type: release_type,
package_type: package_type,
edition_type: edition_type
} = check_profile!()
base_steps = [
&merge_config/1,
&make_docs/1,
:assemble,
&create_RELEASES/1,
©_files(&1, release_type, package_type, edition_type),
©_escript(&1, "nodetool"),
©_escript(&1, "install_upgrade.escript")
]
steps =
if System.get_env("ELIXIR_MAKE_TAR") == "yes" do
base_steps ++ [&prepare_tar_overlays/1, :tar]
else
base_steps
end
[
applications: applications(release_type, edition_type),
skip_mode_validation_for: [
:emqx_mix,
:emqx_machine,
:emqx_gateway,
:emqx_gateway_stomp,
:emqx_gateway_mqttsn,
:emqx_gateway_coap,
:emqx_gateway_lwm2m,
:emqx_gateway_exproto,
:emqx_dashboard,
:emqx_dashboard_sso,
:emqx_audit,
:emqx_resource,
:emqx_connector,
:emqx_exhook,
:emqx_bridge,
:emqx_bridge_mqtt,
:emqx_modules,
:emqx_management,
:emqx_retainer,
:emqx_prometheus,
:emqx_rule_engine,
:emqx_auto_subscribe,
:emqx_slow_subs,
:emqx_plugins,
:emqx_ft,
:emqx_s3,
:emqx_opentelemetry,
:emqx_durable_storage,
:emqx_ds_builtin_local,
:emqx_ds_builtin_raft,
:rabbit_common,
:emqx_eviction_agent,
:emqx_node_rebalance
],
steps: steps,
strip_beams: false
]
end
]
end
def applications(release_type, edition_type) do
{:ok,
[
%{
db_apps: db_apps,
system_apps: system_apps,
common_business_apps: common_business_apps,
ee_business_apps: ee_business_apps,
ce_business_apps: ce_business_apps
}
]} = :file.consult("apps/emqx_machine/priv/reboot_lists.eterm")
edition_specific_apps =
if edition_type == :enterprise do
ee_business_apps
else
ce_business_apps
end
business_apps = common_business_apps ++ edition_specific_apps
excluded_apps = excluded_apps(release_type)
system_apps =
Enum.map(system_apps, fn app ->
if is_atom(app), do: {app, :permanent}, else: app
end)
db_apps = Enum.map(db_apps, &{&1, :load})
business_apps = Enum.map(business_apps, &{&1, :load})
[system_apps, db_apps, [emqx_ctl: :permanent, emqx_machine: :permanent], business_apps]
|> List.flatten()
|> Keyword.reject(fn {app, _type} ->
app in excluded_apps ||
(edition_type == :enterprise && app == :emqx_telemetry)
end)
end
defp excluded_apps(_release_type) do
%{
mnesia_rocksdb: enable_rocksdb?(),
quicer: enable_quicer?(),
jq: enable_jq?(),
observer: is_app?(:observer)
}
|> Enum.reject(&elem(&1, 1))
|> Enum.map(&elem(&1, 0))
end
defp is_app?(name) do
case Application.load(name) do
:ok ->
true
{:error, {:already_loaded, _}} ->
true
_ ->
false
end
end
def check_profile!() do
valid_envs = [
:emqx,
:"emqx-test",
:"emqx-pkg",
:"emqx-enterprise",
:"emqx-enterprise-test",
:"emqx-enterprise-pkg"
]
if Mix.env() == :dev do
env_profile = System.get_env("PROFILE")
if env_profile do
# copy from PROFILE env var
System.get_env("PROFILE")
|> String.to_atom()
|> Mix.env()
else
Mix.shell().info([
:yellow,
"Warning: env var PROFILE is unset; defaulting to emqx"
])
Mix.env(:emqx)
end
end
if Mix.env() not in valid_envs do
formatted_envs =
valid_envs
|> Enum.map(&" * #{&1}")
|> Enum.join("\n")
Mix.raise("""
Invalid env #{Mix.env()}. Valid options are:
#{formatted_envs}
""")
end
mix_env = Mix.env()
{
release_type,
package_type,
edition_type
} =
case mix_env do
:dev ->
{:standard, :bin, :community}
:emqx ->
{:standard, :bin, :community}
:"emqx-test" ->
{:standard, :bin, :community}
:"emqx-enterprise" ->
{:standard, :bin, :enterprise}
:"emqx-enterprise-test" ->
{:standard, :bin, :enterprise}
:"emqx-pkg" ->
{:standard, :pkg, :community}
:"emqx-enterprise-pkg" ->
{:standard, :pkg, :enterprise}
end
test? = to_string(mix_env) =~ ~r/-test$/ || test_env?()
normalize_env!(test?)
# Mix.debug(true)
if Mix.debug?() do
Mix.shell().info([
:blue,
"mix_env: #{Mix.env()}",
"; release type: #{release_type}",
"; package type: #{package_type}",
"; edition type: #{edition_type}",
"; test env?: #{test?}"
])
end
test? = to_string(mix_env) =~ ~r/-test$/ || test_env?()
normalize_env!(test?)
# Mix.debug(true)
if Mix.debug?() do
Mix.shell().info([
:blue,
"mix_env: #{Mix.env()}",
"; release type: #{release_type}",
"; package type: #{package_type}",
"; edition type: #{edition_type}",
"; test env?: #{test?}"
])
end
%{
release_type: release_type,
package_type: package_type,
edition_type: edition_type,
test?: test?
}
end
#############################################################################
# Custom Steps
#############################################################################
# Gathers i18n files and merge them before producing docs and schemas.
defp merge_config(release) do
{_, 0} = System.cmd("bash", ["-c", "./scripts/merge-config.escript"])
release
end
defp make_docs(release) do
profile = System.get_env("MIX_ENV")
os_cmd("build", [profile, "docs"])
release
end
defp copy_files(release, release_type, package_type, edition_type) do
overwrite? = Keyword.get(release.options, :overwrite, false)
bin = Path.join(release.path, "bin")
etc = Path.join(release.path, "etc")
log = Path.join(release.path, "log")
plugins = Path.join(release.path, "plugins")
Mix.Generator.create_directory(bin)
Mix.Generator.create_directory(etc)
Mix.Generator.create_directory(log)
Mix.Generator.create_directory(plugins)
Mix.Generator.create_directory(Path.join(etc, "certs"))
Enum.each(
["mnesia", "configs", "patches", "scripts"],
fn dir ->
path = Path.join([release.path, "data", dir])
Mix.Generator.create_directory(path)
end
)
Mix.Generator.copy_file(
"apps/emqx_auth/etc/acl.conf",
Path.join(etc, "acl.conf"),
force: overwrite?
)
# required by emqx_auth
File.cp_r!(
"apps/emqx/etc/certs",
Path.join(etc, "certs")
)
profile = System.get_env("MIX_ENV")
File.cp_r!(
"rel/config/examples",
Path.join(etc, "examples"),
force: overwrite?
)
# copy /rel/config/ee-examples if profile is enterprise
case profile do
"emqx-enterprise" ->
File.cp_r!(
"rel/config/ee-examples",
Path.join(etc, "examples"),
force: overwrite?
)
_ ->
:ok
end
# this is required by the produced escript / nodetool
Mix.Generator.copy_file(
Path.join(release.version_path, "start_clean.boot"),
Path.join(bin, "no_dot_erlang.boot"),
force: overwrite?
)
assigns = template_vars(release, release_type, package_type, edition_type)
# This is generated by `scripts/merge-config.escript` or `make merge-config`
# So, this should be run before the release.
# TODO: run as a "compiler" step???
render_template(
"apps/emqx_conf/etc/emqx.conf.all",
assigns,
Path.join(etc, "emqx.conf")
)
render_template(
"rel/emqx_vars",
assigns,
Path.join([release.path, "releases", "emqx_vars"])
)
vm_args_template_path =
case release_type do
_ ->
"apps/emqx/etc/vm.args.cloud"
end
render_template(
vm_args_template_path,
assigns,
[
Path.join(etc, "vm.args"),
Path.join(release.version_path, "vm.args")
]
)
for name <- [
"emqx",
"emqx_ctl"
] do
Mix.Generator.copy_file(
"bin/#{name}",
Path.join(bin, name),
force: overwrite?
)
# Files with the version appended are expected by the release
# upgrade script `install_upgrade.escript`
Mix.Generator.copy_file(
Path.join(bin, name),
Path.join(bin, name <> "-#{release.version}"),
force: overwrite?
)
end
for base_name <- ["emqx", "emqx_ctl"],
suffix <- ["", "-#{release.version}"] do
name = base_name <> suffix
File.chmod!(Path.join(bin, name), 0o755)
end
Mix.Generator.copy_file(
"bin/node_dump",
Path.join(bin, "node_dump"),
force: overwrite?
)
File.chmod!(Path.join(bin, "node_dump"), 0o755)
Mix.Generator.copy_file(
"bin/emqx_cluster_rescue",
Path.join(bin, "emqx_cluster_rescue"),
force: overwrite?
)
File.chmod!(Path.join(bin, "emqx_cluster_rescue"), 0o755)
render_template(
"rel/BUILD_INFO",
assigns,
Path.join(release.version_path, "BUILD_INFO")
)
release
end
defp render_template(template, assigns, target) when is_binary(target) do
render_template(template, assigns, [target])
end
defp render_template(template, assigns, tartgets) when is_list(tartgets) do
rendered =
File.read!(template)
|> from_rebar_to_eex_template()
|> EEx.eval_string(assigns)
for target <- tartgets do
File.write!(target, rendered)
end
end
# needed by nodetool and by release_handler
defp create_RELEASES(release) do
apps =
Enum.map(release.applications, fn {app_name, app_props} ->
app_vsn = Keyword.fetch!(app_props, :vsn)
app_path =
"./lib"
|> Path.join("#{app_name}-#{app_vsn}")
|> to_charlist()
{app_name, app_vsn, app_path}
end)
release_entry = [
{
:release,
to_charlist(release.name),
to_charlist(release.version),