How to access Compute Engine from Cloud Build with internal IP

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.

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
<code>ERROR: gcloud crashed (UnboundLocalError): cannot access local variable 'instance' where it is not associated with a value
</code>
<code>ERROR: gcloud crashed (UnboundLocalError): cannot access local variable 'instance' where it is not associated with a value </code>
ERROR: gcloud crashed (UnboundLocalError): cannot access local variable 'instance' where it is not associated with a value

Codes

cloudbuild.yaml

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
<code>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
</code>
<code>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 </code>
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

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
<code>#!/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
</code>
<code>#!/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 </code>
#!/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.

New contributor

tipotto is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.

Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa Dịch vụ tổ chức sự kiện 5 sao Thông tin về chúng tôi Dịch vụ sinh nhật bé trai Dịch vụ sinh nhật bé gái Sự kiện trọn gói Các tiết mục giải trí Dịch vụ bổ trợ Tiệc cưới sang trọng Dịch vụ khai trương Tư vấn tổ chức sự kiện Hình ảnh sự kiện Cập nhật tin tức Liên hệ ngay Thuê chú hề chuyên nghiệp Tiệc tất niên cho công ty Trang trí tiệc cuối năm Tiệc tất niên độc đáo Sinh nhật bé Hải Đăng Sinh nhật đáng yêu bé Khánh Vân Sinh nhật sang trọng Bích Ngân Tiệc sinh nhật bé Thanh Trang Dịch vụ ông già Noel Xiếc thú vui nhộn Biểu diễn xiếc quay đĩa Dịch vụ tổ chức tiệc uy tín Khám phá dịch vụ của chúng tôi Tiệc sinh nhật cho bé trai Trang trí tiệc cho bé gái Gói sự kiện chuyên nghiệp Chương trình giải trí hấp dẫn Dịch vụ hỗ trợ sự kiện Trang trí tiệc cưới đẹp Khởi đầu thành công với khai trương Chuyên gia tư vấn sự kiện Xem ảnh các sự kiện đẹp Tin mới về sự kiện Kết nối với đội ngũ chuyên gia Chú hề vui nhộn cho tiệc sinh nhật Ý tưởng tiệc cuối năm Tất niên độc đáo Trang trí tiệc hiện đại Tổ chức sinh nhật cho Hải Đăng Sinh nhật độc quyền Khánh Vân Phong cách tiệc Bích Ngân Trang trí tiệc bé Thanh Trang Thuê dịch vụ ông già Noel chuyên nghiệp Xem xiếc khỉ đặc sắc Xiếc quay đĩa thú vị
Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa
Thiết kế website Thiết kế website Thiết kế website Cách kháng tài khoản quảng cáo Mua bán Fanpage Facebook Dịch vụ SEO Tổ chức sinh nhật