@@ -4,16 +4,17 @@ import (
44 "context"
55 "encoding/json"
66 "errors"
7+ "log"
8+ "os"
9+ "path/filepath"
10+
711 "github.com/google/uuid"
812 containermanger "github.com/swiftwave-org/swiftwave/container_manager"
913 dockerconfiggenerator "github.com/swiftwave-org/swiftwave/docker_config_generator"
1014 gitmanager "github.com/swiftwave-org/swiftwave/git_manager"
1115 "github.com/swiftwave-org/swiftwave/pubsub"
1216 "github.com/swiftwave-org/swiftwave/swiftwave_service/core"
1317 "gorm.io/gorm"
14- "log"
15- "os"
16- "path/filepath"
1718)
1819
1920func (m Manager ) BuildApplication (request BuildApplicationRequest , ctx context.Context , cancelContext context.CancelFunc ) error {
@@ -176,6 +177,15 @@ func (m Manager) buildApplicationForGit(deployment *core.Deployment, db gorm.DB,
176177 addPersistentDeploymentLog (dbWithoutTx , pubSubClient , deployment .ID , "Reason > " + err .Error ()+ "\n " , true )
177178 return err
178179 }
180+ // delete .git folder after cloning
181+ // -- can be security risk for html based apps
182+ // -- if nginx is running inside container, that can expose the .git folder to public
183+ gitFolder := filepath .Join (tempDirectory , ".git" )
184+ err = os .RemoveAll (gitFolder )
185+ if err != nil {
186+ addPersistentDeploymentLog (dbWithoutTx , pubSubClient , deployment .ID , "Failed to delete the .git folder of cloned repository\n " , false )
187+ addPersistentDeploymentLog (dbWithoutTx , pubSubClient , deployment .ID , "Reason > " + err .Error ()+ "\n " , false )
188+ }
179189 addPersistentDeploymentLog (dbWithoutTx , pubSubClient , deployment .ID , "Cloned git repository successfully\n " , false )
180190 addPersistentDeploymentLog (dbWithoutTx , pubSubClient , deployment .ID , "Commit message > " + commitMessage + "\n " , false )
181191 addPersistentDeploymentLog (dbWithoutTx , pubSubClient , deployment .ID , "Commit hash > " + commitHash + "\n " , false )
@@ -196,7 +206,7 @@ func (m Manager) buildApplicationForGit(deployment *core.Deployment, db gorm.DB,
196206 if err != nil {
197207 return err
198208 }
199- var buildArgsMap = make (map [string ]string )
209+ buildArgsMap : = make (map [string ]string )
200210 for _ , buildArg := range buildArgs {
201211 buildArgsMap [buildArg .Key ] = buildArg .Value
202212 }
@@ -272,7 +282,7 @@ func (m Manager) buildApplicationForTarball(deployment *core.Deployment, db gorm
272282 if err != nil {
273283 return err
274284 }
275- var buildArgsMap = make (map [string ]string )
285+ buildArgsMap : = make (map [string ]string )
276286 for _ , buildArg := range buildArgs {
277287 buildArgsMap [buildArg .Key ] = buildArg .Value
278288 }
0 commit comments