parse, validateExtraHost: honor Hostgateway in format
Flag `--add-host` should support `host-gateway` when argument is in the form of `buildah build --add-host=proxyhost:host-gateway .` This is consistent with podman. Closes: https://github.com/containers/podman/issues/26034 Signed-off-by: flouthoc <flouthoc.git@gmail.com>
This commit is contained in:
parent
5cc3e7d776
commit
56f3171ab0
|
@ -34,6 +34,12 @@ Add a custom host-to-IP mapping (host:ip)
|
|||
|
||||
Add a line to /etc/hosts. The format is hostname:ip. The **--add-host** option can be set multiple times. Conflicts with the --no-hosts option.
|
||||
|
||||
Instead of an IP address, the special flag host-gateway can be given. This resolves to an IP address the container can use to connect to the host. The IP address chosen depends on your network setup, thus there's no guarantee that Buildah can determine the host-gateway address automatically, which will then cause Buildah to fail with an error message. You can overwrite this IP address using the host_containers_internal_ip option in containers.conf.
|
||||
|
||||
The host-gateway address is also used by Buildah to automatically add the host.containers.internal and host.docker.internal hostnames to /etc/hosts. You can prevent that by either giving the --no-hosts option, or by setting host_containers_internal_ip="none" in containers.conf. If no host-gateway address was configured manually and Buildah fails to determine the IP address automatically, Buildah will silently skip adding these internal hostnames to /etc/hosts. If Buildah is running in a virtual machine using podman machine (this includes Mac and Windows hosts), Buildah will silently skip adding the internal hostnames to /etc/hosts, unless an IP address was configured manually; the internal hostnames are resolved by the gvproxy DNS resolver instead.
|
||||
|
||||
Buildah will use the /etc/hosts file of the host as a basis by default, i.e. any hostname present in this file will also be present in the /etc/hosts file of the container. A different base file can be configured using the base_hosts_file config in containers.conf
|
||||
|
||||
**--all-platforms**
|
||||
|
||||
Instead of building for a set of platforms specified using the **--platform** option, inspect the build's base images, and build for all of the platforms for which they are all available. Stages that use *scratch* as a starting point can not be inspected, so at least one non-*scratch* stage must be present for detection to work usefully.
|
||||
|
|
|
@ -23,6 +23,7 @@ import (
|
|||
"github.com/containers/buildah/internal/sbom"
|
||||
"github.com/containers/buildah/internal/tmpdir"
|
||||
"github.com/containers/buildah/pkg/sshagent"
|
||||
"github.com/containers/common/libnetwork/etchosts"
|
||||
"github.com/containers/common/pkg/auth"
|
||||
"github.com/containers/common/pkg/config"
|
||||
"github.com/containers/common/pkg/parse"
|
||||
|
@ -365,6 +366,9 @@ func validateExtraHost(val string) error {
|
|||
if len(arr) != 2 || len(arr[0]) == 0 {
|
||||
return fmt.Errorf("bad format for add-host: %q", val)
|
||||
}
|
||||
if arr[1] == etchosts.HostGateway {
|
||||
return nil
|
||||
}
|
||||
if _, err := validateIPAddress(arr[1]); err != nil {
|
||||
return fmt.Errorf("invalid IP address in add-host: %q", arr[1])
|
||||
}
|
||||
|
|
|
@ -6089,6 +6089,23 @@ _EOF
|
|||
expect_output --substring 'building at STEP "RUN grep "myhostname" /etc/hosts'
|
||||
}
|
||||
|
||||
@test "bud with --add-host with host-gateway" {
|
||||
skip_if_no_runtime
|
||||
|
||||
_prefetch alpine
|
||||
|
||||
mytmpdir=${TEST_SCRATCH_DIR}/my-dir
|
||||
mkdir -p ${mytmpdir}
|
||||
cat > $mytmpdir/Containerfile << _EOF
|
||||
from alpine
|
||||
run cat /etc/hosts
|
||||
_EOF
|
||||
|
||||
run_buildah build --add-host=myhostname:host-gateway -t testbud \
|
||||
$WITH_POLICY_JSON --file ${mytmpdir}/Containerfile ${mytimedir}
|
||||
expect_output --substring "myhostname"
|
||||
}
|
||||
|
||||
@test "bud with --cgroup-parent" {
|
||||
skip_if_rootless_environment
|
||||
skip_if_chroot
|
||||
|
|
Loading…
Reference in New Issue