Okay that's about everything
This commit is contained in:
parent
023ad47ae4
commit
d094ff036f
19 changed files with 236 additions and 79 deletions
|
|
@ -11,12 +11,9 @@ module.exports = {
|
|||
"../lib/ezcontainer_railway_web.ex",
|
||||
"../lib/ezcontainer_railway_web/**/*.*ex"
|
||||
],
|
||||
theme: {
|
||||
extend: {
|
||||
colors: {
|
||||
brand: "#FD4F00",
|
||||
}
|
||||
},
|
||||
theme: {},
|
||||
daisyui: {
|
||||
themes: ["cupcake"]
|
||||
},
|
||||
plugins: [
|
||||
require("daisyui"),
|
||||
|
|
|
|||
|
|
@ -1,4 +1,5 @@
|
|||
defmodule EzcontainerRailway.Railway do
|
||||
alias EzcontainerRailway.Projects
|
||||
alias EzcontainerRailway.GraphqlClient
|
||||
def get_projects(token) do
|
||||
resp = GraphqlClient.query(
|
||||
|
|
@ -23,12 +24,89 @@ defmodule EzcontainerRailway.Railway do
|
|||
end
|
||||
end
|
||||
|
||||
def create_service(container, token) when is_map(container) do
|
||||
def get_services(token) do
|
||||
project_id = Projects.get_project_by_token(token).project_id
|
||||
resp = GraphqlClient.query(
|
||||
"""
|
||||
query getServices($projectId: String!) {
|
||||
project(id: $projectId) {
|
||||
services {
|
||||
edges {
|
||||
node {
|
||||
id
|
||||
name
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
""",
|
||||
token: token,
|
||||
variables: %{
|
||||
projectId: project_id
|
||||
}
|
||||
) |> format_response
|
||||
|
||||
case resp do
|
||||
{:error, _} -> resp
|
||||
{:ok, data} ->
|
||||
final =
|
||||
data["project"]["services"]["edges"]
|
||||
|> Enum.map(&(&1["node"]))
|
||||
|
||||
{:ok, final}
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
def create_service(source, type, token) do
|
||||
resp = case type do
|
||||
"repo" -> create_service_from_repo(source, token)
|
||||
"image" -> create_service_from_image(source, token)
|
||||
end
|
||||
|
||||
case resp do
|
||||
{:error, _} -> resp
|
||||
{:ok, data} -> {:ok, data["serviceCreate"]}
|
||||
end
|
||||
end
|
||||
|
||||
defp create_service_from_image(source, token) do
|
||||
project_id = Projects.get_project_by_token(token).project_id
|
||||
GraphqlClient.query(
|
||||
"""
|
||||
mutation createService($projectId: String!, $image: String!, $name: String!){
|
||||
serviceCreate(input: {projectId: $projectId, name: $name source: { image: $image }}) {
|
||||
id
|
||||
}
|
||||
}
|
||||
""",
|
||||
variables: container
|
||||
)
|
||||
token: token,
|
||||
variables: %{
|
||||
projectId: project_id,
|
||||
image: source,
|
||||
name: source
|
||||
}
|
||||
) |> format_response
|
||||
end
|
||||
|
||||
defp create_service_from_repo(source, token) do
|
||||
project_id = Projects.get_project_by_token(token).project_id
|
||||
GraphqlClient.query(
|
||||
"""
|
||||
mutation createService($projectId: String!, $repo: String!, $name: String!){
|
||||
serviceCreate(input: {projectId: $projectId, name: $name source: { repo: $repo }}) {
|
||||
id
|
||||
}
|
||||
}
|
||||
""",
|
||||
token: token,
|
||||
variables: %{
|
||||
projectId: project_id,
|
||||
repo: source,
|
||||
name: source
|
||||
}
|
||||
) |> format_response
|
||||
end
|
||||
|
||||
def create_project(token) do
|
||||
|
|
@ -51,6 +129,21 @@ defmodule EzcontainerRailway.Railway do
|
|||
end
|
||||
end
|
||||
|
||||
def delete_container(token, service_id) do
|
||||
GraphqlClient.query(
|
||||
"""
|
||||
mutation deleteContainer(id: String!) {
|
||||
serviceDelete(id: $id)
|
||||
}
|
||||
""",
|
||||
token: token,
|
||||
variables: %{
|
||||
id: service_id
|
||||
}
|
||||
)
|
||||
|> format_response
|
||||
end
|
||||
|
||||
def get_user_id(token) do
|
||||
{:ok, resp} = GraphqlClient.query(
|
||||
"""
|
||||
|
|
|
|||
|
|
@ -1,32 +1,27 @@
|
|||
<header class="px-4 sm:px-6 lg:px-8">
|
||||
<div class="flex items-center justify-between border-b border-zinc-100 py-3 text-sm">
|
||||
<div class="flex items-center gap-4">
|
||||
<a href="/">
|
||||
<img src={~p"/images/logo.svg"} width="36" />
|
||||
</a>
|
||||
<p class="bg-brand/5 text-brand rounded-full px-2 font-medium leading-6">
|
||||
v<%= Application.spec(:phoenix, :vsn) %>
|
||||
</p>
|
||||
<%= live_flash(@flash, :error) %>
|
||||
<%= live_flash(@flash, :info) %>
|
||||
<body class="bg-base-300 font-sans leading-normal tracking-normal w-screen h-screen">
|
||||
<!-- Navbar -->
|
||||
<div class="bg-primary p-3">
|
||||
<div class="container mx-auto flex items-center">
|
||||
<!-- App Logo/Name -->
|
||||
<div class="flex items-center text-lg font-extrabold text-base-content">
|
||||
<a href="#" class="hover:underline">
|
||||
Your App Name
|
||||
</a>
|
||||
</div>
|
||||
|
||||
<!-- Navigation links -->
|
||||
<div class="flex ml-auto space-x-4">
|
||||
<a class="btn btn-ghost btn-sm rounded-btn" href="/containers/create">Create Containers</a>
|
||||
<a class="btn btn-ghost btn-sm rounded-btn" href="/containers">Show Containers</a>
|
||||
<a class="btn btn-ghost btn-sm rounded-btn" href="#">Logout</a>
|
||||
</div>
|
||||
</div>
|
||||
<div class="flex items-center gap-4 font-semibold leading-6 text-zinc-900">
|
||||
<a href="https://twitter.com/elixirphoenix" class="hover:text-zinc-700">
|
||||
@elixirphoenix
|
||||
</a>
|
||||
<a href="https://github.com/phoenixframework/phoenix" class="hover:text-zinc-700">
|
||||
GitHub
|
||||
</a>
|
||||
<a
|
||||
href="https://hexdocs.pm/phoenix/overview.html"
|
||||
class="rounded-lg bg-zinc-100 px-2 py-1 hover:bg-zinc-200/80"
|
||||
>
|
||||
Get Started <span aria-hidden="true">→</span>
|
||||
</a>
|
||||
</div>
|
||||
</div>
|
||||
</header>
|
||||
<main class="px-4 py-20 sm:px-6 lg:px-8">
|
||||
<div class="mx-auto max-w-2xl">
|
||||
<.flash_group flash={@flash} />
|
||||
</div>
|
||||
|
||||
<!-- Content Body -->
|
||||
<div class="container mx-auto mt-10">
|
||||
<%= @inner_content %>
|
||||
</div>
|
||||
</main>
|
||||
</div>
|
||||
</body>
|
||||
|
|
|
|||
|
|
@ -11,7 +11,5 @@
|
|||
<script defer phx-track-static type="text/javascript" src={~p"/assets/app.js"}>
|
||||
</script>
|
||||
</head>
|
||||
<body>
|
||||
<%= @inner_content %>
|
||||
</body>
|
||||
<%= @inner_content %>
|
||||
</html>
|
||||
|
|
|
|||
|
|
@ -1 +0,0 @@
|
|||
benbot@darch.125027:1698169376
|
||||
|
|
@ -1,13 +1,14 @@
|
|||
defmodule EzcontainerRailwayWeb.ContainerController do
|
||||
alias EzcontainerRailway.Railway
|
||||
alias Phoenix.Component
|
||||
use EzcontainerRailwayWeb, :controller
|
||||
|
||||
def index(conn, params) do
|
||||
form = Component.to_form(%{"container_name" => "", "container_tag" => ""})
|
||||
{:ok, services} = Railway.get_services(conn |> get_session(:railway_token))
|
||||
|
||||
conn
|
||||
|> assign(:form, form)
|
||||
|> render(:make_container, layout: false)
|
||||
|> assign(:services, services)
|
||||
|> render(:containers)
|
||||
end
|
||||
|
||||
def create(conn, params) do
|
||||
|
|
|
|||
|
|
@ -0,0 +1,13 @@
|
|||
<.flash_group flash={@flash} />
|
||||
<div class="grid grid-cols-3 m-10">
|
||||
<%= for service <- @services do %>
|
||||
<div class="card bg-base-100 shadow-xl">
|
||||
<div class="card-body">
|
||||
<h2 class="card-title"><%= service["name"] %></h2>
|
||||
<div class="card-actions justify-start">
|
||||
<button class="btn btn-xs btn-secondary">Delete</button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<% end %>
|
||||
</div>
|
||||
|
|
@ -1,5 +1,5 @@
|
|||
<.flash_group flash={@flash} />
|
||||
<dialog open class="modal">
|
||||
<dialog open class="modal bg-base-300">
|
||||
<article class="modal-box">
|
||||
<.form
|
||||
for={@form}
|
||||
|
|
@ -8,13 +8,13 @@
|
|||
action="/token"
|
||||
>
|
||||
<label class="label">
|
||||
<span class="label-text">What is your name?</span>
|
||||
<span class="label-text-alt">Top Right label</span>
|
||||
<span class="label-text">Enter your railway token</span>
|
||||
<a href="https://railway.app/account/tokens" class="label-text-alt underline">Get it here</a>
|
||||
</label>
|
||||
|
||||
<input class="input input-bordered" name="railway_token" />
|
||||
<div class="text-center mt-6">
|
||||
<button class="btn">Test</button>
|
||||
<button class="btn">Begin</button>
|
||||
</div>
|
||||
</.form>
|
||||
</article>
|
||||
|
|
|
|||
|
|
@ -1,39 +1,65 @@
|
|||
defmodule EzcontainerRailwayWeb.ContainerCreateLive do
|
||||
alias EzcontainerRailway.Railway
|
||||
alias Phoenix.Component
|
||||
use Phoenix.LiveView
|
||||
use EzcontainerRailwayWeb, :live_view
|
||||
|
||||
def render(assigns) do
|
||||
~H"""
|
||||
<%= live_flash(@flash, :error) %>
|
||||
<%= live_flash(@flash, :info) %>
|
||||
<dialog open class="modal">
|
||||
<article class="modal-box">
|
||||
<.form
|
||||
for={@form}
|
||||
method="post"
|
||||
action="/container"
|
||||
>
|
||||
<label class="label">
|
||||
<span class="label-text">Container Name</span>
|
||||
<span class="label-text-alt mr-20">Tag</span>
|
||||
</label>
|
||||
<div class="flex space-around w-full">
|
||||
<article>
|
||||
<%= if @target == "container" do %>
|
||||
<.form for={@form} phx-submit="create_container">
|
||||
<label class="label">
|
||||
<span class="label-text">Container Name</span>
|
||||
<span class="label-text-alt mr-20">Tag</span>
|
||||
</label>
|
||||
|
||||
<div class="grid grid-rows-1 grid-cols-4 gap-4">
|
||||
<input class="input input-bordered inline col-span-3" name="container_name" />
|
||||
<input class="input input-bordered inline" name="container_tag" />
|
||||
</div>
|
||||
<div class="text-center mt-6">
|
||||
<button class="btn">Test</button>
|
||||
</div>
|
||||
</.form>
|
||||
</article>
|
||||
</dialog>
|
||||
<div class="grid grid-rows-1 grid-cols-4 gap-4">
|
||||
<input class="input input-bordered inline col-span-3" name="name" />
|
||||
<input class="input input-bordered inline" name="tag" />
|
||||
</div>
|
||||
<div class="text-center mt-6">
|
||||
<button phx-submit class="btn btn-primary">CREATE</button>
|
||||
</div>
|
||||
<input type="hidden" name="target" value="container" />
|
||||
</.form>
|
||||
<% end %>
|
||||
<%= if @target == "repo" do %>
|
||||
<.form for={@form} phx-submit="create_container">
|
||||
<label class="label">
|
||||
<span class="label-text">Github Repo</span>
|
||||
<span class="label-text-alt mr-20">Branch</span>
|
||||
</label>
|
||||
|
||||
<div class="grid grid-rows-1 grid-cols-4 gap-4">
|
||||
<input class="input input-bordered inline col-span-3" name="name" />
|
||||
<input class="input input-bordered inline" name="tag" />
|
||||
</div>
|
||||
<div class="text-center mt-6">
|
||||
<button phx-submit class="btn btn-primary">CREATE</button>
|
||||
</div>
|
||||
<input type="hidden" name="target" value="repo" />
|
||||
</.form>
|
||||
<% end %>
|
||||
</article>
|
||||
</div>
|
||||
"""
|
||||
end
|
||||
|
||||
def mount(_params, _session, socket) do
|
||||
form = Component.to_form(%{"container_name" => "", "contianer_tag" => ""})
|
||||
def mount(_params, session, socket) do
|
||||
form = Component.to_form(%{"name" => "", "tag" => ""})
|
||||
|
||||
{:ok, socket |> assign(:form, form)}
|
||||
{:ok, socket |> assign(form: form, target: "container", session: session)}
|
||||
end
|
||||
|
||||
def handle_event("create_container", data, socket) do
|
||||
{:ok, resp} = Railway.create_service(
|
||||
data["name"],
|
||||
"image",
|
||||
socket.assigns.session["railway_token"]
|
||||
)
|
||||
|
||||
{:noreply, socket |> push_redirect('/containers')}
|
||||
end
|
||||
end
|
||||
|
|
|
|||
19
lib/ezcontainer_railway_web/plugs/no_railway_check.ex
Normal file
19
lib/ezcontainer_railway_web/plugs/no_railway_check.ex
Normal file
|
|
@ -0,0 +1,19 @@
|
|||
defmodule EzcontainerRailwayWeb.NoRailwayCheck do
|
||||
alias EzcontainerRailway.Projects
|
||||
alias Phoenix.Controller
|
||||
import Plug.Conn
|
||||
|
||||
def init(default), do: default
|
||||
|
||||
def call(conn, _opts) do
|
||||
case get_session(conn, :railway_token) do
|
||||
nil ->
|
||||
conn
|
||||
_ ->
|
||||
conn
|
||||
|> Controller.put_flash(:info, "You have a railway token")
|
||||
|> Controller.redirect(to: "/containers/create")
|
||||
|> halt()
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
@ -20,7 +20,7 @@ defmodule EzcontainerRailwayWeb.RailwayCheck do
|
|||
end
|
||||
|
||||
conn
|
||||
|> put_session(:project_id, p)
|
||||
|> put_session(:project_id, p.id)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
|||
|
|
@ -19,8 +19,13 @@ defmodule EzcontainerRailwayWeb.Router do
|
|||
plug EzcontainerRailwayWeb.RailwayCheck
|
||||
end
|
||||
|
||||
pipeline :ensure_no_token do
|
||||
plug EzcontainerRailwayWeb.NoRailwayCheck
|
||||
end
|
||||
|
||||
scope "/", EzcontainerRailwayWeb do
|
||||
pipe_through :browser
|
||||
pipe_through :ensure_no_token
|
||||
|
||||
get "/", PageController, :home
|
||||
post "/token", SessionController, :token
|
||||
|
|
@ -30,8 +35,8 @@ defmodule EzcontainerRailwayWeb.Router do
|
|||
pipe_through :browser
|
||||
pipe_through :ensure_token
|
||||
|
||||
live "/containers", ContainerCreateLive
|
||||
resources("/containers", ContainerController, only: [:create, :show])
|
||||
live "/containers/create", ContainerCreateLive
|
||||
resources("/containers", ContainerController, only: [:index, :create, :show])
|
||||
end
|
||||
|
||||
# Other scopes may use custom stacks.
|
||||
|
|
|
|||
BIN
priv/static/favicon-a8ca4e3a2bb8fea46a9ee9e102e7d3eb.ico
Normal file
BIN
priv/static/favicon-a8ca4e3a2bb8fea46a9ee9e102e7d3eb.ico
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 1.2 KiB |
|
|
@ -0,0 +1,6 @@
|
|||
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 71 48" fill="currentColor" aria-hidden="true">
|
||||
<path
|
||||
d="m26.371 33.477-.552-.1c-3.92-.729-6.397-3.1-7.57-6.829-.733-2.324.597-4.035 3.035-4.148 1.995-.092 3.362 1.055 4.57 2.39 1.557 1.72 2.984 3.558 4.514 5.305 2.202 2.515 4.797 4.134 8.347 3.634 3.183-.448 5.958-1.725 8.371-3.828.363-.316.761-.592 1.144-.886l-.241-.284c-2.027.63-4.093.841-6.205.735-3.195-.16-6.24-.828-8.964-2.582-2.486-1.601-4.319-3.746-5.19-6.611-.704-2.315.736-3.934 3.135-3.6.948.133 1.746.56 2.463 1.165.583.493 1.143 1.015 1.738 1.493 2.8 2.25 6.712 2.375 10.265-.068-5.842-.026-9.817-3.24-13.308-7.313-1.366-1.594-2.7-3.216-4.095-4.785-2.698-3.036-5.692-5.71-9.79-6.623C12.8-.623 7.745.14 2.893 2.361 1.926 2.804.997 3.319 0 4.149c.494 0 .763.006 1.032 0 2.446-.064 4.28 1.023 5.602 3.024.962 1.457 1.415 3.104 1.761 4.798.513 2.515.247 5.078.544 7.605.761 6.494 4.08 11.026 10.26 13.346 2.267.852 4.591 1.135 7.172.555ZM10.751 3.852c-.976.246-1.756-.148-2.56-.962 1.377-.343 2.592-.476 3.897-.528-.107.848-.607 1.306-1.336 1.49Zm32.002 37.924c-.085-.626-.62-.901-1.04-1.228-1.857-1.446-4.03-1.958-6.333-2-1.375-.026-2.735-.128-4.031-.61-.595-.22-1.26-.505-1.244-1.272.015-.78.693-1 1.31-1.184.505-.15 1.026-.247 1.6-.382-1.46-.936-2.886-1.065-4.787-.3-2.993 1.202-5.943 1.06-8.926-.017-1.684-.608-3.179-1.563-4.735-2.408l-.077.057c1.29 2.115 3.034 3.817 5.004 5.271 3.793 2.8 7.936 4.471 12.784 3.73A66.714 66.714 0 0 1 37 40.877c1.98-.16 3.866.398 5.753.899Zm-9.14-30.345c-.105-.076-.206-.266-.42-.069 1.745 2.36 3.985 4.098 6.683 5.193 4.354 1.767 8.773 2.07 13.293.51 3.51-1.21 6.033-.028 7.343 3.38.19-3.955-2.137-6.837-5.843-7.401-2.084-.318-4.01.373-5.962.94-5.434 1.575-10.485.798-15.094-2.553Zm27.085 15.425c.708.059 1.416.123 2.124.185-1.6-1.405-3.55-1.517-5.523-1.404-3.003.17-5.167 1.903-7.14 3.972-1.739 1.824-3.31 3.87-5.903 4.604.043.078.054.117.066.117.35.005.699.021 1.047.005 3.768-.17 7.317-.965 10.14-3.7.89-.86 1.685-1.817 2.544-2.71.716-.746 1.584-1.159 2.645-1.07Zm-8.753-4.67c-2.812.246-5.254 1.409-7.548 2.943-1.766 1.18-3.654 1.738-5.776 1.37-.374-.066-.75-.114-1.124-.17l-.013.156c.135.07.265.151.405.207.354.14.702.308 1.07.395 4.083.971 7.992.474 11.516-1.803 2.221-1.435 4.521-1.707 7.013-1.336.252.038.503.083.756.107.234.022.479.255.795.003-2.179-1.574-4.526-2.096-7.094-1.872Zm-10.049-9.544c1.475.051 2.943-.142 4.486-1.059-.452.04-.643.04-.827.076-2.126.424-4.033-.04-5.733-1.383-.623-.493-1.257-.974-1.889-1.457-2.503-1.914-5.374-2.555-8.514-2.5.05.154.054.26.108.315 3.417 3.455 7.371 5.836 12.369 6.008Zm24.727 17.731c-2.114-2.097-4.952-2.367-7.578-.537 1.738.078 3.043.632 4.101 1.728a13 13 0 0 0 1.182 1.106c1.6 1.29 4.311 1.352 5.896.155-1.861-.726-1.861-.726-3.601-2.452Zm-21.058 16.06c-1.858-3.46-4.981-4.24-8.59-4.008a9.667 9.667 0 0 1 2.977 1.39c.84.586 1.547 1.311 2.243 2.055 1.38 1.473 3.534 2.376 4.962 2.07-.656-.412-1.238-.848-1.592-1.507Zl-.006.006-.036-.004.021.018.012.053Za.127.127 0 0 0 .015.043c.005.008.038 0 .058-.002Zl-.008.01.005.026.024.014Z"
|
||||
fill="#FD4F00"
|
||||
/>
|
||||
</svg>
|
||||
|
After Width: | Height: | Size: 3 KiB |
BIN
priv/static/images/logo-06a11be1f2cdde2c851763d00bdd2e80.svg.gz
Normal file
BIN
priv/static/images/logo-06a11be1f2cdde2c851763d00bdd2e80.svg.gz
Normal file
Binary file not shown.
BIN
priv/static/images/logo.svg.gz
Normal file
BIN
priv/static/images/logo.svg.gz
Normal file
Binary file not shown.
5
priv/static/robots-9e2c81b0855bbff2baa8371bc4a78186.txt
Normal file
5
priv/static/robots-9e2c81b0855bbff2baa8371bc4a78186.txt
Normal file
|
|
@ -0,0 +1,5 @@
|
|||
# See https://www.robotstxt.org/robotstxt.html for documentation on how to use the robots.txt file
|
||||
#
|
||||
# To ban all spiders from the entire site uncomment the next two lines:
|
||||
# User-agent: *
|
||||
# Disallow: /
|
||||
BIN
priv/static/robots-9e2c81b0855bbff2baa8371bc4a78186.txt.gz
Normal file
BIN
priv/static/robots-9e2c81b0855bbff2baa8371bc4a78186.txt.gz
Normal file
Binary file not shown.
BIN
priv/static/robots.txt.gz
Normal file
BIN
priv/static/robots.txt.gz
Normal file
Binary file not shown.
Loading…
Add table
Add a link
Reference in a new issue