mirror of
https://github.com/containers/podman.git
synced 2025-10-25 18:25:59 +08:00
Merge pull request #16776 from Luap99/http-proxy
remote: allow --http-proxy for remote clients
This commit is contained in:
@ -621,7 +621,6 @@ func DefineCreateFlags(cmd *cobra.Command, cf *entities.ContainerCreateOptions,
|
||||
|
||||
if registry.IsRemote() {
|
||||
_ = createFlags.MarkHidden("env-host")
|
||||
_ = createFlags.MarkHidden("http-proxy")
|
||||
_ = createFlags.MarkHidden(decryptionKeysFlagName)
|
||||
} else {
|
||||
createFlags.StringVar(
|
||||
|
||||
@ -168,16 +168,7 @@ func buildFlags(cmd *cobra.Command) {
|
||||
logrus.Errorf("Setting up build flags: %v", err)
|
||||
os.Exit(1)
|
||||
}
|
||||
// --http-proxy flag
|
||||
// containers.conf defaults to true but we want to force false by default for remote, since settings do not apply
|
||||
if registry.IsRemote() {
|
||||
flag = fromAndBudFlags.Lookup("http-proxy")
|
||||
buildOpts.HTTPProxy = false
|
||||
if err := flag.Value.Set("false"); err != nil {
|
||||
logrus.Errorf("Unable to set --https-proxy to %v: %v", false, err)
|
||||
}
|
||||
flag.DefValue = "false"
|
||||
}
|
||||
|
||||
flags.AddFlagSet(&fromAndBudFlags)
|
||||
// Add the completion functions
|
||||
fromAndBudFlagsCompletions := buildahCLI.GetFromAndBudFlagsCompletions()
|
||||
|
||||
@ -1,5 +1,5 @@
|
||||
####> This option file is used in:
|
||||
####> podman create, run
|
||||
####> podman build, create, run
|
||||
####> If file is edited, make sure the changes
|
||||
####> are applicable to all of those.
|
||||
#### **--http-proxy**
|
||||
@ -14,6 +14,7 @@ for the container in any other way will override the values that would have
|
||||
been passed through from the host. (Other ways to specify the proxy for the
|
||||
container include passing the values with the **--env** flag, or hard coding the
|
||||
proxy environment at container build time.)
|
||||
(This option is not available with the remote Podman client, including Mac and Windows (excluding WSL2) machines)
|
||||
When used with the remote client it will use the proxy environment variables
|
||||
that are set on the server process.
|
||||
|
||||
Defaults to **true**.
|
||||
|
||||
@ -303,9 +303,7 @@ For the bind-mount conditions, only mounts explicitly requested by the caller vi
|
||||
|
||||
If --hooks-dir is unset for root callers, Buildah will currently default to /usr/share/containers/oci/hooks.d and /etc/containers/oci/hooks.d in order of increasing precedence. Using these defaults is deprecated, and callers should migrate to explicitly setting --hooks-dir.
|
||||
|
||||
#### **--http-proxy**
|
||||
|
||||
Pass through HTTP Proxy environment variables.
|
||||
@@option http-proxy
|
||||
|
||||
#### **--identity-label**
|
||||
|
||||
|
||||
@ -299,7 +299,7 @@ var _ = Describe("Podman build", func() {
|
||||
Expect(session.OutputToString()).To(ContainSubstring("hello"))
|
||||
})
|
||||
|
||||
It("podman build --http_proxy flag", func() {
|
||||
It("podman build http proxy test", func() {
|
||||
if env, found := os.LookupEnv("http_proxy"); found {
|
||||
defer os.Setenv("http_proxy", env)
|
||||
} else {
|
||||
@ -309,6 +309,9 @@ var _ = Describe("Podman build", func() {
|
||||
if IsRemote() {
|
||||
podmanTest.StopRemoteService()
|
||||
podmanTest.StartRemoteService()
|
||||
// set proxy env again so it will only effect the client
|
||||
// the remote client should still use the proxy that was set for the server
|
||||
os.Setenv("http_proxy", "127.0.0.2")
|
||||
}
|
||||
podmanTest.AddImageToRWStore(ALPINE)
|
||||
dockerfile := fmt.Sprintf(`FROM %s
|
||||
@ -317,10 +320,17 @@ RUN printenv http_proxy`, ALPINE)
|
||||
dockerfilePath := filepath.Join(podmanTest.TempDir, "Dockerfile")
|
||||
err := os.WriteFile(dockerfilePath, []byte(dockerfile), 0755)
|
||||
Expect(err).ToNot(HaveOccurred())
|
||||
session := podmanTest.Podman([]string{"build", "--pull-never", "--http-proxy", "--file", dockerfilePath, podmanTest.TempDir})
|
||||
// --http-proxy should be true by default so we do not set it
|
||||
session := podmanTest.Podman([]string{"build", "--pull-never", "--file", dockerfilePath, podmanTest.TempDir})
|
||||
session.Wait(120)
|
||||
Expect(session).Should(Exit(0))
|
||||
Expect(session.OutputToString()).To(ContainSubstring("1.2.3.4"))
|
||||
|
||||
// this tries to use the cache so we explicitly disable it
|
||||
session = podmanTest.Podman([]string{"build", "--no-cache", "--pull-never", "--http-proxy=false", "--file", dockerfilePath, podmanTest.TempDir})
|
||||
session.Wait(120)
|
||||
Expect(session).Should(Exit(1))
|
||||
Expect(session.ErrorToString()).To(ContainSubstring(`Error: building at STEP "RUN printenv http_proxy"`))
|
||||
})
|
||||
|
||||
It("podman build relay exit code to process", func() {
|
||||
|
||||
@ -130,6 +130,9 @@ ENV hello=world
|
||||
if IsRemote() {
|
||||
podmanTest.StopRemoteService()
|
||||
podmanTest.StartRemoteService()
|
||||
// set proxy env again so it will only effect the client
|
||||
// the remote client should still use the proxy that was set for the server
|
||||
os.Setenv("http_proxy", "127.0.0.2")
|
||||
}
|
||||
session := podmanTest.Podman([]string{"run", "--rm", ALPINE, "printenv", "http_proxy"})
|
||||
session.WaitWithDefaultTimeout()
|
||||
|
||||
@ -20,7 +20,7 @@ RUN echo $rand_content > /$rand_filename
|
||||
EOF
|
||||
|
||||
# The 'apk' command can take a long time to fetch files; bump timeout
|
||||
PODMAN_TIMEOUT=240 run_podman build -t build_test --format=docker --http-proxy $tmpdir
|
||||
PODMAN_TIMEOUT=240 run_podman build -t build_test --format=docker $tmpdir
|
||||
is "$output" ".*COMMIT" "COMMIT seen in log"
|
||||
|
||||
run_podman run --rm build_test cat /$rand_filename
|
||||
|
||||
Reference in New Issue
Block a user