runtime icon indicating copy to clipboard operation
runtime copied to clipboard

Extract container image from app image

Open kaotika opened this issue 2 years ago • 0 comments

Hi,

I have some images in dual use: on kubernetes with acorn and in older environments or for special dev jobs with docker. Is there a simpler way to "extract" an image build with acorn then my following workflow?

Needed tools:

  • jq (apt install jq)
  • crane
  • acorn >= 0.8
FROM alpine
# some other cool stuff...
ARG image_name
LABEL image_name="${image_name}"
containers: "\(localData.alpine_container_name)": build: {
	context: "."
	buildArgs: {
		image_name: localData.alpine_container_name
	}
}

localData: {
    alpine_container_name: "alpine"
}
image_gun_base="registry.gitlab.com/my-company/my-image"
image_gun_tag="main"
image_gun_acorn="${image_gun_base}:${image_gun_tag}"

acorn build --push -t ${image_gun_acorn} .

# assume the second entry in the manifests list is the wanted image
image_digest=$(crane manifest ${image_gun_acorn} | jq -r .manifests[1].digest)
image_gun_subimage_with_sha="${image_gun_acorn}@${image_digest}"
image_gun_subimage="${image_gun_subimage_with_sha}/my-image:${image_gun_tag}"

# validate subimages manifest
crane manifest ${image_gun_subimage_with_sha} | jq

# copy image with crane or acorn
crane copy ${image_gun_subimage_with_sha} ${image_gun_subimage}
# or
acorn copy --force ${image_gun_subimage_with_sha} ${image_gun_subimage}

# validate copied image
crane manifest ${image_gun_subimage} | jq

kaotika avatar Sep 06 '23 08:09 kaotika