Skip to content

Commit 409d832

Browse files
authored
Merge pull request #40 from esl/arsenal_upgrade
Upgrade amoc-arsenal
2 parents dbc84c9 + 01140ab commit 409d832

15 files changed

+134
-138
lines changed

.github/workflows/ci.yml

+5-4
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,8 @@ jobs:
1313
name: OTP ${{matrix.otp_vsn}}
1414
strategy:
1515
matrix:
16-
otp_vsn: ['27', '26', '25']
17-
rebar_vsn: ['3.23.0']
16+
otp_vsn: ['27']
17+
rebar_vsn: ['3.24.0']
1818
runs-on: 'ubuntu-24.04'
1919
steps:
2020
- uses: actions/checkout@v4
@@ -33,7 +33,8 @@ jobs:
3333
name: docker container test with OTP ${{matrix.otp_vsn}}
3434
strategy:
3535
matrix:
36-
otp_vsn: ['27', '26', '25']
36+
otp_vsn: ['27']
37+
rebar_vsn: ['3.24.0']
3738
runs-on: 'ubuntu-24.04'
3839
env:
3940
OTP_RELEASE: ${{ matrix.otp_vsn }}
@@ -56,7 +57,7 @@ jobs:
5657
- integration_test
5758
if: github.ref == 'refs/heads/master'
5859
env:
59-
OTP_RELEASE: 27.0
60+
OTP_RELEASE: 27.1
6061
steps:
6162
- uses: actions/checkout@v4
6263
- name: Set up QEMU

Dockerfile

+17-13
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,24 @@
1-
ARG otp_vsn=25.3
2-
FROM erlang:${otp_vsn}
3-
MAINTAINER Erlang Solutions <[email protected]>
1+
ARG otp_vsn=27.1
2+
FROM erlang:${otp_vsn} AS builder
3+
LABEL org.label-schema.name='AMOC Arsenal' \
4+
org.label-schema.vendor='Erlang Solutions'
45

56
WORKDIR /amoc_arsenal_xmpp
6-
COPY ./ ./
77

8-
## build only what is commited
9-
RUN git clean -ffxd
10-
RUN git restore -WS .
8+
COPY rebar.lock .
9+
RUN rebar3 compile --deps_only
1110

12-
RUN rebar3 release
11+
COPY rebar.config .
12+
COPY rel rel
13+
COPY src src
14+
RUN rebar3 compile
1315

14-
ENV PATH "/amoc_arsenal_xmpp/_build/default/rel/amoc_arsenal_xmpp/bin:${PATH}"
16+
CMD ["amoc_arsenal_xmpp", "console", "-noshell", "-noinput", "+Bd"]
1517

16-
COPY --chmod=500 <<-EOF /start_amoc.sh
17-
amoc_arsenal_xmpp console -noshell -noinput +Bd
18-
EOF
18+
FROM builder AS dev
19+
RUN rebar3 release
20+
ENV PATH="/amoc_arsenal_xmpp/_build/default/rel/amoc_arsenal_xmpp/bin:${PATH}"
1921

20-
CMD ["sh", "/start_amoc.sh"]
22+
FROM builder AS prod
23+
RUN rebar3 as prod release
24+
ENV PATH="/amoc_arsenal_xmpp/_build/prod/rel/amoc_arsenal_xmpp/bin:${PATH}"

ci/build_and_push_docker_image.sh

+3-3
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,9 @@
55
set -euo pipefail
66
IFS=$'\n\t'
77

8-
export otp_vsn="${OTP_RELEASE:-25.3}"
8+
export otp_vsn="${OTP_RELEASE:-27.1}"
99
echo "ERLANG/OTP ${otp_vsn}"
1010

1111
docker buildx build --platform linux/amd64,linux/arm64 \
12-
--build-arg otp_vsn \
13-
--push -t mongooseim/amoc-arsenal-xmpp:latest .
12+
--target prod --push --build-arg otp_vsn \
13+
-t mongooseim/amoc-arsenal-xmpp:latest .

ci/build_docker_image.sh

+2-1
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,13 @@ IFS=$'\n\t'
77

88
# Get current repo version
99
version="$(git rev-parse --short HEAD)"
10-
otp_vsn="${OTP_RELEASE:-25.3}"
10+
otp_vsn="${OTP_RELEASE:-27.1}"
1111
echo "ERLANG/OTP ${otp_vsn}"
1212
echo "AMOC-ARSENAL-XMPP ${version}"
1313

