Commit 9d6bf5f1 authored by Noé Gaumont's avatar Noé Gaumont 🐙
Browse files

feat: remove onbuild images that are deprecated

parent 5fd5731101d4
ARG FROM
FROM $FROM
ONBUILD RUN echo "onbuild images are DEPRECATED, use plain $FROM image instead"
ONBUILD ARG CW_INSTANCE_NAME
ONBUILD ENV CW_INSTANCE=${CW_INSTANCE_NAME:-instance}
ONBUILD USER root
ONBUILD COPY . /src/
ONBUILD RUN pip install -e /src
ONBUILD USER cubicweb
ONBUILD RUN docker-cubicweb-helper create-instance
......@@ -67,9 +67,6 @@ Here are some hints to make the best choice:
* Images with cubicweb pre-installed build faster
* Images without cubicweb pre-installed allow to use your own version of cubicweb
* ``onbuild`` images are useful when the Dockerfile in versioned in the source
tree, except when your cube require a build toolchain to install. However
they are DEPRECATED.
Example
~~~~~~~
......@@ -94,29 +91,6 @@ also have to set the ``CUBE`` environment variable::
ENV CUBE=blog
RUN docker-cubicweb-helper create-instance
onbuild images
~~~~~~~~~~~~~~
.. warning:: A lot of magic happen with onbuild images. They are DEPRECATED.
All images have a ``onbuild`` version by adding the suffix ``-onbuild``.
The single tag ``onbuild`` is an alias for buster-3.29-onbuild.
These images use the `ONBUILD intruction`_ to copy current code to the build
context and install your cube in develop mode and create an instance of your cube.
.. _ONBUILD intruction: https://docs.docker.com/engine/reference/builder/#onbuild
For example, given you're in the source tree of `cubicweb-blog`_, a Dockerfile would be as simple as::
FROM logilab/cubicweb:onbuild
You can even build an image without actually writing any Dockerfile::
echo "FROM logilab/cubicweb:onbuild" | docker build -f - -t cubicweb-blog .
.. _cubicweb-blog: https://hg.logilab.org/master/cubes/blog
How to run resulting images ?
-----------------------------
......
......@@ -124,16 +124,11 @@ def tag_aliases(images: List[CubicWebImage], last_debian_dist: str):
fail_tags = []
for major, img in latest.items():
tag = f"{REGISTRY}:{major}"
for onbuild in [None, "onbuild"]:
if onbuild == "onbuild":
tag = f"{REGISTRY}:{major}-{onbuild}"
else:
tag = f"{REGISTRY}:{major}"
src = img.tag
res = run("docker", "tag", src, tag)
conditionnal_append(tags, fail_tags, res.returncode == 0, tag)
res = run("docker", "tag", src, img.major_tag)
conditionnal_append(tags, fail_tags, res.returncode == 0, img.major_tag)
src = img.tag
res = run("docker", "tag", src, tag)
conditionnal_append(tags, fail_tags, res.returncode == 0, tag)
res = run("docker", "tag", src, img.major_tag)
conditionnal_append(tags, fail_tags, res.returncode == 0, img.major_tag)
res = run(
"docker",
......@@ -148,20 +143,14 @@ def tag_aliases(images: List[CubicWebImage], last_debian_dist: str):
print_summary("tag", tags, fail_tags)
def build_image(image: CubicWebImage, onbuild: Optional[str], no_cache=False) -> bool:
def build_image(image: CubicWebImage, no_cache=False) -> bool:
args = {}
dockerfile = "Dockerfile"
if onbuild is not None:
dockerfile = "Dockerfile.onbuild"
args["FROM"] = image.tag
tag = image.tag + "-onbuild"
else:
dockerfile = "Dockerfile"
args["DIST"] = image.debian_dist
args["CUBICWEB_SOURCE"] = f"cubicweb[pyramid]=={image.cubicweb_version}"
tag = image.tag
if image.is_dev():
args["CUBICWEB_SOURCE"] = _cwdev()
args["DIST"] = image.debian_dist
args["CUBICWEB_SOURCE"] = f"cubicweb[pyramid]=={image.cubicweb_version}"
tag = image.tag
if image.is_dev():
args["CUBICWEB_SOURCE"] = _cwdev()
cmd = [
"docker",
......@@ -214,37 +203,34 @@ def build(debian_dists: List[str], images: List[CubicWebImage] = [], rebuild=Fal
built_images = []
failed_images = []
for image in images:
for image_type in (None, "onbuild"):
built = build_image(image, image_type)
conditionnal_append(
built_images, failed_images, built, f"{image}-{image_type}"
built = build_image(image)
conditionnal_append(built_images, failed_images, built, image)
# Do no try to update image not built
if built and rebuild:
tag = image.tag
out = run(
"docker",
"run",
"--rm",
"-t",
"--user",
"root",
"--entrypoint",
"check-docker-updates.sh",
tag,
"apt",
)
# Do no try to update image not built
if built and rebuild and image_type is None:
tag = image.tag
out = run(
"docker",
"run",
"--rm",
"-t",
"--user",
"root",
"--entrypoint",
"check-docker-updates.sh",
if out.returncode == 1:
LOG.warning(
red("%s debian packages updates are available: %s"),
tag,
"apt",
)
if out.returncode == 1:
LOG.warning(
red("%s debian packages updates are available: %s"),
tag,
out.stdout,
)
build_image(image, image_type, no_cache=True)
else:
assert (out.returncode, out.stdout) == (0, b""), out
LOG.info(green("%s debian packages are up-to-date"), tag)
build_image(image, no_cache=True)
else:
assert (out.returncode, out.stdout) == (0, b""), out
LOG.info(green("%s debian packages are up-to-date"), tag)
print_summary("build image", built_images, failed_images)
......@@ -258,7 +244,6 @@ def push(images: List[CubicWebImage], last_debian_dist: str):
def major_tags_gen():
for major, img in latest.items():
yield f"{REGISTRY}:{major}-onbuild"
yield f"{REGISTRY}:{major}"
if major != "latest":
yield img.major_tag
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment