Skip to content

Bug: stacker convert does not convert Dockerfile FROM-AS correctly #756

@jmblatten

Description

@jmblatten

stacker version

v1.1.6

Describe the bug

Dockerfile FROM-AS defines a build stage. The FROM is the base for that build stage and the AS gives the build stage a name. The stacker convert does the correct thing with the AS portion, but each "FROM name" becomes "type: docker" and "url: name". The problem is, the FROM can name a build stage in the Dockerfile and not a url to fetch a base image. The stacker build then fails to build such a converted stacker.yaml file.

i.e.
Dockerfile:
FROM docker.io/library/ubuntu:jammy AS my-base
FROM my-base AS A
COPY hello /tmp/hello
FROM A AS B

converted stacker.yaml:

A:
 build_env:
   arch: amd64
 from:
   type: docker
   url: docker://my-base
 imports:
 - dest: /tmp/hello
   path: hello
B:
 build_env:
   arch: amd64
 from:
   type: docker
   url: docker://A
my-base:
 build_env:
   arch: amd64
 from:
   type: docker
   url: docker://docker.io/library/ubuntu:jammy

Attempt a stacker build,
$ stacker build -f stacker.yaml
Creating new OCI Layout at "/home/ubuntu/testrun/oci"
preparing image A...
copying /home/ubuntu/testrun/hello
imported file hashes (after substitutions):
loading docker://my-base
error: couldn't import base layer my-base: initializing source docker://my-base:latest: reading manifest latest in docker.io/library/my-base: requested access to the resource is denied
error: exit status 1

Note that stacker is unable to get "docker://my-base".

Proposed Solution:
Perhaps the "FROM name" portion of a FROM-AS instruction that does not include a ":" could be interpreted as a stacker layer. And thus converted into "type: built" and "tag: name". If ":" is there then convert to "type: docker" and "url: name". When this is done, stacker build works.

To reproduce

See above.

Expected behavior

See above.

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