Skip to content

Commit

Permalink
Cleanup base sources (pt. 1)
Browse files Browse the repository at this point in the history
Signed-off-by: Christian Berendt <[email protected]>
  • Loading branch information
berendt committed Jul 6, 2023
1 parent 1aaf84d commit 0d2e474
Show file tree
Hide file tree
Showing 3 changed files with 64 additions and 0 deletions.
16 changes: 16 additions & 0 deletions files/cleanup-base-sources.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
#!/usr/bin/env bash

for e in $(find /*-base-source -name '*config-generator*'); do
if [[ -d $e ]]; then
mkdir -p /x/$e
cp -r $e/* /x/$e
else
f=$(dirname $e)
mkdir -p /x/$f
cp -r $f/* /x/$f
fi
done

rm -rf /*-base-source
mv /x/* /
rm -rf /x
12 changes: 12 additions & 0 deletions scripts/004-build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,9 @@ done

# Build & squash base images

# The line can be commented out for tests to build keystone images only.
KOLLA_IMAGES_BASE=^keystone-base

kolla-build \
--template-override templates/$OPENSTACK_VERSION/template-overrides.j2 \
--config-file $KOLLA_CONF \
Expand All @@ -52,6 +55,9 @@ kolla-build \

# Build images

# The line can be commented out for tests to build keystone images only.
KOLLA_IMAGES=^keystone

kolla-build \
--template-override templates/$OPENSTACK_VERSION/template-overrides.j2 \
--config-file $KOLLA_CONF \
Expand All @@ -65,4 +71,10 @@ if grep -q "Failed with status: error" kolla-build-$BUILD_ID.log; then
exit 1
fi

# Cleanup images

python3 src/cleanup-images.py

# List images

docker images
36 changes: 36 additions & 0 deletions src/cleanup-images.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
#!/usr/bin/env python3

import os
import tempfile

from docker import DockerClient
from loguru import logger

VERSION = os.environ.get("OPENSTACK_VERSION", "zed")
FILTERS = {"label": f"de.osism.release.openstack={VERSION}"}

client = DockerClient()

for image in client.images.list(filters=FILTERS):
# skip images without a tag
if not image.tags:
continue

tag = image.tags[0]
logger.info(f"Cleaning up image {tag}")

with tempfile.NamedTemporaryFile() as fp:
fp.write(f"FROM {tag}\n".encode())

# full source directory required in the bifrost image
if "bifrost" not in tag:
fp.write(f"COPY files/cleanup-base-sources.sh /cleanup-base-sources.sh\n".encode())
fp.write(f"RUN bash /cleanup-base-sources.sh\n".encode())
fp.write(f"RUN rm /cleanup-base-sources.sh\n".encode())

fp.seek(0)

client.images.build(fileobj=fp, tag=tag, squash=True)

cmd = "docker-squash --tag {tag} --from-layer 1 {tag}"
subprocess.check_output(cmds, stderr=subprocess.STDOUT)

0 comments on commit 0d2e474

Please sign in to comment.