Skip to content
This repository was archived by the owner on Jan 11, 2022. It is now read-only.
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
21 changes: 20 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ Added advantages of building over Kubernetes,

### Using dashboard

The dashboard/platform is called Bridge
The dashboard is called **Bridge**

[Bridge url](`http://localhost:4000`)

Expand All @@ -127,12 +127,31 @@ The dashboard/platform is called Bridge
- Each app will be having an dedicated url to Discovery.
- Clients use this dedicated endpoint url to get the app's endpoint. (As specified in `Approach` section).

![create-app](doc_assets/create-app.gif?raw=true "scale app")

#### Deploying and managing an app

- When deploying an app, we have to specify the docker image name (which should be public as of now).
- Bridge shows each app's deployment logs/activites.
- Deployment CRUD operations to app are available as button clicks.

![scale-app](doc_assets/scale-app.gif?raw=true "create app")

#### Fetching latest server URL from Discovery

- Client will hit Discovery API, and get the latest server endpoint url.

```
GET - http://localhost:4000/api/get-endpoint?app_name=nightwatch

RESPONSE -
{
"endpoint": "nightwatch.minikube.com/9d00cc18"
}

```


## Demo time

### Things to note
Expand Down
Binary file added doc_assets/create-app.gif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added doc_assets/scale-app.gif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
12 changes: 12 additions & 0 deletions lib/discovery/bridge/bridge_utils.ex
Original file line number Diff line number Diff line change
Expand Up @@ -63,4 +63,16 @@ defmodule Discovery.Bridge.BridgeUtils do
deployment_details
|> DeployManager.create()
end

@doc """
Get latest deployment details of an app

Returns {:ok, term} | {:error, reason}
"""
@spec get_latest_deployment(String.t()) :: map()
def get_latest_deployment(app_name) do
app_name
|> get_deployment_data()
|> List.first()
end
end
8 changes: 6 additions & 2 deletions lib/discovery/deploy/deploy_utils.ex
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@ defmodule Discovery.Deploy.DeployUtils do

@type t :: %DeployUtils{
app_name: String.t(),
app_image: String.t()
app_image: String.t(),
replicas: Integer
}

