Skip to content

Commit

Permalink
Merge pull request #54 from bancolombia/feature/externalize-config
Browse files Browse the repository at this point in the history
Externalized app configuration
  • Loading branch information
gabheadz authored Aug 8, 2023
2 parents 8a87c39 + 61cac47 commit c82a048
Show file tree
Hide file tree
Showing 34 changed files with 560 additions and 309 deletions.
10 changes: 7 additions & 3 deletions channel-sender/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ RUN export MIX_ENV=${BUILD_ENV} && \
# Extract Release archive to /rel for copying in next stage
RUN RELEASE_FILE=`ls -d _build/${BUILD_ENV}/*.gz` && \
mkdir /export && \
cp container_utils/runner.sh /export && \
tar -xf "${RELEASE_FILE}" -C /export

#===================
Expand All @@ -41,11 +42,14 @@ RUN apk upgrade --no-cache && \

RUN addgroup -S adfuser && adduser -S adfuser -G adfuser

WORKDIR /home/adfuser
WORKDIR /app

COPY --from=build --chown=adfuser:adfuser /export/ .

USER adfuser

ENTRYPOINT ["/home/adfuser/bin/channel_sender_ex"]
CMD ["start"]
VOLUME /app/config

ENTRYPOINT ["/bin/bash"]
CMD ["/app/runner.sh"]

4 changes: 2 additions & 2 deletions channel-sender/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ mix compile

### Configuration

Open and edit the config/dev.exs file to configure, you can create and set new environment files.
Open and edit the `config.yaml` file to set up configurations.
| **Parameters** | Description | Default Value |
| -------------------------------- | -------------------------------------- | ------------------ |
| `socket_port` | Port to atend Web Sockets requests | 8082 |
Expand Down Expand Up @@ -63,7 +63,7 @@ $ MIX_ENV=<CONFIG-FILE-NAME> iex --erl "-name [email protected]" -S mix

ADF Sender incorporate `libcluster` dependency in order to facilitate the automatic configuration of erlang clusters in kubernetes.

In folder `deploy_samples\k8s` we have included manifests to deploy ADF sender on kubernetes (and also if istio is present).
In folder [deploy_samples\k8s](./deploy_samples/k8s/README.md) we have included manifests to deploy ADF sender on kubernetes (and also if istio is present), using 3 of the strategies supported by `libcluster`.

## Clients

Expand Down
30 changes: 30 additions & 0 deletions channel-sender/config/config-local.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
channel_sender_ex:
rest_port: 8081
socket_port: 8082
secret_generator:
base: "aV4ZPOf7T7HX6GvbhwyBlDM8B9jfeiwi+9qkBnjXxUZXqAeTrehojWKHkV3U0kGc"
salt: "socket auth"
max_age: 900
initial_redelivery_time: 900
socket_idle_timeout: 30000
channel_shutdown_tolerance: 10000
min_disconnection_tolerance: 50
on_connected_channel_reply_timeout: 2000
accept_channel_reply_timeout: 1000
no_start: false
topology:
strategy: Elixir.Cluster.Strategy.Kubernetes
config:
mode: :hostname
kubernetes_ip_lookup_mode: :pods
kubernetes_service_name: "adfsender-headless"
kubernetes_node_basename: "channel_sender_ex"
kubernetes_selector: "cluster=beam"
namespace: "sendernm"
polling_interval: 5000

logger:
level: debug



3 changes: 0 additions & 3 deletions channel-sender/config/config.exs
Original file line number Diff line number Diff line change
@@ -1,11 +1,8 @@
import Config

config :channel_sender_ex,
channel_supervisor_module: Horde.DynamicSupervisor,
registry_module: Horde.Registry,
app_repo: ChannelSenderEx.Repository.ApplicationRepo,
channel_shutdown_tolerance: 10_000,
no_start: false,
min_disconnection_tolerance: 50,
socket_event_bus: ChannelSenderEx.Core.PubSub.SocketEventBus

Expand Down
11 changes: 1 addition & 10 deletions channel-sender/config/dev.exs
Original file line number Diff line number Diff line change
@@ -1,13 +1,4 @@
import Config

