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

feat: dockerize elixir services #757

Merged
merged 1 commit into from
Aug 2, 2023
Merged
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
40 changes: 1 addition & 39 deletions Tiltfile
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ docker_compose([
"./docker-compose.dotnet.yml",
"./docker-compose.python.yml",
"./docker-compose.web.yml",
"./docker-compose.elixir.yml",
"./docker-compose.node.yml"])

# populate redis for message services that use redis
Expand Down Expand Up @@ -108,61 +109,22 @@ def launch_ruby_name_service(auto_init=True):
def launch_ruby_year_service(auto_init=True):
launch_ruby_svc("year-rb", "ruby/year-service", "puma --port 6001", auto_init=auto_init)

def launch_elixir_svc(name, dirname="", cmd="", auto_init=True):
'''
Starts a single Elixir service.

Parameters:
name: used to display the name of the process in the tilt tab
dirname: (optional) directory name in which to run the app defaults to 'name'
flags: (optional) any additional flags to add to the command line

'''

# env = {'SERVICE_NAME': name}

setup_cmd = "cd {} && mix local.hex --force && mix local.rebar --force && mix deps.get && mix deps.compile".format(
dirname if dirname else name,
)
serve_cmd = "cd {} && mix {}".format(dirname, cmd)

if "elixir" in to_run or name in to_run:
print("About to start {} with command {}".format(name, serve_cmd))

local_resource(name, setup_cmd, auto_init=auto_init, serve_cmd=serve_cmd)

def launch_elixir_frontend(auto_init=True):
launch_elixir_svc("frontend-elixir", dirname="elixir/frontend", cmd="phx.server", auto_init=auto_init)

def launch_elixir_message_service(auto_init=True):
launch_elixir_svc("message-elixir", dirname="elixir/message", cmd="run --no-halt", auto_init=auto_init)

def launch_elixir_name_service(auto_init=True):
launch_elixir_svc("name-elixir", dirname="elixir/name", cmd="run --no-halt", auto_init=auto_init)

def launch_elixir_year_service(auto_init=True):
launch_elixir_svc("year-elixir", dirname="elixir/year", cmd="run --no-halt", auto_init=auto_init)

# Launch all services so that all service resources are registered with Tilt

# Other services use docker

# Server services
launch_go_frontend()
launch_ruby_frontend()
launch_elixir_frontend()

launch_go_message_service()
launch_ruby_message_service()
launch_elixir_message_service()

launch_go_name_service()
launch_ruby_name_service()
launch_elixir_name_service()

launch_go_year_service()
launch_ruby_year_service()
launch_elixir_year_service()

# Create map of "groups" of services to commonly run together (e.g. all node services)
supported_languages = ["go", "python", "rb", "java", "dotnet", "node", "elixir"]
Expand Down
56 changes: 56 additions & 0 deletions docker-compose.elixir.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
version: "2.4"

# noinspection ComposeUnknownKeys
x-common-env: &common-env
HONEYCOMB_API_KEY:
HONEYCOMB_DATASET:
HONEYCOMB_API:
OTEL_EXPORTER_OTLP_ENDPOINT:
OTEL_EXPORTER_OTLP_HEADERS:
OTEL_RESOURCE_ATTRIBUTES: app.running-in=docker
MESSAGE_ENDPOINT: message-service:9000
NAME_ENDPOINT: name-service:8000
YEAR_ENDPOINT: year-service:6001
REDIS_URL: redis
OTEL_COLLECTOR_HOST: collector

services:
frontend-elixir:
container_name: frontend-service
build: ./elixir/frontend
image: hnyexample/frontend-elixir
environment:
<<: *common-env
OTEL_SERVICE_NAME: frontend-elixir
ports:
- 7777:7777

message-elixir:
container_name: message-service
build: ./elixir/message
image: hnyexample/message-elixir
environment:
<<: *common-env
SERVICE_NAME: message-elixir
ports:
- 9000:9000

name-elixir:
container_name: name-service
build: ./elixir/name
image: hnyexample/name-elixir
environment:
<<: *common-env
SERVICE_NAME: name-elixir
ports:
- 8000:8000

year-elixir:
container_name: year-service
build: ./elixir/year
image: hnyexample/year-elixir
environment:
<<: *common-env
SERVICE_NAME: year-elixir
ports:
- 6001:6001
14 changes: 4 additions & 10 deletions elixir/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,9 @@
- Name: Service that chooses a random name.
- Year: Service that returns a random year.

## How to run
## How to run without Tilt/Docker

See top-level README.md for instructions on how to run services with Tilt and Docker (easiest).

### Install Elixir
If using option 1 or 3 below, make sure you have Elixir installed. The preferred way to install Elixir is with [asdf](https://asdf-vm.com/guide/getting-started.html#_1-install-dependencies).
Expand All @@ -26,7 +28,7 @@ asdf install erlang <insert-version-here>
asdf install elixir <insert-version-here>
```

### Option 1: One service at a time
### Run each service

Install dependencies in the service directory

Expand All @@ -48,14 +50,6 @@ Message/Name/Year:
mix run --no-halt
```

### Option 2: All Elixir Services via Docker

In the Elixir directory run `docker-compose up -- build`.

### Option 3: All Elixir Servies via Tilt

In the top level directory run `tilt up elixir`

## See it in action

`curl localhost:7777/greeting` for greeting
Expand Down
36 changes: 0 additions & 36 deletions elixir/docker-compose.yml

This file was deleted.