1414
docker build \
1515
-f Dockerfile \
16+
--target dev \
1617
-t "amoc-arsenal-xmpp:${version}" \
1718
-t "amoc-arsenal-xmpp:latest" \
1819
--build-arg otp_vsn="${otp_vsn}" \

ci/docker-compose.yml

+14-31
Original file line numberDiff line numberDiff line change
@@ -1,55 +1,38 @@
1-
###############################################################################
2-
## you may need to build 'amoc-arsenal-xmpp' docker image, before running: ##
3-
## ##
4-
## docker-compose up -d --scale amoc-worker=2 ##
5-
## ##
6-
## it can be done using this command: ##
7-
## ##
8-
## docker build . -t amoc-arsenal-xmpp ##
9-
## ##
10-
## alternatively, a custom amoc image can be provided by setting AMOC_IMAGE ##
11-
## environment variable: ##
12-
## ##
13-
## AMOC_IMAGE=mongooseim/amoc-arsenal-xmpp docker-compose up -d ##
14-
## ##
15-
###############################################################################
16-
version: "3.3"
171
services:
2+
183
amoc-master:
194
hostname: "amoc-master"
205
image: "${AMOC_IMAGE:-amoc-arsenal-xmpp}"
6+
pull_policy: never
7+
environment:
8+
AMOC_PROMETHEUS_IP: '{0, 0, 0, 0}'
219
ports:
2210
- "4000:4000"
23-
networks:
24-
- amoc-test-network
25-
environment:
26-
AMOC_GRAPHITE_HOST: '"${GRAPHITE_HOST:-host.docker.internal}"'
2711
healthcheck:
2812
test: "amoc_arsenal_xmpp status"
13+
2914
amoc-worker:
3015
image: "${AMOC_IMAGE:-amoc-arsenal-xmpp}"
31-
networks:
32-
- amoc-test-network
16+
pull_policy: never
3317
ulimits: ## ensure that we can use all the ephemeral ports
3418
nofile:
3519
soft: 66000
3620
hard: 66000
3721
environment:
38-
AMOC_GRAPHITE_HOST: '"${GRAPHITE_HOST:-host.docker.internal}"'
3922
AMOC_NODES: "['amoc_arsenal_xmpp@amoc-master']"
4023
AMOC_XMPP_SERVERS: '[[{host, <<"host.docker.internal">>}]]'
41-
entrypoint: [ "sh", "-c", 'AMOC_GRAPHITE_PREFIX="\"amoc-worker.$$HOSTNAME\"" /start_amoc.sh']
24+
AMOC_PROMETHEUS_IP: '{0, 0, 0, 0}'
4225
deploy:
4326
mode: replicated
4427
replicas: 6
4528
healthcheck:
4629
test: "amoc_arsenal_xmpp status"
47-
graphite:
48-
image: "graphiteapp/graphite-statsd:1.1.10-4"
30+
31+
prometheus:
32+
image: "prom/prometheus"
4933
ports:
50-
- "8080:80"
51-
- "2003:2003"
34+
- "9090:9090"
35+
volumes:
36+
- ./prometheus.yml:/etc/prometheus/prometheus.yml
5237
profiles:
53-
- with_graphite
54-
networks:
55-
amoc-test-network:
38+
- with_prometheus

ci/prometheus.yml

+18
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
global:
2+
scrape_interval: 5s
3+
evaluation_interval: 5s
4+
scrape_configs:
5+
- job_name: prometheus
6+
# metrics_path defaults to '/metrics'
7+
# scheme defaults to 'http'.
8+
static_configs:
9+
- targets: ["localhost:9090"]
10+
- job_name: amoc-master
11+
static_configs:
12+
- targets: ["ci-amoc-master-1:9090"]
13+
- job_name: amoc-worker-1
14+
static_configs:
15+
- targets: ["ci-amoc-worker-1:9090"]
16+
- job_name: amoc-worker-2
17+
static_configs:
18+
- targets: ["ci-amoc-worker-2:9090"]

ci/start_amoc_cluster.sh

+2-2
Original file line numberDiff line numberDiff line change
@@ -6,5 +6,5 @@ set -euo pipefail
66
IFS=$'\n\t'
77

