Skip to content

Commit

Permalink
fix: specify dockerfile name or path of the project
Browse files Browse the repository at this point in the history
  • Loading branch information
cchalop1 committed Mar 25, 2024
1 parent 6704833 commit b5650b5
Show file tree
Hide file tree
Showing 6 changed files with 49 additions and 17 deletions.
5 changes: 1 addition & 4 deletions internal/adapter/docker.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
}
Expand Down
23 changes: 23 additions & 0 deletions internal/adapter/filesystem.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"os"
"os/exec"
"path/filepath"
"strings"

"cchalop1.com/deploy/internal"
"cchalop1.com/deploy/internal/domain"
Expand Down Expand Up @@ -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 "/"
}
27 changes: 18 additions & 9 deletions internal/application/deploy-application.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
1 change: 1 addition & 0 deletions internal/domain/deploy.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
6 changes: 3 additions & 3 deletions web/src/DeployPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -58,11 +58,11 @@ export default function DeployPage() {
<FolderIcon />
{deploy.pathToSource}
</div>
<Tabs defaultValue="database-service" className="mt-20">
<TabsList className="w-full justify-between pl-5 pr-5">
<Tabs defaultValue="settings" className="mt-20">
<TabsList className="w-full justify-around pl-5 pr-5">
{/* <TabsTrigger value="database-service">Database Service</TabsTrigger> */}
<TabsTrigger value="logs">Logs</TabsTrigger>
<TabsTrigger value="settings">Settings</TabsTrigger>
<TabsTrigger value="logs">Logs</TabsTrigger>
</TabsList>
{/* <TabsContent value="database-service"></TabsContent> */}
<TabsContent value="logs">
Expand Down
4 changes: 3 additions & 1 deletion web/src/components/forms/CreateDeployForm.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,9 @@ export function CreateDeployForm() {
/>
</div>
<div className="flex flex-col space-y-1.5">
<Label htmlFor="projectPath">Project foder</Label>
<Label htmlFor="projectPath">
Path to your project folder or Dockerfile
</Label>
<Input
id="projectPath"
name="projectPath"
Expand Down

0 comments on commit b5650b5

Please sign in to comment.