From 3becfc6fc8c5e173a6e8491af50ca3b5c3a1ac96 Mon Sep 17 00:00:00 2001 From: Zakaria Mansouri Date: Thu, 6 Feb 2025 11:23:41 +0100 Subject: [PATCH 1/4] refactor: remove old container management logic from deployment script --- api/oracle-cloud/deploy.ts | 19 ------------------- 1 file changed, 19 deletions(-) diff --git a/api/oracle-cloud/deploy.ts b/api/oracle-cloud/deploy.ts index de5024fd..212011b2 100644 --- a/api/oracle-cloud/deploy.ts +++ b/api/oracle-cloud/deploy.ts @@ -52,25 +52,6 @@ const appPath = "~/app"; const sshPrefix = "ssh -o StrictHostKeyChecking=no " + (sshKeyPath ? `-i ${sshKeyPath} ` : "") + sshServer + " "; -// todo-ZM: let docker-compose handle deletion of old containers -// Check for existing containers -logs = execSync(sshPrefix + '"sudo docker ps -aq"'); - -if (String(logs)) { - // stop containers - console.log("⚠️ Stopping all containers ..."); - logs = execSync(sshPrefix + '"sudo docker stop \\$(sudo docker ps -aq)"'); - console.log(String(logs)); - - // delete containers - console.log("⚠️ Deleting all containers ..."); - logs = execSync(sshPrefix + '"sudo docker rm \\$(sudo docker ps -aq)"'); - console.log(String(logs)); - console.log("✅ All containers stopped"); -} else { - console.log("⏩ No container found, skipping stopping containers."); -} - console.log("⚠️ Deleting old code ..."); logs = execSync(sshPrefix + '"rm -f -r ' + appPath + '"'); logs = execSync(sshPrefix + '"mkdir ' + appPath + '"'); From df072fc6ab440acf8cda8b1a064bac3e51b31d17 Mon Sep 17 00:00:00 2001 From: Zakaria Mansouri Date: Thu, 6 Feb 2025 11:36:35 +0100 Subject: [PATCH 2/4] feat: add cleanup for old Docker images and containers in deployment script --- api/oracle-cloud/deploy.ts | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/api/oracle-cloud/deploy.ts b/api/oracle-cloud/deploy.ts index 212011b2..120bd81f 100644 --- a/api/oracle-cloud/deploy.ts +++ b/api/oracle-cloud/deploy.ts @@ -52,6 +52,13 @@ const appPath = "~/app"; const sshPrefix = "ssh -o StrictHostKeyChecking=no " + (sshKeyPath ? `-i ${sshKeyPath} ` : "") + sshServer + " "; +console.log("⚠️ Cleaning up old images ..."); +logs = execSync(sshPrefix + '"sudo docker image prune --force"'); +console.log(String(logs)); +console.log("⚠️ Cleaning up old containers ..."); +logs = execSync(sshPrefix + '"sudo docker container prune --force"'); +console.log(String(logs)); + console.log("⚠️ Deleting old code ..."); logs = execSync(sshPrefix + '"rm -f -r ' + appPath + '"'); logs = execSync(sshPrefix + '"mkdir ' + appPath + '"'); From d37fa5ef284a2b59bb2d9461f206ec0e021a536f Mon Sep 17 00:00:00 2001 From: Zakaria Mansouri Date: Thu, 6 Feb 2025 16:27:20 +0100 Subject: [PATCH 3/4] fix: update MeiliSearch image version and add service dependencies in Docker Compose --- api/oracle-cloud/docker-compose.yml | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/api/oracle-cloud/docker-compose.yml b/api/oracle-cloud/docker-compose.yml index a285e7d0..1f113e07 100644 --- a/api/oracle-cloud/docker-compose.yml +++ b/api/oracle-cloud/docker-compose.yml @@ -13,6 +13,11 @@ services: build: "." ports: - "7070:7070" + depends_on: + postgres: + condition: service_started + meilisearch: + condition: service_started env_file: - /home/ubuntu/app-env/api.env volumes: @@ -28,7 +33,7 @@ services: POSTGRES_HOST_AUTH_METHOD: trust POSTGRES_DB: db meilisearch: - image: getmeili/meilisearch:latest + image: getmeili/meilisearch:v1.11.3 ports: - "7700:7700" volumes: From deec340c07ae1befd3c238564cbbf2398a6fc23f Mon Sep 17 00:00:00 2001 From: Zakaria Mansouri Date: Thu, 6 Feb 2025 16:27:28 +0100 Subject: [PATCH 4/4] fix: reorder cleanup logs for old Docker images and containers in deployment script --- api/oracle-cloud/deploy.ts | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/api/oracle-cloud/deploy.ts b/api/oracle-cloud/deploy.ts index 120bd81f..deb53fa9 100644 --- a/api/oracle-cloud/deploy.ts +++ b/api/oracle-cloud/deploy.ts @@ -52,13 +52,14 @@ const appPath = "~/app"; const sshPrefix = "ssh -o StrictHostKeyChecking=no " + (sshKeyPath ? `-i ${sshKeyPath} ` : "") + sshServer + " "; -console.log("⚠️ Cleaning up old images ..."); -logs = execSync(sshPrefix + '"sudo docker image prune --force"'); -console.log(String(logs)); console.log("⚠️ Cleaning up old containers ..."); logs = execSync(sshPrefix + '"sudo docker container prune --force"'); console.log(String(logs)); +console.log("⚠️ Cleaning up old images ..."); +logs = execSync(sshPrefix + '"sudo docker image prune --force"'); +console.log(String(logs)); + console.log("⚠️ Deleting old code ..."); logs = execSync(sshPrefix + '"rm -f -r ' + appPath + '"'); logs = execSync(sshPrefix + '"mkdir ' + appPath + '"');