Skip to content

Bug: stacker convert is misplacing dockerfile ENV commands #757

@jmblatten

Description

@jmblatten

stacker version

v1.1.6

Describe the bug

stacker convert collects ENV command(s) and holds them in c.env assuming to use in the run section of that build stage. But if the build stage does not have a RUN, then the collected ENV is not used. Instead, it gets used in the next build stage that has a RUN. This seems incorrect behaviour.
Also, it seems ENV is inherited if in the base image. See, https://stackoverflow.com/questions/57577265/which-dockerfile-instructions-are-inherited-in-deriving- images#:~:text=1%20Comment-,Add%20a%20comment,2%2C31914%2022

To reproduce

i.e.
Dockerfile:
FROM docker.io/library/ubuntu:jammy AS my-base
ENV A_DIR="/tmp/a"
FROM base AS A
COPY hello /tmp/hello
FROM A AS B
RUN "echo "hello"
FROM B AS FINAL
ENV B_DIR="/tmp/b"
ENV C_DIR="/tmp/c"

Converted stacker.yaml

A:
 build_env:
  arch: amd64
 from:
  type: docker
  url: docker://base
 imports:
 - dest: /tmp/hello
  path: hello
B:
 build_env:
  arch: amd64
 from:
  type: docker
  url: docker://A
 run:
 - export A_DIR="/tmp/a"
 - sh -e -c '"echo "hello"'
FINAL:
 build_env:
  arch: amd64
 from:
  type: docker
  url: docker://B
my-base:
 build_env:
  arch: amd64
 from:
  type: docker
  url: docker://docker.io/library/ubuntu:jammy

Note that in Dockerfile, my-base contains the ENV instruction, but stacker exports it in layer B, which has a run section. layer A is ignored although it's base is my-base.

Possible solution:
The stacker docs note "environment" label which corresponds to OCI image config spec. See, https://github.com/project-stacker/stacker/blob/main/doc/stacker_yaml.md
Perhaps stacker convert could use this as the equivalent to dockerfile's ENV instruction?

Expected behavior

No response

Screenshots

No response

Additional context

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions