appc / docker2aci

library and CLI tool to convert Docker images to ACIs (archived, see https://github.com/rkt/rkt/issues/4024)
Apache License 2.0
186 stars 60 forks source link

Converting local files from buildah fails "Could not find image" #257

Open orthecreedence opened 6 years ago

orthecreedence commented 6 years ago

Hello. I'm really excited about using rkt and have started playing with it a bit. One problem I'm having is that it's really difficult to create images that rkt can use without using Docker. I had hoped docker2aci could help, but it's giving me problems.

I'm currently using buildah (buildah version 0.10 (image-spec 1.0.0, runtime-spec 1.0.0)) and docker2aci (docker2aci version v0.17.1-2-g365911f-dirty / appc version 0.8.10) with both docker outputs and oci outputs:

# try with OCI
$ #sudo buildah bud /path/to/docker/repo
# success, creates image 183427cef41c
$ sudo buildah push 183427cef41c oci:my-app.oci:latest
# success, creates my-app.oci
$ docker2aci -debug ./my-app.oci
Getting image info...
getting image id...
Error: conversion error: Could not find image
# try with docker
$ sudo buildah bud /path/to/docker/repo
# success, creates image 183427cef41c
$ sudo buildah push 183427cef41c docker-archive:my-app.docker:latest
# success, creates my-app.docker
$ docker2aci -debug ./my-app.docker
Getting image info...
getting image id...
Error: conversion error: Could not find image

I've searched through a lot of the issues/PRs and it seems like OCI support and various Docker formats are supported, but after adding some debug info to lib/internal/backend/file/file.go it looks like it gets hung up on looking for repositories or refs/latest (seems like it's only checking for one specific format and giving up if it doesn't find it).

Any tips? Thanks!

tommie-lie commented 6 years ago

I stumbled over the same issue and thanks to you I figured out what is going on:

Support for OCI images in docker2aci was introduced well before OCI image spec 1.0.0 was released. The code has not seen too much of an update since then, at least not functionally. At the time, the refs/ directory was still the way to go. Shortly after, image-spec 1.0.0-rc5 was released which merged opencontainers/image-spec#533 which removed the refs/ directory and introduced index.json as the canonical place to identify refs.

Long story short: docker2aci does seem to only implement OCI image spec up until v1.0.0-rc4. buildah creates v1.0.0 (final) images. They are not compatible.

I could work around for my usecase by doing:

buildah push ID oci:my-app:latest
cd my-app
mkdir -p refs/
jq -j '.manifests[] | (tostring + "\u0000")' index.json  |xargs -0 -n1 sh -c 'tag=$(echo $0 | jq .annotations[\"org.opencontainers.image.ref.name\"] -r); echo $0 > refs/$tag'
cd ..
tar cf my-app.oci -C my-app .
docker2aci --image my-app:latest my-app.oci

My go-fu is to weak to fix this right away, but the difference between refs/* and index.json seems easy enough. Basically, what used to be refs/* is now the .manifests array and what used to be the filename of the ref is now annotations["org.opencontainers.image.ref.name"] in each element.

tommie-lie commented 6 years ago

I found someone who already did this: https://github.com/woofwoofinc/docker2aci/commit/d4e8e83bfaff27a65d6f7ff4657bcc66a21d0e0f

Their docker2aci works well with buildah's v1.0.0 oci images, but support for pre-v1.0.0-rc5 seems to be removed from their source (which is okay for my usecase).

orthecreedence commented 6 years ago

Oh, this is great! Thanks for pointing me in the right direction. I'm very familiar with go at all (same with all the different manifest formats floating around) so this is really helpful. I'll check out woofwoofinc's branch.