Hi all, with IamgeSpec I can execute RUN command, ...
# flyte-support
s
Hi all, with IamgeSpec I can execute RUN command, I also want to execute COPY command, am I able to do so?
a
Hey Denis, yes Using
.with_commands
you should be able to
s
I tried
Copy code
image_spec = ImageSpec().with_commands(
    'COPY ./packages /packages'
)
Got the error
Copy code
=> ERROR [stage-2  8/10] RUN COPY ./packages /packages                      0.2s
------
 > [stage-2  8/10] RUN COPY ./packages /packages:
0.142 /bin/sh: 1: COPY: not found
------
Dockerfile:29
--------------------
  27 |
  28 |
  29 | >>> RUN COPY ./packages /packages
  30 |
  31 |
--------------------
ERROR: failed to solve: process "/bin/sh -c COPY ./packages /packages" did not complete successfully: exit code: 127
Looks like it is still
RUN
command
According to the code This command works
Copy code
image_spec = ImageSpec()
image_spec.copy = [
    './packages'
]
a
Sorry, for that one you should use .with_copy
s
Though it is not very convenient that extra run commands are executed before extra copy commands. Is there any reason for that?
h
The original intention of the design pattern is to allow composition and therefore ordering. I don't think the current implementation lives up to the premise. Would it be something you can help with? The simplest fix in my opinion is that every
with
should return a new ImageSpec with just the additional change (and points to the original as its base) At image build time, we just run through the linked list in order. @glamorous-carpet-83516 @high-accountant-32689
s
Sure, I’ll make a more careful look in a spare time
g
yup, we don’t support ordering for now. To wrokaround it, you can use nested imageSpec
Copy code
image_spec = ImageSpec(base_image=ImageSpec(copy={...})).with_commands(...)
flytekit will build the first image that copy packages to the image, and then use it as base image for the second imageSpec
s
Thank you!