Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Upgrade amoc-arsenal #40

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 5 additions & 4 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ jobs:
name: OTP ${{matrix.otp_vsn}}
strategy:
matrix:
otp_vsn: ['27', '26', '25']
rebar_vsn: ['3.23.0']
otp_vsn: ['27']
rebar_vsn: ['3.24.0']
runs-on: 'ubuntu-24.04'
steps:
- uses: actions/checkout@v4
Expand All @@ -33,7 +33,8 @@ jobs:
name: docker container test with OTP ${{matrix.otp_vsn}}
strategy:
matrix:
otp_vsn: ['27', '26', '25']
otp_vsn: ['27']
rebar_vsn: ['3.24.0']
runs-on: 'ubuntu-24.04'
env:
OTP_RELEASE: ${{ matrix.otp_vsn }}
Expand All @@ -56,7 +57,7 @@ jobs:
- integration_test
if: github.ref == 'refs/heads/master'
env:
OTP_RELEASE: 27.0
OTP_RELEASE: 27.1
steps:
- uses: actions/checkout@v4
- name: Set up QEMU
Expand Down
30 changes: 17 additions & 13 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,20 +1,24 @@
ARG otp_vsn=25.3
FROM erlang:${otp_vsn}
MAINTAINER Erlang Solutions <[email protected]>
ARG otp_vsn=27.1
FROM erlang:${otp_vsn} AS builder
LABEL org.label-schema.name='AMOC Arsenal' \
org.label-schema.vendor='Erlang Solutions'

WORKDIR /amoc_arsenal_xmpp
COPY ./ ./

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

RUN rebar3 release
COPY rebar.config .
COPY rel rel
COPY src src
RUN rebar3 compile

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

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

CMD ["sh", "/start_amoc.sh"]
FROM builder AS prod
RUN rebar3 as prod release
ENV PATH="/amoc_arsenal_xmpp/_build/prod/rel/amoc_arsenal_xmpp/bin:${PATH}"
6 changes: 3 additions & 3 deletions ci/build_and_push_docker_image.sh
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@
set -euo pipefail
IFS=$'\n\t'

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

docker buildx build --platform linux/amd64,linux/arm64 \
--build-arg otp_vsn \
--push -t mongooseim/amoc-arsenal-xmpp:latest .
--target prod --push --build-arg otp_vsn \
-t mongooseim/amoc-arsenal-xmpp:latest .
3 changes: 2 additions & 1 deletion ci/build_docker_image.sh
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,13 @@ IFS=$'\n\t'

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

docker build \
-f Dockerfile \
--target dev \
-t "amoc-arsenal-xmpp:${version}" \
-t "amoc-arsenal-xmpp:latest" \
--build-arg otp_vsn="${otp_vsn}" \
Expand Down
45 changes: 14 additions & 31 deletions ci/docker-compose.yml
Original file line number Diff line number Diff line change
@@ -1,55 +1,38 @@
###############################################################################
## you may need to build 'amoc-arsenal-xmpp' docker image, before running: ##
## ##
## docker-compose up -d --scale amoc-worker=2 ##
## ##
## it can be done using this command: ##
## ##
## docker build . -t amoc-arsenal-xmpp ##
## ##
## alternatively, a custom amoc image can be provided by setting AMOC_IMAGE ##
## environment variable: ##
## ##
## AMOC_IMAGE=mongooseim/amoc-arsenal-xmpp docker-compose up -d ##
## ##
###############################################################################
version: "3.3"
services:

amoc-master:
hostname: "amoc-master"
image: "${AMOC_IMAGE:-amoc-arsenal-xmpp}"
pull_policy: never
environment:
AMOC_PROMETHEUS_IP: '{0, 0, 0, 0}'
ports:
- "4000:4000"
networks:
- amoc-test-network
environment:
AMOC_GRAPHITE_HOST: '"${GRAPHITE_HOST:-host.docker.internal}"'
healthcheck:
test: "amoc_arsenal_xmpp status"

amoc-worker:
image: "${AMOC_IMAGE:-amoc-arsenal-xmpp}"
networks:
- amoc-test-network
pull_policy: never
ulimits: ## ensure that we can use all the ephemeral ports
nofile:
soft: 66000
hard: 66000
environment:
AMOC_GRAPHITE_HOST: '"${GRAPHITE_HOST:-host.docker.internal}"'
AMOC_NODES: "['amoc_arsenal_xmpp@amoc-master']"
AMOC_XMPP_SERVERS: '[[{host, <<"host.docker.internal">>}]]'
entrypoint: [ "sh", "-c", 'AMOC_GRAPHITE_PREFIX="\"amoc-worker.$$HOSTNAME\"" /start_amoc.sh']
AMOC_PROMETHEUS_IP: '{0, 0, 0, 0}'
deploy:
mode: replicated
replicas: 6
healthcheck:
test: "amoc_arsenal_xmpp status"
graphite:
image: "graphiteapp/graphite-statsd:1.1.10-4"