@type app :: %{
Expand All @@ -20,7 +21,8 @@ defmodule Discovery.Deploy.DeployUtils do

defstruct(
app_name: "",
app_image: ""
app_image: "",
replicas: 1
)

@doc """
Expand All @@ -35,6 +37,7 @@ defmodule Discovery.Deploy.DeployUtils do
app_details = %{
app_name: deployment_details.app_name,
app_image: deployment_details.app_image,
replicas: deployment_details.replicas,
uid: uid
}

Expand Down Expand Up @@ -196,6 +199,7 @@ defmodule Discovery.Deploy.DeployUtils do
String.replace(deploy_template, "APP_NAME", app.app_name)
|> String.replace("UID", app.uid)
|> String.replace("APP_IMAGE", app.app_image)
|> String.replace("APP_REPLICA", "#{app.replicas}")

case File.open("minikube/discovery/#{app.app_name}/#{app.app_name}-#{app.uid}/deploy.yml", [
:write,
Expand Down
46 changes: 44 additions & 2 deletions lib/discovery_web/live/page_live.ex
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ defmodule DiscoveryWeb.PageLive do
selected_app: nil,
create_modal_display: "none",
deploy_modal_display: "none",
scale_modal_display: "none",
create_app_warning: "none",
deploy_app_warning: "none",
modal_input?: true,
Expand Down Expand Up @@ -52,7 +53,30 @@ defmodule DiscoveryWeb.PageLive do
if socket.assigns.modal_input? do
%{
app_name: socket.assigns.selected_app,
app_image: app_image
app_image: app_image,
replicas: 1
}
|> create_deployment()
end

socket =
socket
|> assign(modal_input?: false)

{:noreply, socket}
end

@impl true
def handle_event("update-replica", %{"app-replica" => replica_count} = _params, socket) do
latest_deployment =
socket.assigns.selected_app
|> BridgeUtils.get_latest_deployment()

if socket.assigns.modal_input? do
%{
app_name: socket.assigns.selected_app,
app_image: latest_deployment["image"],
replicas: replica_count |> String.to_integer()
}
|> create_deployment()
end
Expand Down Expand Up @@ -109,6 +133,22 @@ defmodule DiscoveryWeb.PageLive do
{:noreply, socket}
end

@impl true
def handle_event("show-scale-modal", _params, socket) do
display =
case socket.assigns.scale_modal_display do
"none" -> "block"
"block" -> "none"
_ -> "none"
end

socket =
socket
|> assign(scale_modal_display: display, modal_input?: true)

{:noreply, socket}
end

@impl true
def handle_event("hide-modal", _params, socket) do
socket =
Expand All @@ -117,6 +157,7 @@ defmodule DiscoveryWeb.PageLive do
create_modal_display: "none",
deploy_modal_display: "none",
deploy_app_warning: "none",
scale_modal_display: "none",
modal_input?: true
)

Expand Down Expand Up @@ -147,6 +188,7 @@ defmodule DiscoveryWeb.PageLive do
assign(
socket,
deploy_modal_display: "none",
scale_modal_display: "none",
deploy_app_warning: "none",
selected_app_details: selected_app_details,
apps: get_apps()
Expand Down Expand Up @@ -175,7 +217,7 @@ defmodule DiscoveryWeb.PageLive do
Process.send_after(
self(),
{"deployment-created", %{status: deployment_status, app_name: app_name}},
2000
10_000
)
end
end
41 changes: 40 additions & 1 deletion lib/discovery_web/live/page_live.html.leex
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,45 @@
</div>
</section>

<section id="create-modal" style="display:<%= @scale_modal_display %>">
<div class="fixed z-10 inset-0 overflow-y-auto" aria-labelledby="modal-title" role="dialog" aria-modal="true">
<div class="flex items-end justify-center min-h-screen pt-4 px-4 pb-20 text-center sm:block sm:p-0">
<div class="fixed inset-0 bg-gray-500 bg-opacity-75 transition-opacity" aria-hidden="true"></div>

<span class="hidden sm:inline-block sm:align-middle sm:h-screen" aria-hidden="true">&#8203;</span>

<div class="inline-block align-bottom bg-white rounded-lg text-left overflow-hidden shadow-xl transform transition-all sm:my-8 sm:align-middle sm:max-w-lg sm:w-full">
<div class="bg-white px-4 pt-5 pb-4 sm:p-6 sm:pb-4">
<div class="sm:flex sm:items-start">

<div class="mt-3 text-center sm:mt-0 sm:ml-4 sm:text-left">
<h3 class="text-lg leading-6 font-medium text-gray-900" id="modal-title">
Update Replica Count
</h3>
<div class="mt-2">
<p class="text-sm text-gray-500">
Please enter the replica count for the latest deployment.
</p>
</div>
</div>
</div>
</div>
<div class="bg-gray-50 px-4 py-3 sm:px-6 sm:flex sm:flex-row-reverse">
<form phx-submit="update-replica">
<input type="number" min="1" class="py-2 px-8 bg-white-500 text-black rounded-lg hover:bg-grey-700 border border-black-600" name="app-replica" value="<%= @query %>" placeholder="1" required>
<button type="submit" class="w-full inline-flex justify-center rounded-md border border-transparent shadow-sm px-4 py-2 bg-indigo-600 text-base font-medium text-white hover:bg-indigo-700 focus:outline-none focus:ring-2 focus:ring-offset-2 focus:ring-indigo-500 sm:ml-3 sm:w-auto sm:text-sm">
Create
</button>
<button id="cancel-btn"type="button" phx-click="hide-modal" onClick class="mt-3 w-full inline-flex justify-center rounded-md border border-gray-300 shadow-sm px-4 py-2 bg-white text-base font-medium text-gray-700 hover:bg-gray-50 focus:outline-none focus:ring-2 focus:ring-offset-2 focus:ring-indigo-500 sm:mt-0 sm:ml-3 sm:w-auto sm:text-sm">
Cancel
</button>
</form>
</div>
</div>
</div>
</div>
</section>


<div class="flex flex-row">

Expand All @@ -90,7 +129,7 @@
<div class="flex flex-row space-x-6">
<button type="button" phx-click="back" class="py-2 px-4 bg-indigo-500 text-white font-semibold rounded-lg shadow-md hover:bg-indigo-700 focus:outline-none">Back</button>
<button type="button" phx-click="show-deploy-modal" class="py-2 px-4 bg-indigo-500 text-white font-semibold rounded-lg shadow-md hover:bg-indigo-700 focus:outline-none">Deploy</button>
<button onmouseenter="openPopover(event,'popover-id')" onmouseleave="openPopover(event,'popover-id')" aria-labelledby="coming soon" type="button" class="py-2 px-4 bg-opacity-75 bg-indigo-500 text-white font-semibold rounded-lg shadow-md hover:bg-indigo-700 focus:outline-none">Scale</button>
<button type="button" phx-click="show-scale-modal" class="py-2 px-4 bg-indigo-500 text-white font-semibold rounded-lg shadow-md hover:bg-indigo-700 focus:outline-none">Scale</button>
<button onmouseenter="openPopover(event,'popover-id')" onmouseleave="openPopover(event,'popover-id')" aria-labelledby="coming soon" type="button" class="py-2 px-4 bg-opacity-75 bg-pink-500 text-white font-semibold rounded-lg shadow-md hover:bg-pink-700 focus:outline-none">Delete</button>
<div class="hidden block z-50 font-mono text-sm text-left rounded-lg" id="popover-id">
<div>
Expand Down
2 changes: 1 addition & 1 deletion priv/templates/deploy.yml.eex
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ metadata:
annotations:
app_id: "APP_NAME"
spec:
replicas: 1
replicas: APP_REPLICA
strategy:
type: RollingUpdate
rollingUpdate:
Expand Down