Skip to content

Commit

Permalink
Update deployment script and docker-compose file
Browse files Browse the repository at this point in the history
  • Loading branch information
ZibanPirate committed Dec 31, 2023
1 parent ec6c2e5 commit 64c03b5
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 8 deletions.
23 changes: 17 additions & 6 deletions api/oracle-cloud/deploy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,21 +43,23 @@ console.log("⚙️ Deploying to", isProduction ? "Production" : "Staging", "..

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

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

if (String(logs)) {
// stop containers
console.log("⚠️ Stopping all containers ...");
logs = execSync(sshPrefix + '"docker stop \\$(docker ps -aq)"');
logs = execSync(sshPrefix + '"sudo docker stop \\$(sudo docker ps -aq)"');
console.log(String(logs));

// delete containers
console.log("⚠️ Deleting all containers ...");
logs = execSync(sshPrefix + '"docker rm \\$(docker ps -aq)"');
logs = execSync(sshPrefix + '"sudo docker rm \\$(sudo docker ps -aq)"');
console.log(String(logs));
console.log("✅ All containers stopped");
} else {
Expand All @@ -69,10 +71,19 @@ logs = execSync(sshPrefix + '"rm -f -r ' + appPath + '"');
logs = execSync(sshPrefix + '"mkdir ' + appPath + '"');

console.log("⤴️ Uploading new code ...");
logs = execSync("rsync -r oracle-cloud/build/* " + sshServer + ":" + appPath);
logs = execSync(
"rsync " +
(sshKeyPath ? `-e "ssh -i ${sshKeyPath}" ` : "") +
" -r oracle-cloud/build/* " +
sshServer +
":" +
appPath,
);
console.log("✅ New code uploaded.");

console.log("\n⚙️ Starting up the app");
logs = execSync(sshPrefix + '"docker-compose -f ' + appPath + '/docker-compose.yml up -d --build"');
logs = execSync(
sshPrefix + '"sudo docker-compose -f ' + appPath + '/docker-compose.yml up -d --build"',
);
console.log(String(logs));
console.log("✅ Deployment successful.");
4 changes: 2 additions & 2 deletions api/oracle-cloud/docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,6 @@ services:
ports:
- "80:7070"
env_file:
- ~/app-env/api.env
- /home/opc/app-env/api.env
volumes:
- /home/${USER}/app-data/api/fetch_cache:/usr/src/repo/api/fetch_cache
- /home/opc/app-data/api/fetch_cache:/usr/src/repo/api/fetch_cache

0 comments on commit 64c03b5

Please sign in to comment.