@@ -4,16 +4,17 @@ import (
4
4
"context"
5
5
"encoding/json"
6
6
"errors"
7
+ "log"
8
+ "os"
9
+ "path/filepath"
10
+
7
11
"github.com/google/uuid"
8
12
containermanger "github.com/swiftwave-org/swiftwave/container_manager"
9
13
dockerconfiggenerator "github.com/swiftwave-org/swiftwave/docker_config_generator"
10
14
gitmanager "github.com/swiftwave-org/swiftwave/git_manager"
11
15
"github.com/swiftwave-org/swiftwave/pubsub"
12
16
"github.com/swiftwave-org/swiftwave/swiftwave_service/core"
13
17
"gorm.io/gorm"
14
- "log"
15
- "os"
16
- "path/filepath"
17
18
)
18
19
19
20
func (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,
176
177
addPersistentDeploymentLog (dbWithoutTx , pubSubClient , deployment .ID , "Reason > " + err .Error ()+ "\n " , true )
177
178
return err
178
179
}
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
+ }
179
189
addPersistentDeploymentLog (dbWithoutTx , pubSubClient , deployment .ID , "Cloned git repository successfully\n " , false )
180
190
addPersistentDeploymentLog (dbWithoutTx , pubSubClient , deployment .ID , "Commit message > " + commitMessage + "\n " , false )
181
191
addPersistentDeploymentLog (dbWithoutTx , pubSubClient , deployment .ID , "Commit hash > " + commitHash + "\n " , false )
@@ -196,7 +206,7 @@ func (m Manager) buildApplicationForGit(deployment *core.Deployment, db gorm.DB,
196
206
if err != nil {
197
207
return err
198
208
}
199
- var buildArgsMap = make (map [string ]string )
209
+ buildArgsMap : = make (map [string ]string )
200
210
for _ , buildArg := range buildArgs {
201
211
buildArgsMap [buildArg .Key ] = buildArg .Value
202
212
}
@@ -272,7 +282,7 @@ func (m Manager) buildApplicationForTarball(deployment *core.Deployment, db gorm
272
282
if err != nil {
273
283
return err
274
284
}
275
- var buildArgsMap = make (map [string ]string )
285
+ buildArgsMap : = make (map [string ]string )
276
286
for _ , buildArg := range buildArgs {
277
287
buildArgsMap [buildArg .Key ] = buildArg .Value
278
288
}
0 commit comments