From 9a9a50d19482dfe1a227189a8ea38813a9df2b91 Mon Sep 17 00:00:00 2001 From: Dev Aggarwal Date: Fri, 1 Mar 2024 09:50:25 +0530 Subject: [PATCH] pytest on cloudbuild --- cloudbuild.yaml | 81 ++------ docker-compose.yml | 34 ++++ k8s/deployment.yaml | 425 ---------------------------------------- k8s/https-redirect.yaml | 7 - scripts/run-tests.sh | 7 + 5 files changed, 58 insertions(+), 496 deletions(-) create mode 100644 docker-compose.yml delete mode 100644 k8s/deployment.yaml delete mode 100644 k8s/https-redirect.yaml create mode 100755 scripts/run-tests.sh diff --git a/cloudbuild.yaml b/cloudbuild.yaml index 98e615ecf..5ea7f49a6 100644 --- a/cloudbuild.yaml +++ b/cloudbuild.yaml @@ -1,70 +1,23 @@ 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 + 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 args: - - apply - - '--filename=output/expanded' - - '--cluster=$_GKE_CLUSTER' - - '--location=$_GKE_LOCATION' - - '--namespace=$_K8S_NAMESPACE' - id: Apply deploy -images: - - '$_IMAGE_NAME:$COMMIT_SHA' + - 'up' + - '--exit-code-from=pytest' + - '--abort-on-container-exit' + env: + - 'COMMIT_SHA=$COMMIT_SHA' 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..cc1118ff4 --- /dev/null +++ b/docker-compose.yml @@ -0,0 +1,34 @@ +version: '3.3' +services: + postgres: + image: postgres:15.2 + environment: + POSTGRES_USER: dev + POSTGRES_PASSWORD: password + ports: + - "5432:5432" + volumes: + - postgres-data:/var/lib/postgresql/data + command: postgres -c 'max_connections=10000' + + redis: + image: redis:7 + ports: + - "6379:6379" + + pytest: + image: "us-central1-docker.pkg.dev/dara-c1b52/cloudbuild-pytest/gooey-server:$COMMIT_SHA" + depends_on: + - redis + - postgres + command: + - poetry + - run + - ./scripts/run-tests.sh + volumes: + - /workspace/.env:/app/.env + - /workspace/serviceAccountKey.json:/app/serviceAccountKey.json + network_mode: "host" # Use the host network + +volumes: + postgres-data: diff --git a/k8s/deployment.yaml b/k8s/deployment.yaml deleted file mode 100644 index 29a2baa63..000000000 --- a/k8s/deployment.yaml +++ /dev/null @@ -1,425 +0,0 @@ -apiVersion: apps/v1 -kind: Deployment -metadata: - annotations: - autopilot.gke.io/resource-adjustment: >- - {"input":{"containers":[{"limits":{"cpu":"4","ephemeral-storage":"2Gi","memory":"4Gi"},"requests":{"cpu":"2","ephemeral-storage":"2Gi","memory":"4Gi"},"name":"ddgai-1"}]},"output":{"containers":[{"limits":{"cpu":"2","ephemeral-storage":"2Gi","memory":"4Gi"},"requests":{"cpu":"2","ephemeral-storage":"2Gi","memory":"4Gi"},"name":"ddgai-1"}]},"modified":true} - labels: - app: gooey-streamlit - managedFields: - - apiVersion: apps/v1 - fieldsType: FieldsV1 - fieldsV1: - 'f:spec': - 'f:replicas': {} - manager: vpa-recommender - operation: Update - subresource: scale - - apiVersion: apps/v1 - fieldsType: FieldsV1 - fieldsV1: - 'f:spec': - 'f:template': - 'f:spec': - 'f:containers': - 'k:{"name":"ddgai-1"}': - 'f:env': - 'k:{"name":"DARS_API_ROOT"}': - 'f:valueFrom': - 'f:configMapKeyRef': {} - 'k:{"name":"GOOGLE_APPLICATION_CREDENTIALS_JSON"}': - .: {} - 'f:name': {} - 'f:valueFrom': - .: {} - 'f:secretKeyRef': {} - 'k:{"name":"GOOGLE_CLIENT_ID"}': - .: {} - 'f:name': {} - 'f:valueFrom': - .: {} - 'f:configMapKeyRef': {} - 'k:{"name":"GOOSEAI_API_KEY"}': - .: {} - 'f:name': {} - 'f:valueFrom': - .: {} - 'f:configMapKeyRef': {} - 'k:{"name":"GS_BUCKET_NAME"}': - .: {} - 'f:name': {} - 'f:valueFrom': - .: {} - 'f:configMapKeyRef': {} - 'k:{"name":"OPENAI_API_KEY"}': - .: {} - 'f:name': {} - 'f:valueFrom': - .: {} - 'f:configMapKeyRef': {} - 'k:{"name":"POSTMARK_API_TOKEN"}': - .: {} - 'f:name': {} - 'f:valueFrom': - .: {} - 'f:configMapKeyRef': {} - 'k:{"name":"REPLICATE_API_TOKEN"}': - .: {} - 'f:name': {} - 'f:valueFrom': - .: {} - 'f:configMapKeyRef': {} - 'k:{"name":"SECRET_KEY"}': - .: {} - 'f:name': {} - 'f:valueFrom': - .: {} - 'f:configMapKeyRef': {} - 'k:{"name":"UBERDUCK_KEY"}': - .: {} - 'f:name': {} - 'f:valueFrom': - .: {} - 'f:configMapKeyRef': {} - 'k:{"name":"UBERDUCK_SECRET"}': - .: {} - 'f:name': {} - 'f:valueFrom': - .: {} - 'f:configMapKeyRef': {} - 'f:resources': - 'f:limits': - 'f:cpu': {} - 'f:ephemeral-storage': {} - 'f:memory': {} - 'f:requests': - 'f:cpu': {} - 'f:ephemeral-storage': {} - 'f:memory': {} - manager: kubectl-edit - operation: Update - time: '2022-11-13T20:54:58Z' - - apiVersion: apps/v1 - fieldsType: FieldsV1 - fieldsV1: - 'f:metadata': - 'f:labels': - .: {} - 'f:app': {} - 'f:spec': - 'f:progressDeadlineSeconds': {} - 'f:revisionHistoryLimit': {} - 'f:selector': {} - 'f:strategy': - 'f:rollingUpdate': - .: {} - 'f:maxSurge': {} - 'f:maxUnavailable': {} - 'f:type': {} - 'f:template': - 'f:metadata': - 'f:labels': - .: {} - 'f:app': {} - 'f:spec': - 'f:containers': - 'k:{"name":"ddgai-1"}': - .: {} - 'f:env': - .: {} - 'k:{"name":"DARS_API_ROOT"}': - .: {} - 'f:name': {} - 'f:valueFrom': {} - 'k:{"name":"STREAMLIT_SERVER"}': - .: {} - 'f:name': {} - 'f:value': {} - 'f:image': {} - 'f:imagePullPolicy': {} - 'f:name': {} - 'f:resources': {} - 'f:terminationMessagePath': {} - 'f:terminationMessagePolicy': {} - 'f:dnsPolicy': {} - 'f:restartPolicy': {} - 'f:schedulerName': {} - 'f:securityContext': {} - 'f:terminationGracePeriodSeconds': {} - manager: GoogleCloudConsole - operation: Update - time: '2022-11-16T05:35:19Z' - - apiVersion: apps/v1 - fieldsType: FieldsV1 - fieldsV1: - 'f:metadata': - 'f:annotations': - 'f:deployment.kubernetes.io/revision': {} - 'f:status': - 'f:availableReplicas': {} - 'f:conditions': - .: {} - 'k:{"type":"Available"}': - .: {} - 'f:lastTransitionTime': {} - 'f:lastUpdateTime': {} - 'f:message': {} - 'f:reason': {} - 'f:status': {} - 'f:type': {} - 'k:{"type":"Progressing"}': - .: {} - 'f:lastTransitionTime': {} - 'f:lastUpdateTime': {} - 'f:message': {} - 'f:reason': {} - 'f:status': {} - 'f:type': {} - 'f:observedGeneration': {} - 'f:readyReplicas': {} - 'f:replicas': {} - 'f:unavailableReplicas': {} - 'f:updatedReplicas': {} - manager: kube-controller-manager - operation: Update - subresource: status - time: '2022-11-16T05:36:26Z' - name: gooey-streamlit - namespace: default -spec: - replicas: 2 - selector: - matchLabels: - app: gooey-streamlit - strategy: - rollingUpdate: - maxSurge: 25% - maxUnavailable: 25% - type: RollingUpdate - template: - metadata: - labels: - app: gooey-streamlit - spec: - containers: - - env: - - name: STREAMLIT_SERVER - value: '1' - - name: DARS_API_ROOT - valueFrom: - configMapKeyRef: - key: DARS_API_ROOT - name: gooey-env-1 - - name: OPENAI_API_KEY - valueFrom: - configMapKeyRef: - key: OPENAI_API_KEY - name: gooey-env-1 - - name: GOOSEAI_API_KEY - valueFrom: - configMapKeyRef: - key: GOOSEAI_API_KEY - name: gooey-env-1 - - name: REPLICATE_API_TOKEN - valueFrom: - configMapKeyRef: - key: REPLICATE_API_TOKEN - name: gooey-env-1 - - name: GS_BUCKET_NAME - valueFrom: - configMapKeyRef: - key: GS_BUCKET_NAME - name: gooey-env-1 - - name: SECRET_KEY - valueFrom: - configMapKeyRef: - key: SECRET_KEY - name: gooey-env-1 - - name: GOOGLE_CLIENT_ID - valueFrom: - configMapKeyRef: - key: GOOGLE_CLIENT_ID - name: gooey-env-1 - - name: UBERDUCK_KEY - valueFrom: - configMapKeyRef: - key: UBERDUCK_KEY - name: gooey-env-1 - - name: UBERDUCK_SECRET - valueFrom: - configMapKeyRef: - key: UBERDUCK_SECRET - name: gooey-env-1 - - name: POSTMARK_API_TOKEN - valueFrom: - configMapKeyRef: - key: POSTMARK_API_TOKEN - name: gooey-env-1 - - name: GOOGLE_APPLICATION_CREDENTIALS_JSON - valueFrom: - secretKeyRef: - key: GOOGLE_APPLICATION_CREDENTIALS_JSON - name: service-account-key - image: gcr.io/dara-c1b52/github.com/dara-network/ddgai - imagePullPolicy: IfNotPresent - name: ddgai-1 - resources: - limits: - cpu: '4' - ephemeral-storage: 2Gi - memory: 4Gi - requests: - cpu: '4' - ephemeral-storage: 2Gi - memory: 4Gi - securityContext: - capabilities: - drop: - - NET_RAW - securityContext: - seccompProfile: - type: RuntimeDefault - tolerations: - - effect: NoSchedule - key: kubernetes.io/arch - operator: Equal - value: amd64 ---- -apiVersion: autoscaling/v2 -kind: HorizontalPodAutoscaler -metadata: - labels: - app: gooey-streamlit - managedFields: - - apiVersion: autoscaling/v2 - fieldsType: FieldsV1 - fieldsV1: - 'f:metadata': - 'f:labels': - .: {} - 'f:app': {} - 'f:spec': - 'f:maxReplicas': {} - 'f:metrics': {} - 'f:minReplicas': {} - 'f:scaleTargetRef': - 'f:apiVersion': {} - 'f:kind': {} - 'f:name': {} - manager: GoogleCloudConsole - operation: Update - time: '2022-11-12T17:41:02Z' - - apiVersion: autoscaling/v2 - fieldsType: FieldsV1 - fieldsV1: - 'f:status': - 'f:conditions': - .: {} - 'k:{"type":"AbleToScale"}': - .: {} - 'f:lastTransitionTime': {} - 'f:message': {} - 'f:reason': {} - 'f:status': {} - 'f:type': {} - 'k:{"type":"ScalingActive"}': - .: {} - 'f:lastTransitionTime': {} - 'f:message': {} - 'f:reason': {} - 'f:status': {} - 'f:type': {} - 'k:{"type":"ScalingLimited"}': - .: {} - 'f:lastTransitionTime': {} - 'f:message': {} - 'f:reason': {} - 'f:status': {} - 'f:type': {} - 'f:currentMetrics': {} - 'f:currentReplicas': {} - 'f:desiredReplicas': {} - 'f:lastScaleTime': {} - manager: vpa-recommender - operation: Update - subresource: status - time: '2022-11-12T17:46:24Z' - name: gooey-streamlit-hpa-u5pa - namespace: default -spec: - maxReplicas: 2 - metrics: - - resource: - name: cpu - target: - averageUtilization: 80 - type: Utilization - type: Resource - minReplicas: 1 - scaleTargetRef: - apiVersion: apps/v1 - kind: Deployment - name: gooey-streamlit ---- -apiVersion: v1 -kind: Service -metadata: - annotations: - cloud.google.com/neg: '{"ingress":true}' - cloud.google.com/neg-status: >- - {"network_endpoint_groups":{"80":"k8s1-61b64d54-default-gooey-streamlit-p4x9f-80-9ead6c05"},"zones":["us-central1-a","us-central1-c","us-central1-f"]} - generateName: gooey-streamlit- - labels: - app: gooey-streamlit - managedFields: - - apiVersion: v1 - fieldsType: FieldsV1 - fieldsV1: - 'f:metadata': - 'f:generateName': {} - 'f:labels': - .: {} - 'f:app': {} - 'f:spec': - 'f:internalTrafficPolicy': {} - 'f:ports': - .: {} - 'k:{"port":80,"protocol":"TCP"}': - .: {} - 'f:port': {} - 'f:protocol': {} - 'f:targetPort': {} - 'f:selector': {} - 'f:sessionAffinity': {} - 'f:type': {} - manager: GoogleCloudConsole - operation: Update - time: '2022-11-15T16:33:04Z' - - apiVersion: v1 - fieldsType: FieldsV1 - fieldsV1: - 'f:metadata': - 'f:annotations': - 'f:cloud.google.com/neg-status': {} - manager: glbc - operation: Update - subresource: status - time: '2022-11-15T16:40:58Z' - name: gooey-streamlit-p4x9f - namespace: default -spec: - clusterIP: 10.18.129.33 - clusterIPs: - - 10.18.129.33 - internalTrafficPolicy: Cluster - ipFamilies: - - IPv4 - ipFamilyPolicy: SingleStack - ports: - - port: 80 - protocol: TCP - targetPort: 8000 - selector: - app: gooey-streamlit - sessionAffinity: None - type: ClusterIP diff --git a/k8s/https-redirect.yaml b/k8s/https-redirect.yaml deleted file mode 100644 index 9f7ee1c6a..000000000 --- a/k8s/https-redirect.yaml +++ /dev/null @@ -1,7 +0,0 @@ -apiVersion: networking.gke.io/v1beta1 -kind: FrontendConfig -metadata: - name: https-redirect -spec: - redirectToHttps: - enabled: true diff --git a/scripts/run-tests.sh b/scripts/run-tests.sh new file mode 100755 index 000000000..aa179c183 --- /dev/null +++ b/scripts/run-tests.sh @@ -0,0 +1,7 @@ +#!/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 + +echo "Running pytest..." +pytest