Skip to content

Commit

Permalink
fix: add folder
Browse files Browse the repository at this point in the history
  • Loading branch information
cchalop1 committed Oct 2, 2024
1 parent abf4003 commit b76a6ea
Show file tree
Hide file tree
Showing 17 changed files with 155 additions and 68 deletions.
17 changes: 17 additions & 0 deletions internal/adapter/database/database.go
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,23 @@ var servicesConfigMap = map[string]ServicesConfig{
},
},
},
"Minio": {
DefaultPort: 9000,
Name: "Minio",
Icon: "https://min.io/resources/img/logo.svg",
Env: []dto.Env{
{Name: "MINIO_ACCESS_KEY", Value: "", IsSecret: false},
{Name: "MINIO_SECRET_KEY", Value: "", IsSecret: true},
},
Config: container.Config{
Image: "minio/minio:latest",
Cmd: []string{"server", "/data"},
Env: []string{
"MINIO_ACCESS_KEY=$MINIO_ACCESS_KEY",
"MINIO_SECRET_KEY=$MINIO_SECRET_KEY",
},
},
},
}

func GetListOfDatabasesServices() []ServicesConfig {
Expand Down
7 changes: 4 additions & 3 deletions internal/application/create-service.go
Original file line number Diff line number Diff line change
Expand Up @@ -129,8 +129,8 @@ func getPortsForService(service database.ServicesConfig) string {
func createDevContainerService(deployService *service.DeployService, createServiceDto dto.CreateServiceDto) (domain.Service, error) {
exposedPort := "9999"
domainService := domain.Service{
Id: utils.GenerateRandomPassword(5),
Name: deployService.FilesystemAdapter.GetFolderName(*createServiceDto.Path),
Id: utils.GenerateRandomPassword(5),
HostName: deployService.FilesystemAdapter.GetFolderName(*createServiceDto.Path),
Envs: []dto.Env{
// TODO: find a avalaible port
{Name: "PORT", Value: exposedPort},
Expand Down Expand Up @@ -182,10 +182,11 @@ func createServiceForProject(deployService *service.DeployService, createService

domainService := domain.Service{
Id: utils.GenerateRandomPassword(5),
Name: containerHostname,
HostName: containerHostname,
Envs: envs,
VolumsNames: []string{},
Status: "Runing",
Name: strings.ToLower(service.Name),
ImageName: service.Config.Image,
ImageUrl: service.Icon,
ExposePort: exposedPort,
Expand Down
2 changes: 1 addition & 1 deletion internal/application/delete-service.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ func DeleteService(deployService *service.DeployService, projectId string, servi
func deleteServiceWithoutDeploy(deployService *service.DeployService, project *domain.Project, s *domain.Service) error {
server := deployService.DockerAdapter.GetLocalHostServer()
deployService.DockerAdapter.ConnectClient(server)
deployService.DockerAdapter.Delete(s.Name)
deployService.DockerAdapter.Delete(s.HostName)

removeEnvsFromProject(project, s.Envs)

Expand Down
16 changes: 8 additions & 8 deletions internal/application/deploy-project.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ func DeployProject(deployService *service.DeployService, deployProjectDto dto.De
for _, service := range project.Services {
if service.IsDevContainer {
exposeServiceId = service.Id
fmt.Println("Service to expose found:", service.Name)
fmt.Println("Service to expose found:", service.HostName)
break
}
}
Expand All @@ -64,13 +64,13 @@ func DeployProject(deployService *service.DeployService, deployProjectDto dto.De

// Build all services
for _, service := range project.Services {
fmt.Println("Building service:", service.Name)
fmt.Println("Building service:", service.HostName)
err = pullAndBuildService(deployService, service, server)
if err != nil {
fmt.Println("Error building service:", service.Name, err)
fmt.Println("Error building service:", service.HostName, err)
return domain.Deploy{}, err
}
fmt.Println("Service built:", service.Name)
fmt.Println("Service built:", service.HostName)
}

containersConfig := []container.Config{}
Expand All @@ -92,7 +92,7 @@ func DeployProject(deployService *service.DeployService, deployProjectDto dto.De
if !service.IsDevContainer {
hostNameEnvs = append(hostNameEnvs, dto.Env{
//TODO: get the real name of the service
Name: strings.ToUpper(strings.Split(service.ImageName, ":")[0]) + "_HOSTNAME",
Name: strings.ToUpper(service.Name) + "_HOSTNAME",
Value: service.GetDockerName(),
})
}
Expand All @@ -106,18 +106,18 @@ func DeployProject(deployService *service.DeployService, deployProjectDto dto.De

// Configure all services
for _, service := range project.Services {
fmt.Println("Configuring service:", service.Name)
fmt.Println("Configuring service:", service.HostName)
config := deployService.DockerAdapter.ConfigContainer(service)
if service.Id == exposeServiceId {
fmt.Println("Exposing service:", service.Name)
fmt.Println("Exposing service:", service.HostName)
deployService.DockerAdapter.ExposeContainer(&config, adapter.ExposeContainerParams{
IsTls: true,
Domain: server.Domain,
Port: service.ExposePort,
})
}
containersConfig = append(containersConfig, config)
fmt.Println("Service configured:", service.Name)
fmt.Println("Service configured:", service.HostName)
}

// Run all services
Expand Down
38 changes: 19 additions & 19 deletions internal/application/get-project-settings.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,35 +12,35 @@ func GetProjectSettings(deployService *service.DeployService, projectId string)
return dto.ProjectSettingsDto{}, err
}

folders, err := deployService.FilesystemAdapter.GetFolders(project.Path)
// folders, err := deployService.FilesystemAdapter.GetFolders(project.Path)

folders = append(folders, dto.PathDto{
Name: deployService.FilesystemAdapter.GetFolderName(project.Path),
FullPath: project.Path,
})
// folders = append(folders, dto.PathDto{
// Name: deployService.FilesystemAdapter.GetFolderName(project.Path),
// FullPath: project.Path,
// })

if err != nil {
return dto.ProjectSettingsDto{}, err
}

foldersList := []dto.PathDto{}

for _, folder := range folders {
keepFolder := true
for _, service := range project.Services {
if service.CurrentPath == folder.FullPath {
keepFolder = false
}
}
if keepFolder {
foldersList = append(foldersList, folder)
}
}
// foldersList := []dto.PathDto{}

// for _, folder := range folders {
// keepFolder := true
// for _, service := range project.Services {
// if service.CurrentPath == folder.FullPath {
// keepFolder = false
// }
// }
// if keepFolder {
// foldersList = append(foldersList, folder)
// }
// }

projectSetting := dto.ProjectSettingsDto{
CurrentPath: project.Path,
CurrentFolderName: deployService.FilesystemAdapter.GetFolderName(project.Path),
Folders: foldersList,
Folders: []dto.PathDto{},
}

return projectSetting, nil
Expand Down
3 changes: 2 additions & 1 deletion internal/domain/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (
// TODO: change to save serviceConfig
type Service struct {
Id string `json:"id"`
HostName string `json:"hostName"`
Name string `json:"name"`
Envs []dto.Env `json:"envs"`
VolumsNames []string `json:"volumsNames"`
Expand All @@ -23,5 +24,5 @@ type Service struct {
}

func (s *Service) GetDockerName() string {
return strings.ToLower(s.Name + "-" + s.Id)
return strings.ToLower(s.HostName + "-" + s.Id)
}
2 changes: 1 addition & 1 deletion web/src/components/ServiceCard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ export default function ServiceCard({ service, onClick }: ServiceCardProps) {
</div>
</div>
<div className="font-bold text-xl mt-2 ml-4 mr-4 mb-2">
{service.name}
{service.hostName}
</div>
{isDevContainer ? (
<div className="font-mono ml-4 mr-4 text-sm">{service.currentPath}</div>
Expand Down
9 changes: 9 additions & 0 deletions web/src/components/databaseServices/CommandModal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,15 @@ export default function CommandModal({
<CommandInput placeholder="Type to search and lauch a service in the list..." />
<CommandList onSelect={() => setOpen(false)}>
<CommandEmpty>No results found.</CommandEmpty>
<CommandGroup heading="Current Folder">
<CommandItem
onSelect={() => create({ path: projectSettings.currentPath })}
className="flex gap-3"
>
<Folder className="w-5" />
<span className="h-4">{projectSettings.currentFolderName}</span>
</CommandItem>
</CommandGroup>
<CommandGroup heading="Chose a folders in the list">
{projectSettings.folders.map((folder) => (
<CommandItem
Expand Down
4 changes: 2 additions & 2 deletions web/src/components/databaseServices/DatabaseServiceCard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -23,13 +23,13 @@ export default function DatabaseServiceCard({

return (
<Card
key={service.name}
key={service.hostName}
className="flex justify-between p-3 mb-3 hover:shadow-md cursor-pointer"
>
<div className="flex flex-col gap-3">
<div className="flex items-center gap-5">
<img className="w-10" src={service.imageUrl}></img>
<p className="font-bold">{service.name}</p>
<p className="font-bold">{service.hostName}</p>
<Status status={service.status} />
</div>
</div>
Expand Down
2 changes: 1 addition & 1 deletion web/src/components/modals/ModalServiceSettings.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ export default function ModalServiceSettings({
) : (
<img src="/icons/service.png" className="w-8" />
)}
<div className="font-bold">{service.name}</div>
<div className="font-bold">{service.hostName}</div>
</div>
}
>
Expand Down
47 changes: 18 additions & 29 deletions web/src/components/project/ProjectPageHeader.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
import { FileText, Settings } from "lucide-react";
import { Tooltip, TooltipProvider, TooltipTrigger } from "../ui/tooltip";
import { TooltipContent } from "@radix-ui/react-tooltip";
import { PlayCircle, Settings } from "lucide-react";

type ProjectPageHeaderProps = {
onClickDeploy: () => void;
Expand All @@ -17,32 +15,23 @@ export default function ProjectPageHeader({
<div className="font-semibold border rounded-full shadow-lg bg-white pl-4 pr-4 flex items-center">
🛵 JustDeploy
</div>
<TooltipProvider>
<div className="border rounded-full shadow-lg bg-white p-2 flex gap-3">
<Tooltip>
<TooltipTrigger>
<button
className="rounded-full bg-green-50 w-9 h-9 flex justify-center items-center"
onClick={onClickSettings}
>
<Settings />
</button>
</TooltipTrigger>
<TooltipContent>
<div className="p-2">Settings</div>
</TooltipContent>
</Tooltip>
<button className="rounded-full bg-green-50 w-9 h-9 flex justify-center items-center">
<FileText />
</button>
<button
className="font-mono bg-button text-white p-1 pl-4 pr-4 rounded-xl border border-green-200"
onClick={onClickDeploy}
>
Deploy
</button>
</div>
</TooltipProvider>
<div className="border rounded-full shadow-lg bg-white p-2 flex gap-3">
<button
className="rounded-full bg-green-50 w-9 h-9 flex justify-center items-center"
onClick={onClickSettings}
>
<Settings />
</button>
{/* <button className="rounded-full bg-green-50 w-9 h-9 flex justify-center items-center">
<PlayCircle />
</button> */}
<button
className="font-mono bg-button text-white p-1 pl-4 pr-4 rounded-xl border border-green-200"
onClick={onClickDeploy}
>
Deploy
</button>
</div>
</div>
);
}
2 changes: 1 addition & 1 deletion web/src/components/project/ServiceSideBar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ export default function ServiceSideBar({
className="absolute right-5 top-28 w-1/4 rounded-lg border shadow-lg h-full bg-white p-8"
>
<div className="flex justify-between">
<div className="font-bold text-2xl">{serviceSelected?.name}</div>
<div className="font-bold text-2xl">{serviceSelected?.hostName}</div>
<X
className="h-6 cursor-pointer"
onClick={() => setServiceSelected(null)}
Expand Down
40 changes: 40 additions & 0 deletions web/src/components/ui/background.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
import useMouseMove from "@/hooks/useMouseMove";
import type { ReactNode } from "react";

export default function Background({ children }: { children: ReactNode }) {
useMouseMove();
return (
<>
<div className="-z-50 fixed top-0 left-0">
<div className="sticky top-0 left-0 h-screen w-screen overflow-hidden">
<div className="absolute inset-0 z-[-1] bg-muted-foreground/15" />
<div className="-translate-x-1/2 -translate-y-1/2 absolute top-[--y] left-[--x] z-[-1] h-56 w-56 rounded-full bg-gradient-radial from-0% from-muted-foreground/40 to-90% to-transparent blur-md" />
<svg xmlns="http://www.w3.org/2000/svg" width="100%" height="100%">
<defs>
<pattern
id="dotted-pattern"
width="16"
height="16"
patternUnits="userSpaceOnUse"
>
<circle cx="2" cy="2" r="1" fill="black" />
</pattern>
<mask id="dots-mask">
<rect width="100%" height="100%" fill="white" />
<rect width="100%" height="100%" fill="url(#dotted-pattern)" />
</mask>
</defs>
<rect
width="100%"
height="100%"
fill="hsl(var(--background))"
mask="url(#dots-mask)"
/>
</svg>
</div>
</div>

{children}
</>
);
}
26 changes: 26 additions & 0 deletions web/src/hooks/useMouseMove.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import React from "react";

export default function useMouseMove() {
React.useEffect(() => {
function mouseMoveEvent(e: MouseEvent) {
const scale = window.visualViewport?.scale;
// disable mouse movement on viewport zoom - causes page to slow down
if (scale === 1) {
const body = document.body;

const targetX = e.clientX;
const targetY = e.clientY;

// TODO: make it move around cursor so you feal like its floating around it
// the animation requires tranformX and transformY on the HTML Element
body.style.setProperty("--x", `${targetX}px`);
body.style.setProperty("--y", `${targetY}px`);
}
}

document.addEventListener("mousemove", mouseMoveEvent);
return () => {
document.removeEventListener("mousemove", mouseMoveEvent);
};
}, []);
}
5 changes: 4 additions & 1 deletion web/src/routes.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import CreateDeployLoading from "@/pages/CreateDeployLoading";
import Layout from "@/Layout";
import ProjectPageWrapper from "./pages/project/ProjectPageWrapper";
import { NotificationProvider } from "./contexts/Notifications";
import Background from "./components/ui/background";

const router = createBrowserRouter(
createRoutesFromElements(
Expand All @@ -37,7 +38,9 @@ const router = createBrowserRouter(
path="project/:id"
element={
<NotificationProvider>
<ProjectPageWrapper />
<Background>
<ProjectPageWrapper />
</Background>
</NotificationProvider>
}
/>
Expand Down
1 change: 1 addition & 0 deletions web/src/services/getProjectSettings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ export type PathDto = {

export type ProjectSettingsDto = {
currentPath: string;
currentFolderName: string;
folders: PathDto[];
};

Expand Down
Loading

0 comments on commit b76a6ea

Please sign in to comment.