Quickly patch a docker image
Overview
In this example we are going to apply a 2 line patch to the xena nova_compute to fix vgpu. We will then update the image in our registry and push it.
I have tested this by copying out the original file that needs patching on a live system to a backup file, making the new version in a new file testing and then making a patch.
After this we will move on to making a new image using a Dockerfile and then pushing back to the registry
Make the patch on the live system
copy original and make new version with changes
docker cp nova_compute:/var/lib/kolla/venv/lib/python3.6/site-packages/nova/virt/libvirt/config.py config.py.old cp config.py.old config.py vi config.py
ok now we creating a patch file like this using diff like this:
diff -Naur config.py.old config.py > vgpu.patch
cat vgpu.patch
--- config.py.old 2022-06-08 18:06:30.000000000 +0200
+++ config.py 2022-06-10 17:01:49.000000000 +0200
@@ -3136,6 +3136,8 @@
for c in xmldoc:
if c.tag == "name":
self.name = c.text
+ if len(self.name) > 41:
+ self.name = self.name[:41]
elif c.tag == "parent":
self.parent = c.text
elif c.tag == "capability" and c.get("type") in ['pci', 'net']:
ok great I will copy and past this file into my image building VM which is called centos stream 8 build in the admin project on the BMC demo system. if this has not changed then you should be able to hit this using
ssh centos@10.10.12.93
if you are on the VPN
patching the image on the centos-stream build vm
I have already setup this node to push to the registry
I make a patch folder in /home/centos/kolla-xena/nova-compute-vgpu-patch
I copy my patch file in (C&P in vi or scp is fine)
I make my script
cat patch.sh #!/bin/bash if [ ! -f ./config.py ]; then container_id=$(docker create registry.define-technology.com:5000/kolla/centos-source-nova-compute:13.1.0) docker cp $container_id:/var/lib/kolla/venv/lib/python3.6/site-packages/nova/virt/libvirt/config.py ./config.py patch --verbose --backup -p0 --forward ./config.py vgpu.patch docker rm $container_id fi docker build ./ -t kolla/centos-source-nova-compute:13.1.0-vpgu
What this does is (if there is no config.py in pwd)
- create a temporary container from the unpatched version in the registry created using kolla-build (registry.define-technology.com:5000/kolla/centos-source-nova-compute:13.1.0)
- copy out the original file we want to modify and patch it here
- patch the file using our patch file we copy and pasted in (yes we could have copied the original instead and skipped all these steps but it's a pain to go from vpn to another vpn)
- remove out temporary container
- finally use a docker file in the current dir that we will create next and tag the image in the local machine as kolla/centos-source-nova-compute:13.1.0-vpgu
I make my Dockerfile
cat Dockerfile FROM registry.define-technology.com:5000/kolla/centos-source-nova-compute:13.1.0 MAINTAINER definetech ADD config.py /var/lib/kolla/venv/lib/python3.6/site-packages/nova/virt/libvirt/config.py
What this does is pull the container from thee registry and add the file the script will make
I then make the patch script executable and run it
chmod a+x patch.sh ./patch.sh [centos@centos-stream-8-build nova-compute-vgpu-patch]$ ./patch.sh Hmm... Looks like a unified diff to me... The text leading up to this was: -------------------------- |--- config.py.orig 2022-06-08 16:06:30.000000000 +0000 |+++ config.py 2022-09-13 15:12:33.000000000 +0000 -------------------------- patching file ./config.py.orig Using Plan A... Hunk #1 succeeded at 3136. done 63e907d461e379f5aac0e01fd2e7a06ed192cc22dd7749000d15749f56af8a1d Sending build context to Docker daemon 129kB Step 1/3 : FROM registry.define-technology.com:5000/kolla/centos-source-nova-compute:13.1.0 ---> d679222ce5f6 Step 2/3 : MAINTAINER definetech ---> Using cache ---> a5116a321cf4 Step 3/3 : ADD config.py /var/lib/kolla/venv/lib/python3.6/site-packages/nova/virt/libvirt/config.py ---> Using cache ---> 9f24ce46cb50 Successfully built 9f24ce46cb50 Successfully tagged kolla/centos-source-nova-compute:13.1.0-vpgu
OK cool!
retag the image and push it
we need to tag it into the remote registry and push it like this: I tag it 2x so the xena tag points to this latest one so my kolla-ansible deploy will auto pull it next time the other is a specific version I can grab easily
docker image tag 6a73782c28e5 registry.define-technology.com:5000/kolla/centos-source-nova-compute:xena docker image tag 6a73782c28e5 registry.define-technology.com:5000/kolla/centos-source-nova-compute:13.1.0-vpgu
I then push both
[centos@centos-stream-8-build nov-compute-vgpu-patch]$ docker image push registry.define-technology.com:5000/kolla/centos-source-nova-compute:xena The push refers to repository [registry.define-technology.com:5000/kolla/centos-source-nova-compute] 9edd2979f9d7: Pushed 10a928327833: Layer already exists 72e10fe91e4b: Layer already exists 1a955b80310b: Layer already exists c1a9650e0fbe: Layer already exists db13f4375cdb: Layer already exists c86c5a7f9ba5: Layer already exists 0f03ed29d7ae: Layer already exists 157f8647b5a6: Layer already exists c00b5c2f7e2b: Layer already exists 8a81428241a4: Layer already exists 5df710584acd: Layer already exists e6c7a4598f0e: Layer already exists ca327191c31a: Layer already exists 4d67bdd24bbe: Layer already exists a4c469747181: Layer already exists a87ed12b9bd5: Layer already exists fa47a7b3f947: Layer already exists db26ae996658: Layer already exists f47b56de3bb8: Layer already exists c15e6d575719: Layer already exists 3a23548130c2: Layer already exists caa9beadec0d: Layer already exists 4f0c7c3cdca0: Layer already exists e45fcf539a8f: Layer already exists 940953f5da7b: Layer already exists 2295777f2289: Layer already exists 0f9e2cd6f428: Layer already exists d8ddf38fea32: Layer already exists 7e803b580653: Layer already exists 7f8db04cdf74: Layer already exists b0d8b48a0361: Layer already exists f1169f782306: Layer already exists d7db75e2b431: Layer already exists 4f2cfc8e1d9c: Layer already exists 2fda120dca9d: Layer already exists b20f86037b6a: Layer already exists cfb384290b61: Layer already exists 2fa7a397a825: Layer already exists 7cec48be98b5: Layer already exists e9f8533305d1: Layer already exists f0e656ec34e5: Layer already exists 8fb83a9e4695: Layer already exists 6ffceb8347ee: Layer already exists 22a079a22b0a: Layer already exists b8e0cedff7ca: Layer already exists 2beade966b29: Layer already exists 2bee813718b1: Layer already exists de74aa5c66af: Layer already exists 0067d70a5699: Layer already exists 55746cb9d6dc: Layer already exists 5d9ef8a0564d: Layer already exists e9b312bba1ab: Layer already exists c86122b5e4d3: Layer already exists 3813924f3fa4: Layer already exists xena: digest: sha256:cdbcd75ad9c9e551df481a33a5b4bcd273d0c6d48ebc36c24c49624d202822ce size: 11802 [centos@centos-stream-8-build nov-compute-vgpu-patch]$ docker image push registry.define-technology.com:5000/kolla/centos-source-nova-compute:13.1.0-vpgu The push refers to repository [registry.define-technology.com:5000/kolla/centos-source-nova-compute] 9edd2979f9d7: Layer already exists 10a928327833: Layer already exists 72e10fe91e4b: Layer already exists 1a955b80310b: Layer already exists c1a9650e0fbe: Layer already exists db13f4375cdb: Layer already exists c86c5a7f9ba5: Layer already exists 0f03ed29d7ae: Layer already exists 157f8647b5a6: Layer already exists c00b5c2f7e2b: Layer already exists 8a81428241a4: Layer already exists 5df710584acd: Layer already exists e6c7a4598f0e: Layer already exists ca327191c31a: Layer already exists 4d67bdd24bbe: Layer already exists a4c469747181: Layer already exists a87ed12b9bd5: Layer already exists fa47a7b3f947: Layer already exists db26ae996658: Layer already exists f47b56de3bb8: Layer already exists c15e6d575719: Layer already exists 3a23548130c2: Layer already exists caa9beadec0d: Layer already exists 4f0c7c3cdca0: Layer already exists e45fcf539a8f: Layer already exists 940953f5da7b: Layer already exists 2295777f2289: Layer already exists 0f9e2cd6f428: Layer already exists d8ddf38fea32: Layer already exists 7e803b580653: Layer already exists 7f8db04cdf74: Layer already exists b0d8b48a0361: Layer already exists f1169f782306: Layer already exists d7db75e2b431: Layer already exists 4f2cfc8e1d9c: Layer already exists 2fda120dca9d: Layer already exists b20f86037b6a: Layer already exists cfb384290b61: Layer already exists 2fa7a397a825: Layer already exists 7cec48be98b5: Layer already exists e9f8533305d1: Layer already exists f0e656ec34e5: Layer already exists 8fb83a9e4695: Layer already exists 6ffceb8347ee: Layer already exists 22a079a22b0a: Layer already exists b8e0cedff7ca: Layer already exists 2beade966b29: Layer already exists 2bee813718b1: Layer already exists de74aa5c66af: Layer already exists 0067d70a5699: Layer already exists 55746cb9d6dc: Layer already exists 5d9ef8a0564d: Layer already exists e9b312bba1ab: Layer already exists c86122b5e4d3: Layer already exists 3813924f3fa4: Layer already exists 13.1.0-vpgu: digest: sha256:cdbcd75ad9c9e551df481a33a5b4bcd273d0c6d48ebc36c24c49624d202822ce size: 11802
Done!