88
cd "$(git rev-parse --show-toplevel)/ci"
9-
docker compose --profile with_graphite up --wait --wait-timeout 100 --scale amoc-worker=2
10-
9+
docker compose --profile with_prometheus up --wait \
10+
--wait-timeout 100 --scale amoc-worker=2

ci/stop_amoc_cluster.sh

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,4 +6,4 @@ set -euo pipefail
66
IFS=$'\n\t'
77

88
cd "$(git rev-parse --show-toplevel)/ci"
9-
docker compose --profile with_graphite down
9+
docker compose --profile with_prometheus down

ci/test_amoc_cluster.sh

+22-21
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,23 @@ function assert_match()
2929
exit 1; }
3030
}
3131

32+
function contains()
33+
{
34+
local output="$(cat -)"
35+
local ret= acc=0
36+
for pattern in "$@"; do
37+
ret="$(echo "$output" | grep -q -e "$pattern"; echo "$?")"
38+
if [ "$ret" -ne "0" ]; then
39+
[ "$(($acc))" -eq "0" ] && {
40+
echo "contains FAILED"
41+
echo "output: '${output}'"; }
42+
echo "pattern is missing: '${pattern}'"
43+
fi >&2
44+
acc+="+${ret}"
45+
done
46+
test "$(($acc))" "-eq" "0"
47+
}
48+
3249
function get_nodes()
3350
{
3451
curl -s -X GET "http://localhost:4000/nodes" -H "accept: application/json" \
@@ -42,13 +59,6 @@ function number_of_nodes()
4259
| jq '.nodes | length'
4360
}
4461

45-
function get_graphite_prefix()
46-
{
47-
local node="$1"
48-
curl -s -X GET "http://localhost:4000/status/$node" -H "accept: application/json" \
49-
| jq '.env.AMOC_GRAPHITE_PREFIX | ltrimstr("\"") | rtrimstr("\"")' | sed 's/"//g'
50-
}
51-
5262
function retry()
5363
{
5464
local n="$1" m="0"
@@ -62,27 +72,18 @@ function retry()
6272
echo -e "\nsuccess after '$m' retries";
6373
}
6474

65-
function are_metrics_reported()
75+
function metrics_reported()
6676
{
67-
local graphite_prefix="$1"
68-
local length="$(curl -s "http://localhost:8080/metrics/find?query=${graphite_prefix}.*" | jq "length")"
69-
[ "$length" -gt "0" ]
77+
curl -s 'http://localhost:9090/api/v1/targets' | contains "$@"
7078
}
7179

72-
function wait_for_reported_metrics()
73-
{
74-
local graphite_prefix="$1"
75-
retry 60 are_metrics_reported "$graphite_prefix"
80+
function wait_for_metrics() {
81+
retry 60 metrics_reported "$@"
7682
}
7783

7884
assert_equal "number of nodes" 3 "$(number_of_nodes)"
7985

8086
for node in $(get_nodes); do
8187
assert_match "node name" "amoc_arsenal_xmpp@.*" "$node"
82-
if [ "$node" != "amoc_arsenal_xmpp@amoc-master" ]; then
83-
graphite_prefix="$(get_graphite_prefix $node)"
84-
wait_for_reported_metrics "$graphite_prefix"
85-
else
86-
wait_for_reported_metrics "amoc-master"
87-
fi
88+
wait_for_metrics "amoc-master"
8889
done

rebar.config

+9-2
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,21 @@
1+
{minimum_otp_vsn, "27"}.
2+
13
{ erl_opts, [
24
debug_info
35
]}.
46

57
{ deps, [
6-
{amoc_arsenal, {git, "https://github.com/esl/amoc-arsenal.git", {branch, "stable"}}},
8+
{amoc_arsenal, {git, "https://github.com/esl/amoc-arsenal.git", {branch, "main"}}},
79
{escalus, "4.2.16"},
8-
{jiffy, "1.1.2"},
10+
{exml, "3.4.1", {pkg, hexml}},
11+
{gun, "2.1.0"},
912
{fusco, "0.1.1"}
1013
]}.
1114

15+
{ shell, [
16+
{apps, [amoc_arsenal_xmpp]}
17+
]}.
18+
1219
{ xref_checks, [
1320
%% enable most checks, but avoid 'unused calls' which makes amoc-arsenal fail...
1421
undefined_function_calls, undefined_functions, locals_not_used,

0 commit comments

Comments
 (0)