From 9bb0ef3d0a4760656209c550b7b430e7c9fea2ec Mon Sep 17 00:00:00 2001 From: Dev Aggarwal Date: Fri, 1 Mar 2024 09:50:25 +0530 Subject: [PATCH 01/18] cloudbuild --- cloudbuild.yaml | 87 +++++++++++++--------------------------------- docker-compose.yml | 38 ++++++++++++++++++++ 2 files changed, 62 insertions(+), 63 deletions(-) create mode 100644 docker-compose.yml diff --git a/cloudbuild.yaml b/cloudbuild.yaml index 98e615ecf..793e7156b 100644 --- a/cloudbuild.yaml +++ b/cloudbuild.yaml @@ -1,70 +1,31 @@ steps: - - name: 'gcr.io/cloud-builders/docker' - entrypoint: 'bash' - args: ['-c', 'docker pull gcr.io/$PROJECT_ID/[IMAGE_NAME]:latest || exit 0'] - - name: gcr.io/cloud-builders/docker - args: - - build - - '-t' - - '$_IMAGE_NAME:$COMMIT_SHA' - - '--cache-from' - - 'gcr.io/$PROJECT_ID/[IMAGE_NAME]:latest' - - . - - '-f' - - $_DOCKERFILE_NAME - dir: $_DOCKERFILE_DIR - id: Build - - name: gcr.io/cloud-builders/gke-deploy + - name: 'gcr.io/kaniko-project/executor:latest' args: - - prepare - - '--filename=$_K8S_YAML_PATH' - - '--image=$_IMAGE_NAME:$COMMIT_SHA' - - '--app=$_K8S_APP_NAME' - - '--version=$COMMIT_SHA' - - '--namespace=$_K8S_NAMESPACE' - - '--label=$_K8S_LABELS' - - '--annotation=$_K8S_ANNOTATIONS,gcb-build-id=$BUILD_ID' - - '--create-application-cr' - >- - --links="Build - details=https://console.cloud.google.com/cloud-build/builds/$BUILD_ID?project=$PROJECT_ID" - - '--output=output' - id: Prepare deploy - - name: gcr.io/cloud-builders/gsutil + --destination=us-central1-docker.pkg.dev/dara-c1b52/cloudbuild-pytest/gooey-server:$COMMIT_SHA + - '--cache=true' + - name: gcr.io/google.com/cloudsdktool/cloud-sdk args: - '-c' - - |- - if [ "$_OUTPUT_BUCKET_PATH" != "" ] - then - gsutil cp -r output/suggested gs://$_OUTPUT_BUCKET_PATH/config/$_K8S_APP_NAME/$BUILD_ID/suggested - gsutil cp -r output/expanded gs://$_OUTPUT_BUCKET_PATH/config/$_K8S_APP_NAME/$BUILD_ID/expanded - fi - id: Save configs - entrypoint: sh - - name: gcr.io/cloud-builders/gke-deploy + - > + gcloud secrets versions access latest + --secret="gooey-server-pytest-secrets" > /workspace/.env + entrypoint: bash + - name: gcr.io/cloud-builders/docker + entrypoint: docker-compose args: - - apply - - '--filename=output/expanded' - - '--cluster=$_GKE_CLUSTER' - - '--location=$_GKE_LOCATION' - - '--namespace=$_K8S_NAMESPACE' - id: Apply deploy -images: - - '$_IMAGE_NAME:$COMMIT_SHA' + - run + - us-central1-docker.pkg.dev/dara-c1b52/cloudbuild-pytest/gooey-server:$COMMIT_SHA + - bash + - '-c' + - | + echo "Activating Poetry environment..." + poetry run echo "Poetry environment activated." + echo "Running Django migrations..." + poetry run ./manage.py migrate + echo "Running pytest..." + poetry run pytest -v + entrypoint: docker options: - substitutionOption: ALLOW_LOOSE -substitutions: - _K8S_YAML_PATH: k8s/ - _K8S_LABELS: '' - _IMAGE_NAME: gcr.io/dara-c1b52/github.com/dara-network/ddgai - _GKE_CLUSTER: gooey-cluster-us-1 - _OUTPUT_BUCKET_PATH: dara-c1b52_cloudbuild/deploy - _K8S_NAMESPACE: default - _K8S_ANNOTATIONS: gcb-trigger-id=55dd6852-1610-461f-95da-19e8660e03d5 - _DOCKERFILE_NAME: Dockerfile - _K8S_APP_NAME: gooey-streamlit - _GKE_LOCATION: us-central1 - _DOCKERFILE_DIR: '' -tags: - - gcp-cloud-build-deploy - - $_K8S_APP_NAME + pool: + name: projects/dara-c1b52/locations/us-central1/workerPools/gooey diff --git a/docker-compose.yml b/docker-compose.yml new file mode 100644 index 000000000..ef15aedaa --- /dev/null +++ b/docker-compose.yml @@ -0,0 +1,38 @@ +version: '3.8' +services: + postgres: + image: postgres:latest + environment: + POSTGRES_USER: dev + POSTGRES_PASSWORD: password + POSTGRES_DB: gooey + ports: + - "5432:5432" + volumes: + - postgres-data:/var/lib/postgresql/data + + redis: + image: redis:7 + ports: + - "6379:6379" + + app: + image: "us-central1-docker.pkg.dev/dara-c1b52/cloudbuild-pytest/gooey-server:$COMMIT_SHA" + depends_on: + - redis + - postgres + command: + - bash + - '-c' + - | + echo "Downloading fixtures" + wget https://storage.googleapis.com/dara-c1b52.appspot.com/daras_ai/media/ca0f13b8-d6ed-11ee-870b-8e93953183bb/fixture.json + + echo "Running Django migrations..." + poetry run ./manage.py migrate + + echo "Running pytest..." + poetry run pytest -v + +volumes: + postgres-data: From 09785a8fd8d62405c7f5bd35f5bb0c651f8ed5cc Mon Sep 17 00:00:00 2001 From: Dev Aggarwal Date: Fri, 1 Mar 2024 09:52:45 +0530 Subject: [PATCH 02/18] cloudbuild --- cloudbuild.yaml | 14 +------------- 1 file changed, 1 insertion(+), 13 deletions(-) diff --git a/cloudbuild.yaml b/cloudbuild.yaml index 793e7156b..3415441a6 100644 --- a/cloudbuild.yaml +++ b/cloudbuild.yaml @@ -13,19 +13,7 @@ steps: entrypoint: bash - name: gcr.io/cloud-builders/docker entrypoint: docker-compose - args: - - run - - us-central1-docker.pkg.dev/dara-c1b52/cloudbuild-pytest/gooey-server:$COMMIT_SHA - - bash - - '-c' - - | - echo "Activating Poetry environment..." - poetry run echo "Poetry environment activated." - echo "Running Django migrations..." - poetry run ./manage.py migrate - echo "Running pytest..." - poetry run pytest -v - entrypoint: docker + args: up options: pool: name: projects/dara-c1b52/locations/us-central1/workerPools/gooey From 1a0afe77a82e60d444aefcf6cc6d2beac3d8e549 Mon Sep 17 00:00:00 2001 From: Dev Aggarwal Date: Fri, 1 Mar 2024 09:53:44 +0530 Subject: [PATCH 03/18] cloudbuild --- cloudbuild.yaml | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/cloudbuild.yaml b/cloudbuild.yaml index 3415441a6..b5ae530f7 100644 --- a/cloudbuild.yaml +++ b/cloudbuild.yaml @@ -13,7 +13,8 @@ steps: entrypoint: bash - name: gcr.io/cloud-builders/docker entrypoint: docker-compose - args: up + args: + - up options: pool: name: projects/dara-c1b52/locations/us-central1/workerPools/gooey From 23040beb2c57082db92ba6b66a54524bb0be4ebb Mon Sep 17 00:00:00 2001 From: Dev Aggarwal Date: Fri, 1 Mar 2024 10:05:08 +0530 Subject: [PATCH 04/18] cloudbuild --- cloudbuild.yaml | 7 ++----- docker-compose.yml | 2 +- 2 files changed, 3 insertions(+), 6 deletions(-) diff --git a/cloudbuild.yaml b/cloudbuild.yaml index b5ae530f7..437c094d5 100644 --- a/cloudbuild.yaml +++ b/cloudbuild.yaml @@ -1,15 +1,12 @@ steps: - name: 'gcr.io/kaniko-project/executor:latest' args: - - >- - --destination=us-central1-docker.pkg.dev/dara-c1b52/cloudbuild-pytest/gooey-server:$COMMIT_SHA + - '--destination=us-central1-docker.pkg.dev/dara-c1b52/cloudbuild-pytest/gooey-server:$COMMIT_SHA' - '--cache=true' - name: gcr.io/google.com/cloudsdktool/cloud-sdk args: - '-c' - - > - gcloud secrets versions access latest - --secret="gooey-server-pytest-secrets" > /workspace/.env + - 'gcloud secrets versions access latest --secret="gooey-server-pytest-secrets" > /workspace/.env' entrypoint: bash - name: gcr.io/cloud-builders/docker entrypoint: docker-compose diff --git a/docker-compose.yml b/docker-compose.yml index ef15aedaa..d78de2742 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -1,7 +1,7 @@ version: '3.8' services: postgres: - image: postgres:latest + image: postgres:15.2 environment: POSTGRES_USER: dev POSTGRES_PASSWORD: password From c6c0f3b8c59c9d79df53b21475766574cd1e1f6c Mon Sep 17 00:00:00 2001 From: Dev Aggarwal Date: Fri, 1 Mar 2024 10:09:17 +0530 Subject: [PATCH 05/18] cloudbuild --- docker-compose.yml | 1 - 1 file changed, 1 deletion(-) diff --git a/docker-compose.yml b/docker-compose.yml index d78de2742..21186cab2 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -1,4 +1,3 @@ -version: '3.8' services: postgres: image: postgres:15.2 From 64111c6be43826f54a3bbddcbdecfcc5dd869904 Mon Sep 17 00:00:00 2001 From: Dev Aggarwal Date: Fri, 1 Mar 2024 10:13:47 +0530 Subject: [PATCH 06/18] cloudbuild --- docker-compose.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/docker-compose.yml b/docker-compose.yml index 21186cab2..a64079f6c 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -1,3 +1,4 @@ +version: '3.3' services: postgres: image: postgres:15.2 From c9dd6c470259bebb0c2f5dd231a5e9318602a12d Mon Sep 17 00:00:00 2001 From: Dev Aggarwal Date: Fri, 1 Mar 2024 10:18:15 +0530 Subject: [PATCH 07/18] cloudbuild --- cloudbuild.yaml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/cloudbuild.yaml b/cloudbuild.yaml index 437c094d5..3d7342292 100644 --- a/cloudbuild.yaml +++ b/cloudbuild.yaml @@ -12,6 +12,8 @@ steps: entrypoint: docker-compose args: - up + env: + - 'COMMIT_SHA=$COMMIT_SHA' options: pool: name: projects/dara-c1b52/locations/us-central1/workerPools/gooey From 4d3d8aa0c86016e4445325fcdc62f235cbda2585 Mon Sep 17 00:00:00 2001 From: Dev Aggarwal Date: Fri, 1 Mar 2024 10:26:48 +0530 Subject: [PATCH 08/18] cloudbuild --- docker-compose.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docker-compose.yml b/docker-compose.yml index a64079f6c..7773ec1c2 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -26,7 +26,7 @@ services: - '-c' - | echo "Downloading fixtures" - wget https://storage.googleapis.com/dara-c1b52.appspot.com/daras_ai/media/ca0f13b8-d6ed-11ee-870b-8e93953183bb/fixture.json + wget -q https://storage.googleapis.com/dara-c1b52.appspot.com/daras_ai/media/ca0f13b8-d6ed-11ee-870b-8e93953183bb/fixture.json echo "Running Django migrations..." poetry run ./manage.py migrate From 2993a405005a57cc095912d8229dcd643881e1fa Mon Sep 17 00:00:00 2001 From: Dev Aggarwal Date: Fri, 1 Mar 2024 10:34:12 +0530 Subject: [PATCH 09/18] cloudbuild --- docker-compose.yml | 14 +++----------- scripts/run-tests.sh | 8 ++++++++ 2 files changed, 11 insertions(+), 11 deletions(-) create mode 100644 scripts/run-tests.sh diff --git a/docker-compose.yml b/docker-compose.yml index 7773ec1c2..eba643135 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -22,17 +22,9 @@ services: - redis - postgres command: - - bash - - '-c' - - | - echo "Downloading fixtures" - wget -q https://storage.googleapis.com/dara-c1b52.appspot.com/daras_ai/media/ca0f13b8-d6ed-11ee-870b-8e93953183bb/fixture.json - - echo "Running Django migrations..." - poetry run ./manage.py migrate - - echo "Running pytest..." - poetry run pytest -v + - poetry + - run + - ./scripts/run-tests.sh volumes: postgres-data: diff --git a/scripts/run-tests.sh b/scripts/run-tests.sh new file mode 100644 index 000000000..17ece2ccd --- /dev/null +++ b/scripts/run-tests.sh @@ -0,0 +1,8 @@ +echo "Downloading fixtures" +wget -q https://storage.googleapis.com/dara-c1b52.appspot.com/daras_ai/media/ca0f13b8-d6ed-11ee-870b-8e93953183bb/fixture.json + +echo "Running Django migrations..." +./manage.py migrate + +echo "Running pytest..." +ulimit -n unlimited && pytest From 654799cc6f81908c734864cfbd4a462e813606e3 Mon Sep 17 00:00:00 2001 From: Dev Aggarwal Date: Fri, 1 Mar 2024 10:45:42 +0530 Subject: [PATCH 10/18] cloudbuild --- cloudbuild.yaml | 4 +++- docker-compose.yml | 2 +- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/cloudbuild.yaml b/cloudbuild.yaml index 3d7342292..4f19a27be 100644 --- a/cloudbuild.yaml +++ b/cloudbuild.yaml @@ -11,7 +11,9 @@ steps: - name: gcr.io/cloud-builders/docker entrypoint: docker-compose args: - - up + - 'up' + - '--exit-code-from=pytest' + - '--abort-on-container-exit' env: - 'COMMIT_SHA=$COMMIT_SHA' options: diff --git a/docker-compose.yml b/docker-compose.yml index eba643135..bc95c933c 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -16,7 +16,7 @@ services: ports: - "6379:6379" - app: + pytest: image: "us-central1-docker.pkg.dev/dara-c1b52/cloudbuild-pytest/gooey-server:$COMMIT_SHA" depends_on: - redis From 22a351c9f972d46a439905bfe6342f5fcb77fbe9 Mon Sep 17 00:00:00 2001 From: Dev Aggarwal Date: Fri, 1 Mar 2024 10:51:20 +0530 Subject: [PATCH 11/18] cloudbuild --- scripts/run-tests.sh | 0 1 file changed, 0 insertions(+), 0 deletions(-) mode change 100644 => 100755 scripts/run-tests.sh diff --git a/scripts/run-tests.sh b/scripts/run-tests.sh old mode 100644 new mode 100755 From 527585d6b6e17045af1506c271d7b12abdf5e39c Mon Sep 17 00:00:00 2001 From: Dev Aggarwal Date: Fri, 1 Mar 2024 10:55:44 +0530 Subject: [PATCH 12/18] cloudbuild --- scripts/run-tests.sh | 2 ++ 1 file changed, 2 insertions(+) diff --git a/scripts/run-tests.sh b/scripts/run-tests.sh index 17ece2ccd..0b7e4c902 100755 --- a/scripts/run-tests.sh +++ b/scripts/run-tests.sh @@ -1,3 +1,5 @@ +#!/usr/bin/env bash + echo "Downloading fixtures" wget -q https://storage.googleapis.com/dara-c1b52.appspot.com/daras_ai/media/ca0f13b8-d6ed-11ee-870b-8e93953183bb/fixture.json From 95f58ee381b3422e102fc816e8e5498079e9965f Mon Sep 17 00:00:00 2001 From: Dev Aggarwal Date: Fri, 1 Mar 2024 11:02:01 +0530 Subject: [PATCH 13/18] cloudbuild --- scripts/run-tests.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/run-tests.sh b/scripts/run-tests.sh index 0b7e4c902..ddfe8b4cb 100755 --- a/scripts/run-tests.sh +++ b/scripts/run-tests.sh @@ -7,4 +7,4 @@ echo "Running Django migrations..." ./manage.py migrate echo "Running pytest..." -ulimit -n unlimited && pytest +pytest From da2bfaa4b06b5a87b5a65abf7d316d2c8ac9dc55 Mon Sep 17 00:00:00 2001 From: Dev Aggarwal Date: Fri, 1 Mar 2024 11:17:48 +0530 Subject: [PATCH 14/18] cloudbuild --- docker-compose.yml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/docker-compose.yml b/docker-compose.yml index bc95c933c..d933cc991 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -25,6 +25,8 @@ services: - poetry - run - ./scripts/run-tests.sh + volumes: + - /workspace/.env:/app/.env volumes: postgres-data: From 9474ca3dbf2edd1bfbb993deba86835eeb0368bd Mon Sep 17 00:00:00 2001 From: Dev Aggarwal Date: Fri, 1 Mar 2024 11:27:24 +0530 Subject: [PATCH 15/18] cloudbuild --- docker-compose.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/docker-compose.yml b/docker-compose.yml index d933cc991..a588e26a8 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -27,6 +27,7 @@ services: - ./scripts/run-tests.sh volumes: - /workspace/.env:/app/.env + network_mode: "host" # Use the host network volumes: postgres-data: From 5b15bbb25c6155494b4e9fb2b7eb4160ab51b6f9 Mon Sep 17 00:00:00 2001 From: Dev Aggarwal Date: Fri, 1 Mar 2024 11:40:15 +0530 Subject: [PATCH 16/18] cloudbuild --- docker-compose.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/docker-compose.yml b/docker-compose.yml index a588e26a8..c56f53d3d 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -10,6 +10,7 @@ services: - "5432:5432" volumes: - postgres-data:/var/lib/postgresql/data + command: postgres -c 'max_connections=10000' redis: image: redis:7 From c20f920d1a53500cfb3e605b63fbe3e55498dbca Mon Sep 17 00:00:00 2001 From: Dev Aggarwal Date: Fri, 1 Mar 2024 12:17:43 +0530 Subject: [PATCH 17/18] cloudbuild --- cloudbuild.yaml | 4 +++- docker-compose.yml | 1 + 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/cloudbuild.yaml b/cloudbuild.yaml index 4f19a27be..5ea7f49a6 100644 --- a/cloudbuild.yaml +++ b/cloudbuild.yaml @@ -6,7 +6,9 @@ steps: - name: gcr.io/google.com/cloudsdktool/cloud-sdk args: - '-c' - - 'gcloud secrets versions access latest --secret="gooey-server-pytest-secrets" > /workspace/.env' + - | + gcloud secrets versions access latest --secret="gooey-server-pytest-secrets" > /workspace/.env + gcloud secrets versions access latest --secret="gooey-server-pytest-service-account-key" > /workspace/serviceAccountKey.json entrypoint: bash - name: gcr.io/cloud-builders/docker entrypoint: docker-compose diff --git a/docker-compose.yml b/docker-compose.yml index c56f53d3d..2022d730c 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -28,6 +28,7 @@ services: - ./scripts/run-tests.sh volumes: - /workspace/.env:/app/.env + - /workspace/serviceAccountKey.json:/app/serviceAccountKey.json network_mode: "host" # Use the host network volumes: From a19b6a92f7f6cddb471e74b6b05accab7adc9917 Mon Sep 17 00:00:00 2001 From: Dev Aggarwal Date: Fri, 1 Mar 2024 12:47:23 +0530 Subject: [PATCH 18/18] cloudbuild --- scripts/run-tests.sh | 3 --- 1 file changed, 3 deletions(-) diff --git a/scripts/run-tests.sh b/scripts/run-tests.sh index ddfe8b4cb..aa179c183 100755 --- a/scripts/run-tests.sh +++ b/scripts/run-tests.sh @@ -3,8 +3,5 @@ echo "Downloading fixtures" wget -q https://storage.googleapis.com/dara-c1b52.appspot.com/daras_ai/media/ca0f13b8-d6ed-11ee-870b-8e93953183bb/fixture.json -echo "Running Django migrations..." -./manage.py migrate - echo "Running pytest..." pytest