diff --git a/internal/adapter/docker.go b/internal/adapter/docker.go index 2ec065b..0cf3c23 100644 --- a/internal/adapter/docker.go +++ b/internal/adapter/docker.go @@ -61,11 +61,8 @@ func (d *DockerAdapter) BuildImage(deploy *domain.Deploy) { return } - DockerFileName := "Dockerfile" - // TODO add deploy domain - buildOptions := types.ImageBuildOptions{ - Dockerfile: DockerFileName, + Dockerfile: deploy.DockerFileName, Tags: []string{deploy.GetDockerName()}, Remove: true, } diff --git a/internal/adapter/filesystem.go b/internal/adapter/filesystem.go index 6744648..575f034 100644 --- a/internal/adapter/filesystem.go +++ b/internal/adapter/filesystem.go @@ -5,6 +5,7 @@ import ( "os" "os/exec" "path/filepath" + "strings" "cchalop1.com/deploy/internal" "cchalop1.com/deploy/internal/domain" @@ -107,3 +108,25 @@ func (fs *FilesystemAdapter) RemoveDockerCertOfServer(serverId string) error { pathLocalCertDir := internal.CERT_DOCKER_FOLDER + "/" + serverId + "/" return os.Remove(pathLocalCertDir) } + +func (fs *FilesystemAdapter) IsFolder(path string) bool { + fileInfo, err := os.Stat(path) + if err != nil { + return false + } + + return fileInfo.IsDir() +} + +func (fs *FilesystemAdapter) BaseDir(path string) string { + return filepath.Base(path) +} + +func (fs *FilesystemAdapter) GetDir(path string) string { + arr := strings.Split(path, "/") + if len(arr) > 1 { + arr = arr[:len(arr)-2] // remove the last element + return strings.Join(arr, "/") + "/" + } + return "/" +} diff --git a/internal/application/deploy-application.go b/internal/application/deploy-application.go index 499f628..0184596 100644 --- a/internal/application/deploy-application.go +++ b/internal/application/deploy-application.go @@ -56,16 +56,25 @@ func DeployApplication(deployService *service.DeployService, newDeploy dto.NewDe return err } + isFolder := adapter.NewFilesystemAdapter().IsFolder(pathToDir) + DockerFileName := "Dockerfile" + fmt.Println(isFolder) + if !isFolder { + DockerFileName = adapter.NewFilesystemAdapter().BaseDir(pathToDir) + pathToDir = adapter.NewFilesystemAdapter().GetDir(pathToDir) + } + deploy := domain.Deploy{ - Id: utils.GenerateRandomPassword(5), - Name: newDeploy.Name, - ServerId: newDeploy.ServerId, - PathToSource: pathToDir, - Status: "Installing", - EnableTls: newDeploy.EnableTls, - Email: newDeploy.Email, - Envs: newDeploy.Envs, - SubDomain: newDeploy.Name, + Id: utils.GenerateRandomPassword(5), + Name: newDeploy.Name, + ServerId: newDeploy.ServerId, + PathToSource: pathToDir, + Status: "Installing", + EnableTls: newDeploy.EnableTls, + Email: newDeploy.Email, + Envs: newDeploy.Envs, + SubDomain: newDeploy.Name, + DockerFileName: DockerFileName, } err = deployService.DatabaseAdapter.SaveDeploy(deploy) diff --git a/internal/domain/deploy.go b/internal/domain/deploy.go index 0429ad2..83c9ad1 100644 --- a/internal/domain/deploy.go +++ b/internal/domain/deploy.go @@ -19,6 +19,7 @@ type Deploy struct { Status string `json:"status"` Url string `json:"url"` SubDomain string `json:"subDomain"` + DockerFileName string `json:"dockerFileName"` } func (d *Deploy) GetDockerName() string { diff --git a/web/src/DeployPage.tsx b/web/src/DeployPage.tsx index 0d3fcc2..0ceaadc 100644 --- a/web/src/DeployPage.tsx +++ b/web/src/DeployPage.tsx @@ -58,11 +58,11 @@ export default function DeployPage() { {deploy.pathToSource} - - + + {/* Database Service */} - Logs Settings + Logs {/* */} diff --git a/web/src/components/forms/CreateDeployForm.tsx b/web/src/components/forms/CreateDeployForm.tsx index fa2f9c2..a758690 100644 --- a/web/src/components/forms/CreateDeployForm.tsx +++ b/web/src/components/forms/CreateDeployForm.tsx @@ -145,7 +145,9 @@ export function CreateDeployForm() { />
- +