config :channel_sender_ex,
secret_base:
{"aV4ZPOf7T7HX6GvbhwyBlDM8B9jfeiwi+9qkBnjXxUZXqAeTrehojWKHkV3U0kGc", "socket auth"},
socket_port: 8082,
initial_redelivery_time: 900,
socket_idle_timeout: 30000,
rest_port: 8081,
max_age: 900,
topology: [
strategy: Cluster.Strategy.Gossip
]
config_file: "./config/config-local.yaml"
12 changes: 2 additions & 10 deletions channel-sender/config/dev1.exs
Original file line number Diff line number Diff line change
@@ -1,13 +1,5 @@
import Config


config :channel_sender_ex,
secret_base:
{"aV4ZPOf7T7HX6GvbhwyBlDM8B9jfeiwi+9qkBnjXxUZXqAeTrehojWKHkV3U0kGc", "socket auth"},
socket_port: 8092,
initial_redelivery_time: 900,
socket_idle_timeout: 30000,
rest_port: 8091,
max_age: 900,
topology: [
strategy: Cluster.Strategy.Gossip
]
config_file: "./config/config-local1.yaml"
11 changes: 1 addition & 10 deletions channel-sender/config/dev2.exs
Original file line number Diff line number Diff line change
@@ -1,13 +1,4 @@
import Config

config :channel_sender_ex,
secret_base:
{"aV4ZPOf7T7HX6GvbhwyBlDM8B9jfeiwi+9qkBnjXxUZXqAeTrehojWKHkV3U0kGc", "socket auth"},
socket_port: 8072,
initial_redelivery_time: 900,
socket_idle_timeout: 30000,
rest_port: 8071,
max_age: 900,
topology: [
strategy: Cluster.Strategy.Gossip
]
config_file: "./config/config-local2.yaml"
8 changes: 1 addition & 7 deletions channel-sender/config/prod.exs
Original file line number Diff line number Diff line change
@@ -1,10 +1,4 @@
import Config

config :channel_sender_ex,
secret_base:
{"aV4ZPOf7T7HX6GvbhwyBlDM8B9jfeiwi+9qkBnjXxUZXqAeTrehojWKHkV3U0kGc", "socket auth"},
socket_port: 8082,
initial_redelivery_time: 900,
socket_idle_timeout: 30000,
rest_port: 8081,
max_age: 900
config_file: "/app/config/config.yaml"
24 changes: 0 additions & 24 deletions channel-sender/config/runtime.exs

This file was deleted.

12 changes: 12 additions & 0 deletions channel-sender/container_utils/runner.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
#!/bin/sh

trap "echo; exit" INT

# load any needed env vars
File=/app/config/env.sh
if test -f "$File"; then
. $File
fi

