From 640c7504c40cf12d7ec7318179b9a3c7367b89b2 Mon Sep 17 00:00:00 2001 From: dx-tan Date: Fri, 22 Dec 2023 10:54:04 +0700 Subject: [PATCH] Update: new deploy flow for AWS --- .dockerignore | 3 +-- .gitignore | 1 + cope2n-ai-fi/.dockerignore | 3 +-- cope2n-ai-fi/modules/sdsvkvu | 2 +- cope2n-api/Dockerfile | 2 +- demo-ocr | 1 - deploy_images.py | 15 ++++++++++++--- deploy_images.sh | 18 ++++++++++-------- docker-compose-dev.yml | 15 +++++++++------ 9 files changed, 36 insertions(+), 24 deletions(-) delete mode 160000 demo-ocr diff --git a/.dockerignore b/.dockerignore index a89b7d9..191381e 100644 --- a/.dockerignore +++ b/.dockerignore @@ -1,2 +1 @@ -.git -weights/ \ No newline at end of file +.git \ No newline at end of file diff --git a/.gitignore b/.gitignore index d62f580..06e3308 100644 --- a/.gitignore +++ b/.gitignore @@ -28,3 +28,4 @@ curl.md cope2n-api/fwd_api/commands/init_database.py /data backup +demo-ocr/ \ No newline at end of file diff --git a/cope2n-ai-fi/.dockerignore b/cope2n-ai-fi/.dockerignore index bf7ca8c..d38e621 100755 --- a/cope2n-ai-fi/.dockerignore +++ b/cope2n-ai-fi/.dockerignore @@ -4,5 +4,4 @@ __pycache__ DataBase/image_temp/ DataBase/json_temp/ -DataBase/template.db -weights \ No newline at end of file +DataBase/template.db \ No newline at end of file diff --git a/cope2n-ai-fi/modules/sdsvkvu b/cope2n-ai-fi/modules/sdsvkvu index bdba044..a471c10 160000 --- a/cope2n-ai-fi/modules/sdsvkvu +++ b/cope2n-ai-fi/modules/sdsvkvu @@ -1 +1 @@ -Subproject commit bdba044bb2eacac7c7cfe0e0f321196d03b681f6 +Subproject commit a471c1018c17cc917d1723776bae81f829450f95 diff --git a/cope2n-api/Dockerfile b/cope2n-api/Dockerfile index 03e8ce6..18d6e3f 100755 --- a/cope2n-api/Dockerfile +++ b/cope2n-api/Dockerfile @@ -19,6 +19,6 @@ COPY --chown=${UID}:${GID} requirements.txt /app WORKDIR /app RUN pip install -r requirements.txt --no-cache-dir -# COPY --chown=${UID}:${GID} . /app +COPY --chown=${UID}:${GID} . /app ENV TZ="Asia/Ho_Chi_Minh" diff --git a/demo-ocr b/demo-ocr deleted file mode 160000 index 036226c..0000000 --- a/demo-ocr +++ /dev/null @@ -1 +0,0 @@ -Subproject commit 036226c29ecd4aa0e28e89880c7b331523266caa diff --git a/deploy_images.py b/deploy_images.py index 5a13c7d..5f1804f 100644 --- a/deploy_images.py +++ b/deploy_images.py @@ -3,7 +3,8 @@ import hashlib import random import string import os -import boto3 +import boto3 +from datetime import datetime BASH_FILE = './deploy_images.sh' S3_ENDPOINT = "" @@ -75,6 +76,8 @@ def random_hash(): def deploy(): # Define the variable tag = str(random_hash()[:8]) + now = datetime.now() + tag = tag + "_" + str(now.strftime("%d%m%y%H%M%S")) print(tag) # Execute the Bash script with the variable as a command-line argument @@ -85,14 +88,20 @@ def deploy(): # TODO: Update to S3 s3_client = MinioS3Client(S3_ACCESS_KEY, S3_SECRET_KEY, S3_BUCKET, S3_ENDPOINT) local_compose_file = f"./docker-compose_{tag}.yml" - local_env_file = f"./.env_{tag}.yml" + local_env_file = f"./.env_{tag}" s3_compose_file = f"docker-yaml-files/docker-compose_{tag}.yml" - s3_env_file = f"env-files/.env_{tag}.yml" + s3_env_file = f"env-files/.env_{tag}" + print(f"[INFO]: Uploading compose and env file to s3...") s3_client.upload_file(local_compose_file, s3_compose_file) s3_client.upload_file(local_env_file, s3_env_file) + print(f"[INFO]: Deleting files...") + os.remove(local_compose_file) + os.remove(local_env_file) + + print(f"[INFO]: Done !!!") if __name__=="__main__": deploy() \ No newline at end of file diff --git a/deploy_images.sh b/deploy_images.sh index 528b881..688822a 100755 --- a/deploy_images.sh +++ b/deploy_images.sh @@ -1,21 +1,23 @@ #!/bin/bash -docker compose -f docker-compose-dev.yml build tag=$1 -echo "Tag received from Python: $tag" +echo "[INFO] Tag received from Python: $tag" -echo "Building AI image with tag: $tag..." +echo "[INFO] Pushing AI image with tag: $tag..." +docker compose -f docker-compose-dev.yml build cope2n-fi-sbt docker tag sidp/cope2n-ai-fi-sbt:latest public.ecr.aws/v4n9y6r8/sidp/cope2n-ai-fi-sbt:${tag} -# docker push public.ecr.aws/v4n9y6r8/sidp/cope2n-ai-fi-sbt:${tag} +docker push public.ecr.aws/v4n9y6r8/sidp/cope2n-ai-fi-sbt:${tag} -echo "Building BE image with tag: $tag..." +echo "[INFO] Pushing BE image with tag: $tag..." +docker compose -f docker-compose-dev.yml build be-ctel-sbt docker tag sidp/cope2n-be-fi-sbt:latest public.ecr.aws/v4n9y6r8/sidp/cope2n-be-fi-sbt:${tag} -# docker push public.ecr.aws/v4n9y6r8/sidp/cope2n-ai-fi-sbt:${tag} +docker push public.ecr.aws/v4n9y6r8/sidp/cope2n-be-fi-sbt:${tag} -echo "Building BE image with tag: $tag..." +echo "[INFO] Pushing FE image with tag: $tag..." +docker compose -f docker-compose-dev.yml build fe-sbt docker tag sidp/cope2n-fe-fi-sbt:latest public.ecr.aws/v4n9y6r8/sidp/cope2n-fe-fi-sbt:${tag} -# docker push public.ecr.aws/v4n9y6r8/sidp/cope2n-ai-fi-sbt:${tag} +docker push public.ecr.aws/v4n9y6r8/sidp/cope2n-fe-fi-sbt:${tag} cp ./docker-compose.yml ./docker-compose_${tag}.yml sed -i "s/{{tag}}/$tag/g" ./docker-compose_${tag}.yml diff --git a/docker-compose-dev.yml b/docker-compose-dev.yml index 368ad50..96e890a 100755 --- a/docker-compose-dev.yml +++ b/docker-compose-dev.yml @@ -34,7 +34,7 @@ services: command: bash run.sh deploy: mode: replicated - replicas: 3 + replicas: 1 # Back-end services be-ctel-sbt: build: @@ -69,12 +69,14 @@ services: - S3_SECRET_KEY=${S3_SECRET_KEY} - S3_BUCKET_NAME=${S3_BUCKET_NAME} restart: always + ports: + - 9000:9000 networks: - ctel-sbt volumes: - ${HOST_MEDIA_FOLDER}:${MEDIA_ROOT} - - ./data/BE_static:/app/static - - ./cope2n-api:/app + - BE_static:/app/static + # - ./cope2n-api:/app working_dir: /app depends_on: db-sbt: @@ -160,7 +162,7 @@ services: condition: service_started volumes: - ${HOST_MEDIA_FOLDER}:${MEDIA_ROOT} - - ./cope2n-api:/app + # - ./cope2n-api:/app working_dir: /app command: sh -c "celery -A fwd_api.celery_worker.worker worker -l INFO -c 5" @@ -201,7 +203,7 @@ services: shm_size: 10gb privileged: true ports: - - 80:80 + - 9881:80 depends_on: be-ctel-sbt: condition: service_started @@ -211,9 +213,10 @@ services: - VITE_PROXY=http://be-ctel-sbt:${BASE_PORT} - VITE_API_BASE_URL=http://fe-sbt:80 volumes: - - ./data/BE_static:/backend-static + - BE_static:/backend-static networks: - ctel-sbt volumes: db_data: + BE_static: \ No newline at end of file