Home > Enterprise >  Why isn't Cloud Code honoring my cloudbuild.yaml file but gcloud beta builds submit is?
Why isn't Cloud Code honoring my cloudbuild.yaml file but gcloud beta builds submit is?

Time:09-29

I am using Google's Cloud Code extension with Visual Studio Code to use GCP's Cloud Build and deploy to a local kubernetes cluster (Docker Desktop). I have directed Cloud Build to run unit tests after installing modules.

When I build using the command line gcloud beta builds submit, the Cloud Build does the module install and successfully fails to build because I intentionally wrote a failing unit test. So that's great.

However, when I try to build and deploy using the Cloud Code extension, it is not using my cloudbuild.yaml at all. I know this because the

1.) The build succeeds even with the failing unit test

2.) No logging from the unit test appears in GCP logging

3.) I completely deleted cloudbuild.yaml and the build / deploy still succeeded, which seems to imply Cloud Code is using Dockerfile

What do I need to do to ensure Cloud Code uses cloudbuild.yaml for its build/deploy to a local instance of kubernetes?

Thanks!

cloudbuild.yaml

steps:
- name: node
  entrypoint: npm
  args: ['install']
- id: "test"
  name: node
  entrypoint: npm
  args: ['test']
options:
  logging: CLOUD_LOGGING_ONLY

scaffold.yaml

apiVersion: skaffold/v2beta19
kind: Config
build:
  tagPolicy:
    sha256: {}
  artifacts:
  - context: .
    image: genesys-gencloud-dev
deploy:
  kubectl:
    manifests:
    - kubernetes-manifests/**
profiles:
- name: cloudbuild
  build:
    googleCloudBuild: {}

launch.json

{
  "configurations": [
    {
      "name": "Kubernetes: Run/Debug - cloudbuild",
      "type": "cloudcode.kubernetes",
      "request": "launch",
      "skaffoldConfig": "${workspaceFolder}\\skaffold.yaml",
      "profile": "cloudbuild",
      "watch": true,
      "cleanUp": false,
      "portForward": true,
      "internalConsoleOptions": "neverOpen",
      "imageRegistry": "gcr.io/my-gcp-project",
      "debug": [
        {
          "image": "my-image-dev",
          "containerName": "my-container-dev",
          "sourceFileMap": {
            "${workspaceFolder}": "/WORK_DIR"
          }
        }
      ]
    }
  ]
}

CodePudding user response:

You will need to edit your skaffold.yaml file to use Cloud Build:

build:
  googleCloudBuild: {}

See https://skaffold.dev/docs/pipeline-stages/builders/#remotely-on-google-cloud-build for more details.

EDIT: It looks like your skaffold.yaml enables cloud build for the cloudbuild profile, but that the profile isn't active.

Some options:

UDPATE (from asker)

I needed to do the following:

  1. Update skaffold.yaml as follows. In particular note the image, field under build > artifacts, and projectId field under profiles > build.
apiVersion: skaffold/v2beta19
kind: Config
build:
  tagPolicy:
    sha256: {}
  artifacts:
  - context: .
    image: gcr.io/my-project-id/my-image
deploy:
  kubectl:
    manifests:
    - kubernetes-manifests/**
profiles:
- name: cloudbuild
  build:
    googleCloudBuild:
      projectId: my-project-id
  1. Run this command to activate the profile: skaffold dev -p cloudbuild
  • Related