Skip to content
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
2 changes: 1 addition & 1 deletion .github/workflows/erlang-checks.yml
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ jobs:
run:
name: Run checks
needs: setup
uses: valitydev/erlang-workflows/.github/workflows/erlang-parallel-build.yml@v1.0.13
uses: valitydev/erlang-workflows/.github/workflows/erlang-parallel-build.yml@v1.0.14
with:
otp-version: ${{ needs.setup.outputs.otp-version }}
rebar-version: ${{ needs.setup.outputs.rebar-version }}
Expand Down
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -18,3 +18,5 @@ _checkouts/
# make stuff
/.image.*
Makefile.env

.idea
16 changes: 11 additions & 5 deletions Dockerfile.dev
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ ARG THRIFT_VERSION
ARG BUILDARCH

RUN apt-get --yes update && \
apt-get --yes --no-install-recommends install iproute2=5.10.0-4 && \
apt-get --yes --no-install-recommends install iproute2=5.10.0-4 sshpass=1.09-1+b1 && \
apt-get clean && \
rm -rf /var/lib/apt/lists/*

Expand All @@ -17,13 +17,19 @@ RUN wget -q -O- "https://github.com/valitydev/thrift/releases/download/${THRIFT_
ENV NETUNREACH_NETWORK="10.254.254.0/24"
ENV NETUNREACH_ADDRESS="10.254.254.10"

RUN echo '#!/bin/sh' >> /entrypoint.sh && \
echo "ip route add throw ${NETUNREACH_NETWORK}" >> /entrypoint.sh && \
echo 'exec "$@"' >> /entrypoint.sh && \
chmod +x /entrypoint.sh
COPY ./test_resources/ssh/ /root/.ssh/
RUN chown -R root:root /root/.ssh && \
chmod 600 /root/.ssh/*

COPY ./test_resources/entrypoint.sh.dev /entrypoint.sh
RUN chmod +x /entrypoint.sh

ENTRYPOINT ["/entrypoint.sh"]

ENV CHARSET=UTF-8
ENV LANG=C.UTF-8
ENV SERVICE_NAME=mg
CMD ["/bin/bash"]

EXPOSE 4369
EXPOSE 8022
64 changes: 64 additions & 0 deletions Dockerfile.test
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
ARG OTP_VERSION

# Build the release
FROM docker.io/library/erlang:${OTP_VERSION} AS builder
SHELL ["/bin/bash", "-o", "pipefail", "-c"]

# Install thrift compiler
ARG THRIFT_VERSION
ARG TARGETARCH

RUN wget -q -O- "https://github.com/valitydev/thrift/releases/download/${THRIFT_VERSION}/thrift-${THRIFT_VERSION}-linux-${TARGETARCH}.tar.gz" \
| tar -xvz -C /usr/local/bin/

# Copy sources
RUN mkdir /build
COPY . /build/

# Build the release
WORKDIR /build
RUN rebar3 compile \
&& rebar3 as prod release

# Make a runner image
FROM docker.io/library/erlang:${OTP_VERSION}-slim

ARG SERVICE_NAME=mg
ARG USER_UID=1001
ARG USER_GID=$USER_UID

# Set env
ENV CHARSET=UTF-8
ENV LANG=C.UTF-8

# Expose SERVICE_NAME as env so CMD expands properly on start
ENV SERVICE_NAME=${SERVICE_NAME}

# Set runtime
WORKDIR /opt/${SERVICE_NAME}

COPY --from=builder /build/_build/prod/rel/${SERVICE_NAME} /opt/${SERVICE_NAME}
COPY ./test_resources/authorized_keys /root/.ssh/authorized_keys
RUN chown root:root /root/.ssh/authorized_keys && \
chmod 600 /root/.ssh/*

# install packages
RUN apt-get update && \
apt-get --yes --no-install-recommends install openssh-server=1:8.4p1-5+deb11u3 iproute2=5.10.0-4 iputils-ping=3:20210202-1 && \
apt-get clean && \
rm -rf /var/lib/apt/lists/*

# configure ssh
RUN mkdir /var/run/sshd && \
/bin/bash -o pipefail -c "echo \"root:security\" | chpasswd" && \
sed -i "s/#PermitRootLogin prohibit-password/PermitRootLogin yes/" /etc/ssh/sshd_config

# create entrypoint
COPY ./test_resources/entrypoint.sh.test /entrypoint.sh
RUN chmod +x /entrypoint.sh

ENTRYPOINT ["/entrypoint.sh"]

EXPOSE 22
EXPOSE 4369
EXPOSE 8022
20 changes: 18 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -14,15 +14,19 @@ DOTENV := $(shell grep -v '^\#' .env)
DEV_IMAGE_TAG = $(TEST_CONTAINER_NAME)-dev
DEV_IMAGE_ID = $(file < .image.dev)

TEST_IMAGE_TAG = $(DIST_CONTAINER_NAME)-test
TEST_IMAGE_ID = $(file < .image.test)

DOCKER ?= docker
DOCKERCOMPOSE ?= docker-compose
DOCKERCOMPOSE_W_ENV = DEV_IMAGE_TAG=$(DEV_IMAGE_TAG) $(DOCKERCOMPOSE) -f compose.yaml -f compose.tracing.yaml
REBAR ?= rebar3
TEST_CONTAINER_NAME ?= testrunner
DIST_CONTAINER_NAME ?= distrunner

all: compile xref lint check-format dialyze eunit

.PHONY: dev-image clean-dev-image wc-shell test
.PHONY: dev-image test-image clean-dev-image clean-test-image wc-shell test

dev-image: .image.dev

Expand All @@ -36,6 +40,18 @@ ifneq ($(DEV_IMAGE_ID),)
rm .image.dev
endif

test-image: .image.test

.image.test: Dockerfile.test .env
env $(DOTENV) $(DOCKERCOMPOSE_W_ENV) build $(DIST_CONTAINER_NAME)
$(DOCKER) image ls -q -f "reference=$(TEST_IMAGE_ID)" | head -n1 > $@

clean-test-image:
ifneq ($(TEST_IMAGE_ID),)
$(DOCKER) image rm -f $(TEST_IMAGE_TAG)
rm .image.test
endif

DOCKER_WC_OPTIONS := -v $(PWD):$(PWD) --workdir $(PWD)
DOCKER_WC_EXTRA_OPTIONS ?= --rm
DOCKER_RUN = $(DOCKER) run -t $(DOCKER_WC_OPTIONS) $(DOCKER_WC_EXTRA_OPTIONS)
Expand Down Expand Up @@ -87,7 +103,7 @@ eunit:
$(REBAR) eunit --cover

common-test:
$(REBAR) ct --cover --name test_node@127.0.0.1
$(REBAR) ct --cover

cover:
$(REBAR) covertool generate
Expand Down
16 changes: 10 additions & 6 deletions apps/mg/src/mg_configurator.erl
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@

-type pulse() :: mg_core_pulse:handler().

-type scaling_opts() :: #{scaling := mg_core_cluster:scaling_type()}.

-spec construct_child_specs(config()) -> [supervisor:child_spec()].
construct_child_specs(
#{
Expand All @@ -46,14 +48,15 @@ construct_child_specs(
Quotas = maps:get(quotas, Config, []),
HealthChecks = maps:get(health_check, Config, #{}),
ClusterOpts = maps:get(cluster, Config, #{}),
Scaling = maps:get(scaling, ClusterOpts, global_based),

QuotasChildSpec = quotas_child_specs(Quotas, quota),
EventMachinesChildSpec = events_machines_child_specs(Namespaces, Pulse),
WoodyServerChildSpec = mg_woody:child_spec(
woody_server,
#{
pulse => Pulse,
automaton => api_automaton_options(Namespaces, Pulse),
automaton => api_automaton_options(Namespaces, Pulse, #{scaling => Scaling}),
woody_server => WoodyServer,
additional_routes => [
get_startup_route(),
Expand All @@ -62,7 +65,7 @@ construct_child_specs(
]
}
),
ClusterSpec = mg_core_union:child_spec(ClusterOpts),
ClusterSpec = mg_core_cluster:child_spec(ClusterOpts),

lists:flatten([
QuotasChildSpec,
Expand Down Expand Up @@ -129,7 +132,8 @@ machine_options(NS, Config, Pulse) ->
Options = maps:with(
[
retries,
timer_processing_timeout
timer_processing_timeout,
scaling
],
Config
),
Expand All @@ -150,8 +154,8 @@ machine_options(NS, Config, Pulse) ->
suicide_probability => maps:get(suicide_probability, Config, undefined)
}.

-spec api_automaton_options(namespaces(), pulse()) -> mg_woody_automaton:options().
api_automaton_options(NSs, Pulse) ->
-spec api_automaton_options(namespaces(), pulse(), scaling_opts()) -> mg_woody_automaton:options().
api_automaton_options(NSs, Pulse, ScalingOpts) ->
maps:fold(
fun(NS, ConfigNS, Options) ->
Options#{
Expand All @@ -163,7 +167,7 @@ api_automaton_options(NSs, Pulse) ->
)
}
end,
#{},
ScalingOpts,
NSs
).

Expand Down
7 changes: 6 additions & 1 deletion apps/mg/src/mg_health_check.erl
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,11 @@

-export([global/0]).
-export([startup/0]).
-export([skip/0]).

-spec global() -> {erl_health:status(), erl_health:details()}.
global() ->
ClusterSize = mg_core_union:cluster_size(),
ClusterSize = mg_core_cluster:cluster_size(),
ConnectedCount = erlang:length(erlang:nodes()),
case is_quorum(ClusterSize, ConnectedCount) of
true ->
Expand All @@ -21,6 +22,10 @@ global() ->
startup() ->
%% maybe any checks?
logger:info("union. node ~p started", [node()]),
skip().

-spec skip() -> {erl_health:status(), erl_health:details()}.
skip() ->
{passing, []}.

%% Internal functions
Expand Down
1 change: 1 addition & 0 deletions apps/mg/test/mg_tests_SUITE.erl
Original file line number Diff line number Diff line change
Expand Up @@ -241,6 +241,7 @@ mg_config(#{endpoint := {IP, Port}}, C) ->
storage => {exponential, infinity, 1, 10},
timers => {exponential, infinity, 1, 10}
},
scaling => global_based,
% сейчас существуют проблемы, которые не дают включить на постоянной основе эту опцию
% (а очень хочется, чтобы проверять работоспособность идемпотентных ретраев)
% TODO в будущем нужно это сделать
Expand Down
Loading