I'm trying to put some integration tests in the Cloud Build process. So far I managed to connect to a MySQL server, but I can't connect to a Redis server since I can't add --vpc-connector
option to gradle test
command to configure Serverless VPC Connector.
This is part of cloudbuild.yaml
:
steps:
- name: 'gradle:6.8.3-jdk11'
args:
- 'test'
- '--no-daemon'
- '-i'
- '--stacktrace'
id: Test
entrypoint: gradle
- name: gcr.io/cloud-builders/docker
args:
- build
- '--no-cache'
- '-t'
- '$_GCR_HOSTNAME/$PROJECT_ID/$REPO_NAME/$_SERVICE_NAME:$COMMIT_SHA'
- .
- '-f'
- Dockerfile
id: Build
- name: gcr.io/cloud-builders/docker
args:
- push
- '$_GCR_HOSTNAME/$PROJECT_ID/$REPO_NAME/$_SERVICE_NAME:$COMMIT_SHA'
id: Push
- name: 'gcr.io/google.com/cloudsdktool/cloud-sdk:slim'
args:
- run
- services
- update
- $_SERVICE_NAME
- '--platform=managed'
- '--image=$_GCR_HOSTNAME/$PROJECT_ID/$REPO_NAME/$_SERVICE_NAME:$COMMIT_SHA'
- >-
--labels=managed-by=gcp-cloud-build-deploy-cloud-run,commit-sha=$COMMIT_SHA,gcb-build-id=$BUILD_ID,gcb-trigger-id=$_TRIGGER_ID,$_LABELS
- '--region=$_DEPLOY_REGION'
- '--quiet'
- '--vpc-connector=$_SERVERLESS_VPC_CONNECTOR'
id: Deploy
entrypoint: gcloud
(... omitted ...)
Everything works fine If I remove the Test
step. I need to add --vpc-connector
option to Test
step somehow to connect to the Redis server, but there is no such option in the gradle:6.8.3-jdk11
image.
How to configure Serverless VPC Connector in the Test
step so gradle test
command can connect to the Redis server?
You are mixing 2 concepts:
So, Gradle absolutely don't care about the infrastructure: It will try to reach a private IP, the REDIS private IP.
Cloud Build doesn't support VPC connector and thus, you can't access private resources in your project through Cloud Build. (A private preview is ongoing to have Cloud Build worker directly in your VPC and thus not to have this VPC connectivity issue (because already in the VPC), but I haven't visibility on a public preview of this feature)