prometheus:
image: "prom/prometheus"
ports:
- "8080:80"
- "2003:2003"
- "9090:9090"
volumes:
- ./prometheus.yml:/etc/prometheus/prometheus.yml
profiles:
- with_graphite
networks:
amoc-test-network:
- with_prometheus
18 changes: 18 additions & 0 deletions ci/prometheus.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
global:
scrape_interval: 5s
evaluation_interval: 5s
scrape_configs:
- job_name: prometheus
# metrics_path defaults to '/metrics'
# scheme defaults to 'http'.
static_configs:
- targets: ["localhost:9090"]
- job_name: amoc-master
static_configs:
- targets: ["ci-amoc-master-1:9090"]
- job_name: amoc-worker-1
static_configs:
- targets: ["ci-amoc-worker-1:9090"]
- job_name: amoc-worker-2
static_configs:
- targets: ["ci-amoc-worker-2:9090"]
4 changes: 2 additions & 2 deletions ci/start_amoc_cluster.sh
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,5 @@ set -euo pipefail
IFS=$'\n\t'

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

docker compose --profile with_prometheus up --wait \
--wait-timeout 100 --scale amoc-worker=2
2 changes: 1 addition & 1 deletion ci/stop_amoc_cluster.sh
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,4 @@ set -euo pipefail
IFS=$'\n\t'

cd "$(git rev-parse --show-toplevel)/ci"
docker compose --profile with_graphite down
docker compose --profile with_prometheus down
43 changes: 22 additions & 21 deletions ci/test_amoc_cluster.sh
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,23 @@ function assert_match()
exit 1; }
}

function contains()
{
local output="$(cat -)"
local ret= acc=0
for pattern in "$@"; do
ret="$(echo "$output" | grep -q -e "$pattern"; echo "$?")"
if [ "$ret" -ne "0" ]; then
[ "$(($acc))" -eq "0" ] && {
echo "contains FAILED"
echo "output: '${output}'"; }
echo "pattern is missing: '${pattern}'"
fi >&2
acc+="+${ret}"
done
test "$(($acc))" "-eq" "0"
}

function get_nodes()
{
curl -s -X GET "http://localhost:4000/nodes" -H "accept: application/json" \
Expand All @@ -42,13 +59,6 @@ function number_of_nodes()
| jq '.nodes | length'
}

function get_graphite_prefix()
{
local node="$1"
curl -s -X GET "http://localhost:4000/status/$node" -H "accept: application/json" \
| jq '.env.AMOC_GRAPHITE_PREFIX | ltrimstr("\"") | rtrimstr("\"")' | sed 's/"//g'
}

function retry()
{
local n="$1" m="0"
Expand All @@ -62,27 +72,18 @@ function retry()
echo -e "\nsuccess after '$m' retries";
}

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

function wait_for_reported_metrics()
{
local graphite_prefix="$1"
retry 60 are_metrics_reported "$graphite_prefix"
function wait_for_metrics() {
retry 60 metrics_reported "$@"
}

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

for node in $(get_nodes); do
assert_match "node name" "amoc_arsenal_xmpp@.*" "$node"
if [ "$node" != "amoc_arsenal_xmpp@amoc-master" ]; then
graphite_prefix="$(get_graphite_prefix $node)"
wait_for_reported_metrics "$graphite_prefix"
else
wait_for_reported_metrics "amoc-master"
fi
wait_for_metrics "amoc-master"
done
9 changes: 8 additions & 1 deletion rebar.config
Original file line number Diff line number Diff line change
@@ -1,14 +1,21 @@
{minimum_otp_vsn, "27"}.

{ erl_opts, [
debug_info
]}.

{ deps, [
{amoc_arsenal, {git, "https://github.com/esl/amoc-arsenal.git", {branch, "main"}}},
{escalus, "4.2.16"},
{jiffy, "1.1.2"},
{exml, "3.4.1", {pkg, hexml}},
{gun, "2.1.0"},
{fusco, "0.1.1"}
]}.

{ shell, [
{apps, [amoc_arsenal_xmpp]}
]}.

{ xref_checks, [
%% enable most checks, but avoid 'unused calls' which makes amoc-arsenal fail...
undefined_function_calls, undefined_functions, locals_not_used,
Expand Down
Loading