Skip to content

Commit

Permalink
cloudbuild
Browse files Browse the repository at this point in the history
  • Loading branch information
devxpy committed Mar 1, 2024
1 parent c6af347 commit 9bb0ef3
Show file tree
Hide file tree
Showing 2 changed files with 62 additions and 63 deletions.
87 changes: 24 additions & 63 deletions cloudbuild.yaml
Original file line number Diff line number Diff line change
@@ -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
38 changes: 38 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -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:

0 comments on commit 9bb0ef3

Please sign in to comment.