atomic icon indicating copy to clipboard operation
atomic copied to clipboard

There seems no way to pass dollar sign to atomic run via --opt1

Open adelton opened this issue 9 years ago • 5 comments

When string with dollar sign is passed as value of --opt1 to atomic run, the string disappears.

Consider Dockerfile

FROM fedora
LABEL RUN 'docker run --rm ${IMAGE} echo the value: ${OPT1}'

For "normal" values it works:

# atomic run --opt1=jezek test-double-sub_env_strings
docker run --rm test-double-sub_env_strings echo the value: jezek
the value: jezek

But for values with dollar sign it does not:

# atomic run --opt1='$jezek' test-double-sub_env_strings
docker run --rm test-double-sub_env_strings echo the value:
the value:

I suspect the reason is

        # Perform variable subs
        in_string = os.path.expandvars(in_string)

        # Replace undefined variables with blank
        in_string = re.sub(r'\$\{?\S*\}?', '', in_string)

in sub_env_strings -- the re.sub replaces not just undefined variables, but also results of previous successful expandvars which put the $jezek there instead of ${OPT1}.

adelton avatar Aug 18 '16 07:08 adelton

On related note, I'm also concerned by a double expansion attempts caused by

        cmd = self.gen_cmd(args)
        cmd = self.sub_env_strings(cmd)
        self.display(cmd)
        if self.args.display:
            return

        if not self.args.quiet:
            self.check_args(cmd)
        if not self.args.display:
            util.check_call(self.sub_env_strings(cmd), env=self.cmd_env())

in https://github.com/projectatomic/atomic/blob/master/Atomic/run.py#L50. Note that there is cmd = self.sub_env_strings(cmd), followed by util.check_call(self.sub_env_strings(cmd), ... -- the sub_env_strings is called twice.

adelton avatar Aug 18 '16 07:08 adelton

@adelton Are we ok on this one? Can I close it or do you think we still need to change?

rhatdan avatar Oct 11 '16 11:10 rhatdan

I'm not sure what the expected behaviour and handling of dollars should be.

I have atomic-1.13.1-1.el7.x86_64 and I see

# docker build -t issue-540 .
Sending build context to Docker daemon 2.048 kB
Step 1 : FROM fedora
 ---> 11a5107645d4
Step 2 : LABEL RUN 'docker run --rm ${IMAGE} echo the value: ${OPT1}'
 ---> Using cache
 ---> 084b61e41724
Successfully built 084b61e41724
# atomic run --opt1=jezek issue-540
docker run --rm issue-540 echo the value: jezek
the value: jezek
# atomic run --opt1='$jezek' issue-540
docker run --rm issue-540 echo the value:
the value:
# 

So the issue does not seem to be fixed.

adelton avatar Oct 14 '16 13:10 adelton

Is $jezek have a alue.?

If you do

jezek="foobar" atomic run --opt1='$jezek' issue-540 Do you get nothing?

rhatdan avatar Oct 14 '16 15:10 rhatdan

Right, nothing as well:

# jezek="foobar" atomic run --opt1='$jezek' issue-540
docker run --rm issue-540 echo the value:
the value:

adelton avatar Oct 27 '16 13:10 adelton