Skip to content

Commit 64c03b5

Browse files
committed
Update deployment script and docker-compose file
1 parent ec6c2e5 commit 64c03b5

File tree

2 files changed

+19
-8
lines changed

2 files changed

+19
-8
lines changed

api/oracle-cloud/deploy.ts

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -43,21 +43,23 @@ console.log("⚙️ Deploying to", isProduction ? "Production" : "Staging", "..
4343

4444
let logs: Buffer;
4545
const sshServer = isProduction ? process.env.SSH_ADDRESS_PRD : process.env.SSH_ADDRESS_STG;
46+
const sshKeyPath = process.env.SSH_PATH;
4647
const appPath = "~/app";
47-
const sshPrefix = "ssh -o StrictHostKeyChecking=no " + sshServer + " ";
48+
const sshPrefix =
49+
"ssh -o StrictHostKeyChecking=no " + (sshKeyPath ? `-i ${sshKeyPath} ` : "") + sshServer + " ";
4850

4951
// Check for existing containers
50-
logs = execSync(sshPrefix + '"docker ps -aq"');
52+
logs = execSync(sshPrefix + '"sudo docker ps -aq"');
5153

5254
if (String(logs)) {
5355
// stop containers
5456
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)"');
5658
console.log(String(logs));
5759

5860
// delete containers
5961
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)"');
6163
console.log(String(logs));
6264
console.log("✅ All containers stopped");
6365
} else {
@@ -69,10 +71,19 @@ logs = execSync(sshPrefix + '"rm -f -r ' + appPath + '"');
6971
logs = execSync(sshPrefix + '"mkdir ' + appPath + '"');
7072

7173
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+
);
7382
console.log("✅ New code uploaded.");
7483

7584
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+
);
7788
console.log(String(logs));
7889
console.log("✅ Deployment successful.");

api/oracle-cloud/docker-compose.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,6 @@ services:
66
ports:
77
- "80:7070"
88
env_file:
9-
- ~/app-env/api.env
9+
- /home/opc/app-env/api.env
1010
volumes:
11-
- /home/${USER}/app-data/api/fetch_cache:/usr/src/repo/api/fetch_cache
11+
- /home/opc/app-data/api/fetch_cache:/usr/src/repo/api/fetch_cache

0 commit comments

Comments
 (0)