I’m currently using Cloud Build to build HTML and JavaScript codes when they’re pushed to a specific repository on GitHub.
After build process is completed, files and folders are transferred to a Compute Engine instance via SCP. The static internal IP(10.0.0.2) is assigned to the instance.
What I want to achieve
I want Cloud Build to transfer files and folders to the Compute Engine instance via SCP with internal IP so that I can restrict the source IP range for SSH port (port 22) in VPC firewall.
Using remote-builder as suggested in the following post is the best approach to make it work?
GC Cloud Build access to Compute Engine through internal IP
Or do I need to configure Cloud Build to use static external IP by using proxy VM as suggested in the following blog?
https://datatonic.com/insights/configuring-cloud-build-static-external-ip-addresses/
According to the below page, it seems the static external IP range for private pools are not officially supported as of now.
https://issuetracker.google.com/issues/197128153?pli=1
What I tried
I created a private pool for Cloud Build and configured it to access the VPC network to which the Compute Engine instance belongs via VPC peering.
Details
- Internal IP assigned to Compute Engine instance: 10.0.0.2
- Internal IP range of the private pool: 192.168.0.0/24
- External IP for the private pool: assigned (For retrieving source code from GitHub repository during build process. If not set, error occurs without internet connection.)
Verification results
When accessed from Cloud Build by curl, specifying the internal IP of the target Compute Engine instance, the access from the private pool’s internal IP range was confirmed from server logs.
However, when SCP was executed to the instance with the internal IP, the following error occurred during the process of transferring with SCP.
ERROR: gcloud crashed (UnboundLocalError): cannot access local variable 'instance' where it is not associated with a value
Codes
cloudbuild.yaml
steps:
- id: "Delete unnecessary files"
name: "ubuntu"
entrypoint: "bash"
args: ["./build.sh"]
- id: "Transfer all files with scp"
name: "gcr.io/google.com/cloudsdktool/cloud-sdk"
entrypoint: "gcloud"
args:
[
"compute",
"scp",
"--project",
"test-project",
"--region",
"asia-northeast1",
"--zone",
"asia-northeast1-a",
"--network",
"test-vpc",
"--port",
"22",
"--recurse",
"./test",
"test-user@target-vm:/home/app/build-test",
"--internal-ip",
]
options:
pool:
name: projects/test-project/locations/asia-northeast1/workerPools/test-private-pool
timeout: 1800s
build.sh
#!/bin/bash
if [ -e "README.md" ]
then
rm README.md
fi
mkdir test
GLOBIGNORE="test:cloudbuild.yaml:build.sh:.git:.gitignore:.vscode"
mv * ./test
unset GLOBIGNORE
Thank you in advance.
tipotto is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.