Take advantage of instance metadata to detect private IP address to use in Nomad and others
Auto-populate /etc/circleci/public-ipv4 with private IP address
Background
Historically, there was an issue that detection of private IP address for a Nomad client (see also: #176).
Recently, we found out that we need to populate /etc/circleci/public-ipv4 in Nomad clients with respective private IPv4 addresses for those using CircleCI in a private subnet without assigning public IPv4 addresses.
For the purpose fix is required to 1) detect whether any public IPv4 addresses is assigned, and 2) sniff correct private IPv4 address to write in /etc/circleci/public-ipv4; otherwise "Rebuild with SSH" is broken.
What will this change do?
Fill PRIVATE_IP variable at the top level using instance metadata.
Fill PUBLIC_IP variable using instance metadata.
If PUBLIC_IP contains characters unusable for IPv4 addresses (effectively meaning a circumstance that build-agent will fail to start upon "Rebuild with SSH"), populate /etc/circleci/public-ipv4 with PRIVATE_IP.
Considerations
I tested this change with my test environment and confirm that this change will not break existing Service boxes: terraform apply on this change just replace a launch configuration for Nomad clients and update ASG.
(It even means that operators have to manually destroy existing Nomad clients to apply this fix.)
Contribution checklist
☑️ I have read the Contributing Guidelines
☑️ Commits have been made with meaningful commit messages
☑️ All automated tests have passed successfully
Description
/etc/circleci/public-ipv4
with private IP addressBackground
/etc/circleci/public-ipv4
in Nomad clients with respective private IPv4 addresses for those using CircleCI in a private subnet without assigning public IPv4 addresses./etc/circleci/public-ipv4
; otherwise "Rebuild with SSH" is broken.What will this change do?
PRIVATE_IP
variable at the top level using instance metadata.PUBLIC_IP
variable using instance metadata.PUBLIC_IP
contains characters unusable for IPv4 addresses (effectively meaning a circumstance that build-agent will fail to start upon "Rebuild with SSH"), populate/etc/circleci/public-ipv4
withPRIVATE_IP
.Considerations
terraform apply
on this change just replace a launch configuration for Nomad clients and update ASG.Contribution checklist
☑️ I have read the Contributing Guidelines ☑️ Commits have been made with meaningful commit messages ☑️ All automated tests have passed successfully