From 878cd8c30560bd2ec3e6db19dbdc98dd3ce58e52 Mon Sep 17 00:00:00 2001 From: Quentin Date: Thu, 6 Apr 2023 16:34:46 +0000 Subject: [PATCH] =?UTF-8?q?Update=20Article=20=E2=80=9C2023-04-06-un-regis?= =?UTF-8?q?tre-statique-docker-avec-garage=E2=80=9D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ...un-registre-statique-docker-avec-garage.md | 45 ++++++++++++++++++- 1 file changed, 44 insertions(+), 1 deletion(-) diff --git a/_posts/2023-04-06-un-registre-statique-docker-avec-garage.md b/_posts/2023-04-06-un-registre-statique-docker-avec-garage.md index 3beeaa7..10fc9bc 100644 --- a/_posts/2023-04-06-un-registre-statique-docker-avec-garage.md +++ b/_posts/2023-04-06-un-registre-statique-docker-avec-garage.md @@ -2,7 +2,7 @@ layout: post title: Un registre statique Docker avec Garage date: 2023-04-06T16:13:14.025+02:00 -status: draft +status: published sitemap: true category: developpement description: Héberger vos conteneurs Docker directement depuis Garage @@ -288,3 +288,46 @@ S3-compatible object store for self-hosted geo-distributed deployments Nous y voilà : nous savons créer un registre Docker statique ! Et maintenant, pourquoi ne pas construire nos images directement avec Nix ? ## Construire l'image nous-même avec Nix + +On va utiliser `pkgs.dockerTools.buildImage` pour générer une archive docker qui va ressembler à ça : + +``` +$ tar -tvf result +dr-xr-xr-x root/root 0 1980-01-01 01:00 ./ +dr-xr-xr-x root/root 0 1980-01-01 01:00 4bc17b9fc1404e9543364c02ec354faee7ca6e004dc829994a61fd42935e00aa/ +-r--r--r-- root/root 3 1980-01-01 01:00 4bc17b9fc1404e9543364c02ec354faee7ca6e004dc829994a61fd42935e00aa/VERSION +-r--r--r-- root/root 396 1980-01-01 01:00 4bc17b9fc1404e9543364c02ec354faee7ca6e004dc829994a61fd42935e00aa/json +-r--r--r-- root/root 9932800 1980-01-01 01:00 4bc17b9fc1404e9543364c02ec354faee7ca6e004dc829994a61fd42935e00aa/layer.tar +-r--r--r-- root/root 447 1980-01-01 01:00 e9eaf28bc5306e0390c8e3d7ec7f072933c67a5e5dadcd4b4e699cdcbee20d00.json +-r--r--r-- root/root 286 1980-01-01 01:00 manifest.json +-r--r--r-- root/root 135 1980-01-01 01:00 repositories +``` + +De cette archive, on va pas se casser la tête dans un premier temps, on va simplement demander à skopeo de nous la convertir dans le format que l'on connait : + +```bash +skopeo --insecure-policy copy docker-archive:result dir:/tmp/albatros-img +``` + +Ensuite on va la copier simplement comme vu précédemment : + +```bash +sha256sum manifest.json # 840b4265d58d0358a3c4183ba0e39e7bb4c3dfb78a50cac7532476ab25666def +aws s3 cp --content-type application/vnd.docker.distribution.manifest.v2+json manifest.json s3://quentin.dufour.io/v2/albatros/manifests/sha256:840b4265d58d0358a3c4183ba0e39e7bb4c3dfb78a50cac7532476ab25666def +aws s3 cp --content-type application/vnd.docker.distribution.manifest.v2+json manifest.json s3://quentin.dufour.io/v2/albatros/manifests/v0.9 +aws s3 cp ./83695be784e20268eafd08d35b47f50d689d831ae4a047750a4ed2c0a29debc7 s3://quentin.dufour.io/v2/albatros/blobs/sha256:83695be784e20268eafd08d35b47f50d689d831ae4a047750a4ed2c0a29debc7 +aws s3 cp ./e9eaf28bc5306e0390c8e3d7ec7f072933c67a5e5dadcd4b4e699cdcbee20d00 s3://quentin.dufour.io/v2/albatros/blobs/sha256:e9eaf28bc5306e0390c8e3d7ec7f072933c67a5e5dadcd4b4e699cdcbee20d00 +``` + +Et voilà, on peut lancer notre binaire maintenant : + +``` +$ docker run --rm -it quentin.dufour.io/albatros:v0.9 +Unable to find image 'quentin.dufour.io/albatros:v0.9' locally +v0.9: Pulling from albatros +Digest: sha256:840b4265d58d0358a3c4183ba0e39e7bb4c3dfb78a50cac7532476ab25666def +Status: Downloaded newer image for quentin.dufour.io/albatros:v0.9 +2023/04/06 16:31:42 unable to parse config, error: env: required environment variable "ALBATROS_URL" is not set +``` + +Alors là on a envoyé une image simple et non une image multi-arch, mais c'est tout à fait possible à faire, l'exercice est laissé à la lectrice ou au lecture que vous êtes pour le moment. Bonne chance !