Skip to content

Commit a56df83

Browse files
Add empty server implementation, tested locally
1 parent b4a358f commit a56df83

File tree

4 files changed

+85
-1
lines changed

4 files changed

+85
-1
lines changed

ee/ephemeral_environments/Makefile

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,9 @@ ifdef CI
2323
sem-service start postgres 9.6 --db=$(POSTGRES_DB_NAME) --user=$(POSTGRES_DB_USER) --password=$(POSTGRES_DB_PASSWORD)
2424
endif
2525

26+
console.ex:
27+
docker compose run --service-ports $(CONTAINER_ENV_VARS) --rm app sh -c "mix ecto.create && mix ecto.migrate && iex -S mix"
28+
2629
migration.gen:
2730
@if [ -z "$(NAME)" ]; then \
2831
echo "Usage: make migration.gen NAME={migration_name}"; \

ee/ephemeral_environments/lib/ephemeral_environments/application.ex

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,16 @@ defmodule EphemeralEnvironments.Application do
99
"Starting EphemeralEnvironments in '#{Application.get_env(:ephemeral_environments, :env)}' environment"
1010
)
1111

12-
children = [EphemeralEnvironments.Repo]
12+
grpc_port = Application.get_env(:ephemeral_environments, :grpc_listen_port)
13+
14+
children = [
15+
EphemeralEnvironments.Repo,
16+
{GRPC.Server.Supervisor,
17+
servers: [EphemeralEnvironments.Grpc.EphemeralEnvironmentsServer],
18+
port: Application.get_env(:ephemeral_environments, :grpc_listen_port),
19+
start_server: true,
20+
adapter_opts: [ip: {0, 0, 0, 0}]}
21+
]
1322

1423
opts = [strategy: :one_for_one, name: EphemeralEnvironments.Supervisor]
1524
Enum.each(children, fn child -> Logger.info("Starting #{inspect(child)}") end)
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
defmodule EphemeralEnvironments.Repo.EphemeralEnvironmentType do
2+
use Ecto.Schema
3+
import Ecto.Changeset
4+
5+
@primary_key {:id, :binary_id, autogenerate: true}
6+
@foreign_key_type :binary_id
7+
8+
schema "ephemeral_environment_types" do
9+
field :org_id, :binary_id
10+
field :name, :string
11+
field :description, :string
12+
field :created_by, :binary_id
13+
field :last_modified_by, :binary_id
14+
field :state, :string
15+
field :max_number_of_instances, :integer
16+
17+
timestamps()
18+
end
19+
20+
@doc false
21+
def changeset(ephemeral_environment_type, attrs) do
22+
ephemeral_environment_type
23+
|> cast(attrs, [:org_id, :name, :description, :created_by, :last_modified_by, :state, :max_number_of_instances])
24+
|> validate_required([:org_id, :name, :created_by, :last_modified_by, :state])
25+
|> validate_length(:name, min: 1, max: 255)
26+
|> validate_length(:description, max: 1000)
27+
|> validate_inclusion(:state, [:draft, :ready, :cordoned, :deleted])
28+
|> validate_number(:max_number_of_instances, greater_than: 0)
29+
end
30+
end
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
defmodule EphemeralEnvironments.Grpc.EphemeralEnvironmentsServer do
2+
use GRPC.Server, service: InternalApi.EphemeralEnvironments.EphemeralEnvironments.Service
3+
4+
alias InternalApi.EphemeralEnvironments.{
5+
ListRequest,
6+
ListResponse,
7+
DescribeRequest,
8+
DescribeResponse,
9+
CreateRequest,
10+
CreateResponse,
11+
UpdateRequest,
12+
UpdateResponse,
13+
DeleteRequest,
14+
DeleteResponse,
15+
CordonRequest,
16+
CordonResponse
17+
}
18+
19+
def list(_request, _stream) do
20+
%ListResponse{}
21+
end
22+
23+
def describe(_request, _stream) do
24+
%DescribeResponse{}
25+
end
26+
27+
def create(_request, _stream) do
28+
%CreateResponse{}
29+
end
30+
31+
def update(_request, _stream) do
32+
%UpdateResponse{}
33+
end
34+
35+
def delete(_request, _stream) do
36+
%DeleteResponse{}
37+
end
38+
39+
def cordon(_request, _stream) do
40+
%CordonResponse{}
41+
end
42+
end

0 commit comments

Comments
 (0)