@@ -43,21 +43,23 @@ console.log("⚙️ Deploying to", isProduction ? "Production" : "Staging", "..
43
43
44
44
let logs : Buffer ;
45
45
const sshServer = isProduction ? process . env . SSH_ADDRESS_PRD : process . env . SSH_ADDRESS_STG ;
46
+ const sshKeyPath = process . env . SSH_PATH ;
46
47
const appPath = "~/app" ;
47
- const sshPrefix = "ssh -o StrictHostKeyChecking=no " + sshServer + " " ;
48
+ const sshPrefix =
49
+ "ssh -o StrictHostKeyChecking=no " + ( sshKeyPath ? `-i ${ sshKeyPath } ` : "" ) + sshServer + " " ;
48
50
49
51
// Check for existing containers
50
- logs = execSync ( sshPrefix + '"docker ps -aq"' ) ;
52
+ logs = execSync ( sshPrefix + '"sudo docker ps -aq"' ) ;
51
53
52
54
if ( String ( logs ) ) {
53
55
// stop containers
54
56
console . log ( "⚠️ Stopping all containers ..." ) ;
55
- logs = execSync ( sshPrefix + '"docker stop \\$(docker ps -aq)"' ) ;
57
+ logs = execSync ( sshPrefix + '"sudo docker stop \\$(sudo docker ps -aq)"' ) ;
56
58
console . log ( String ( logs ) ) ;
57
59
58
60
// delete containers
59
61
console . log ( "⚠️ Deleting all containers ..." ) ;
60
- logs = execSync ( sshPrefix + '"docker rm \\$(docker ps -aq)"' ) ;
62
+ logs = execSync ( sshPrefix + '"sudo docker rm \\$(sudo docker ps -aq)"' ) ;
61
63
console . log ( String ( logs ) ) ;
62
64
console . log ( "✅ All containers stopped" ) ;
63
65
} else {
@@ -69,10 +71,19 @@ logs = execSync(sshPrefix + '"rm -f -r ' + appPath + '"');
69
71
logs = execSync ( sshPrefix + '"mkdir ' + appPath + '"' ) ;
70
72
71
73
console . log ( "⤴️ Uploading new code ..." ) ;
72
- logs = execSync ( "rsync -r oracle-cloud/build/* " + sshServer + ":" + appPath ) ;
74
+ logs = execSync (
75
+ "rsync " +
76
+ ( sshKeyPath ? `-e "ssh -i ${ sshKeyPath } " ` : "" ) +
77
+ " -r oracle-cloud/build/* " +
78
+ sshServer +
79
+ ":" +
80
+ appPath ,
81
+ ) ;
73
82
console . log ( "✅ New code uploaded." ) ;
74
83
75
84
console . log ( "\n⚙️ Starting up the app" ) ;
76
- logs = execSync ( sshPrefix + '"docker-compose -f ' + appPath + '/docker-compose.yml up -d --build"' ) ;
85
+ logs = execSync (
86
+ sshPrefix + '"sudo docker-compose -f ' + appPath + '/docker-compose.yml up -d --build"' ,
87
+ ) ;
77
88
console . log ( String ( logs ) ) ;
78
89
console . log ( "✅ Deployment successful." ) ;
0 commit comments