# run release
/app/bin/channel_sender_ex start
2 changes: 1 addition & 1 deletion channel-sender/deploy_samples/k8s/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ The demo templates rely on [libcluster](https://hexdocs.pm/libcluster/readme.htm

These templates also asume istio is installed and enforcing mtls cluster-wide.

## Folders
## Strategies

a. [libcluster-kubernetes](./libcluster-kubernetes/README.md): Templates for deploying sender using `libcluster` strategy `Cluster.Strategy.Kubernetes`.

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -110,46 +110,55 @@ Building an Erlang Cluster with `libcluster` strategy named: [`Cluster.Strategy

### 2.1. ADF Sender configuration

a. **Topology config**

You can set topology related configuration in `config\runtime.exs`:

```elixir
import Config
config :logger, level: :info
config :channel_sender_ex,
secret_base:
{"aV4ZPOf7T7HX6GvbhwyBlDM8B9jfeiwi+9qkBnjXxUZXqAeTrehojWKHkV3U0kGc", "socket auth"},
socket_port: 8082,
initial_redelivery_time: 900,
socket_idle_timeout: 30000,
rest_port: 8081,
max_age: 900,
topology: [
strategy: Elixir.Cluster.Strategy.Kubernetes.DNS,
config: [
service: "adfsender-headless"
application_name: "channel_sender_ex"
namespace: "sendernm"
polling_interval: 5000
]
]
a. **Basic Sender Configuration**

You can provide all sender configuration via a yaml file.

For containers using prod release, path should be: `/app/config/config.yaml` for mounting the file.

config.yaml:
```yaml
channel_sender_ex:
rest_port: 8081
socket_port: 8082
secret_generator:
base: "aV4ZPOf7T7HX6GvbhwyBlDM8B9jfeiwi+9qkBnjXxUZXqAeTrehojWKHkV3U0kGc"
salt: "socket auth"
max_age: 900
initial_redelivery_time: 900
socket_idle_timeout: 30000
channel_shutdown_tolerance: 10000
min_disconnection_tolerance: 50
on_connected_channel_reply_timeout: 2000
accept_channel_reply_timeout: 1000
no_start: false
# --- libcluster related config ---
topology:
strategy: Elixir.Cluster.Strategy.Kubernetes
config:
service: "adfsender-headless"
application_name: "channel_sender_ex"
namespace: "sendernm"
polling_interval: 5000
# --- end libcluster configuration ---
logger:
level: debug
```
where:

Note the specifics in the libcluster configuration:

- `service` it's the headless service name defined in `app.yaml`.
- `application_name` it's the elixir release name. See `mix.exs`. Default release name is `channel_sender_ex`.
- `namespace`: namespace where sender is being deployed.

b. **Define related env vars for release**

via `rel/env.sh.eex` file:
You must mount a file in the following path `/app/config/env.sh`, performing any env configuration:

```elixir
```bash
export RELEASE_DISTRIBUTION=name
export RELEASE_NODE=<%= @release.name %>@${POD_IP}
export RELEASE_NODE=channel_sender_ex@${POD_IP}
```

check env var POD_IP being injected in `app.yaml`.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ spec:
spec:
containers:
- name: adfsender
image: bancolombia/async-dataflow-channel-sender:0.1.4
image: bancolombia/async-dataflow-channel-sender:0.1.5
env:
- name: POD_IP
valueFrom:
Expand Down Expand Up @@ -90,11 +90,11 @@ spec:
memory: 250M
volumeMounts:
- name: config-volume
mountPath: /home/adfuser/releases/0.1.4/env.sh
mountPath: /app/config/env.sh
subPath: env.sh
- name: config-volume
mountPath: /home/adfuser/releases/0.1.4/runtime.exs
subPath: runtime.exs
mountPath: /app/config/config.yaml
subPath: config.yaml
volumes:
- name: config-volume
configMap:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,26 +8,28 @@ data:
#!/bin/sh
export RELEASE_DISTRIBUTION=name
export RELEASE_NODE=channel_sender_ex@${POD_IP}
runtime.exs: |-
import Config
config :channel_sender_ex,
secret_base:
{"aV4ZPOf7T7HX6GvbhwyBlDM8B9jfeiwi+9qkBnjXxUZXqAeTrehojWKHkV3U0kGc", "socket auth"},
socket_port: 8082,
initial_redelivery_time: 900,
socket_idle_timeout: 30000,
rest_port: 8091,
max_age: 900,
# libcluster topology for this demostration.
# To see other topologies supported by libcluster
# see library documentation.
topology: [
strategy: Cluster.Strategy.Kubernetes.DNS,
config: [
service: "adfsender-headless",
application_name: "channel_sender_ex",
namespace: "sendernm",
config.yaml: |-
channel_sender_ex:
rest_port: 8081
socket_port: 8082
secret_generator:
base: "aV4ZPOf7T7HX6GvbhwyBlDM8B9jfeiwi+9qkBnjXxUZXqAeTrehojWKHkV3U0kGc"
salt: "socket auth"
max_age: 900
initial_redelivery_time: 900
socket_idle_timeout: 30000
channel_shutdown_tolerance: 10000
min_disconnection_tolerance: 50
on_connected_channel_reply_timeout: 2000
accept_channel_reply_timeout: 1000
no_start: false
topology:
strategy: Elixir.Cluster.Strategy.Kubernetes.DNS
config:
service: "adfsender-headless"
application_name: "channel_sender_ex"
namespace: "sendernm"
polling_interval: 5000
]
]
logger:
level: debug
Loading

0 comments on commit c82a048

Please sign in to comment.