tutorials: improve theme + use pandoc 2

This commit is contained in:
nemunaire 2018-11-16 02:38:41 +01:00
parent de21be218a
commit d25af4fdb2
65 changed files with 1281 additions and 1292 deletions

View file

@ -3,6 +3,8 @@ Registres
**Outils nécessaires :** `curl`, `gunzip`, `jq`, `tar`.
* * * * *
Dans cette partie, nous allons appréhender le fonctionnement d'un registre OCI,
et préparer le *rootfs* d'une image de base (Debian, Ubuntu, hello, ...) : en
nous préoccupant simplement de la couche la plus basse (qui ne contient pas de
@ -24,23 +26,23 @@ intéresse aujourd'hui !
Il n'en reste pas moins que le jeton est forgé pour un service donné (dans
notre cas `registry.docker.io`) et avec un objectif bien cerné (pour nous, on
souhaite récupérer le contenu du dépôt[^quiddepot] `hello-world` :
`repository:hello-world:pull`). Ce qui nous donne :
<span lang="en-US">`repository:hello-world:pull`</span>). Ce qui nous donne :
[^quiddepot]: Dans un registre, les fichiers qui composent l'image forment un
dépôt (*repository*).
<div lang="en-US">
```shell
42sh$ curl "https://auth.docker.io/token"\
> "?service=registry.docker.io&scope=repository:library/hello-world:pull" | jq .
```bash
42sh$ curl "https://auth.docker.io/token?service=registry.docker.io&"\
> "scope=repository:library/hello-world:pull" | jq .
```
```json
{
"token": "lUWXBCZzg2TGNUdmMy...daVZxGTj0eh",
"access_token": "eyJhbGciOiJSUzI1NiIsI...N5q469M3ZkL_HA",
"expires_in": 300,
"issued_at": "2012-12-12T12:12:12.123456789Z"
}
{
"token": "lUWXBCZzg2TGNUdmMy...daVZxGTj0eh",
"access_token": "eyJhbGciOiJSUzI1NiIsI...N5q469M3ZkL_HA",
"expires_in": 300,
"issued_at": "2012-12-12T12:12:12.123456789Z"
}
```
</div>
@ -50,8 +52,8 @@ registre.
Avec `jq`, on peut l'extraire grâce à :
<div lang="en-US">
```shell
| jq -r .token
```bash
| jq -r .token
```
</div>
@ -62,11 +64,11 @@ Une fois en possession de notre jeton, nous pouvons maintenant demander l'index
d'images à notre registre :
<div lang="en-US">
```shell
curl -s \
-H "Authorization: Bearer ${TOKEN}" \
-H "Accept: application/vnd.docker.distribution.manifest.list.v2+json" \
"https://registry-1.docker.io/v2/library/hello-world/manifests/latest" | jq .
```bash
curl -s \
-H "Authorization: Bearer ${TOKEN}" \
-H "Accept: application/vnd.docker.distribution.manifest.list.v2+json" \
"https://registry-1.docker.io/v2/library/hello-world/manifests/latest" | jq .
```
</div>
@ -81,11 +83,11 @@ Demandons maintenant le manifest correspondant à notre matériel et à notre
système d'exploitation :
<div lang="en-US">
```shell
curl -s \
-H "Authorization: Bearer ${TOKEN}" \
-H "Accept: ${MEDIATYPE}" \
"https://registry-1.docker.io/v2/library/hello-world/manifests/${MANIFEST_DIGEST}" | jq .
```bash
curl -s \
-H "Authorization: Bearer ${TOKEN}" \
-H "Accept: ${MEDIATYPE}" \
"https://registry-1.docker.io/v2/library/hello-world/manifests/${MANIFEST_DIGEST}" | jq .
```
</div>
@ -101,10 +103,10 @@ répertoire `blobs`, il ne s'agit en effet plus de manifest. Si les manifests so
Pour récupérer la configuration de l'image :
<div lang="en-US">
```shell
curl -s --location \
-H "Authorization: Bearer ${TOKEN}" \
"https://registry-1.docker.io/v2/library/hello-world/blobs/${CONFIG_DIGEST}" | jq .
```bash
curl -s --location \
-H "Authorization: Bearer ${TOKEN}" \
"https://registry-1.docker.io/v2/library/hello-world/blobs/${CONFIG_DIGEST}" | jq .
```
</div>
@ -112,9 +114,9 @@ Pour récupérer la configuration de l'image :
Enfin, armé du `digest` de notre couche, il ne nous reste plus qu'à la demander gentiment :
<div lang="en-US">
```shell
wget --header "Authorization: Bearer ${TOKEN}" \
"https://registry-1.docker.io/v2/library/hello-world/blobs/${LAYER_DIGEST}"
```bash
wget --header "Authorization: Bearer ${TOKEN}" \
"https://registry-1.docker.io/v2/library/hello-world/blobs/${LAYER_DIGEST}"
```
</div>
@ -126,40 +128,40 @@ Le type indiqué par le manifest pour cette couche était
tarball compressée au format gzip :
<div lang="en-US">
```shell
mkdir rootfs
tar xzf ${DL_LAYER} -C rootfs
```bash
mkdir rootfs
tar xzf ${DL_LAYER} -C rootfs
```
</div>
Et voilà, nous avons extrait notre première image, nous devrions pouvoir :
<div lang="en-US">
```shell
42sh# chroot rootfs /hello
Hello from Docker!
[...]
```bash
42sh# chroot rootfs /hello
Hello from Docker!
[...]
```
</div>
## Exercice {.unnumbered}
## Exercice {-}
Réalisez un script pour automatiser l'ensemble de ces étapes :
<div lang="en-US">
```shell
42sh$ cd $(mktemp)
```bash
42sh$ cd $(mktemp)
42sh$ ~/workspace/registry_play.sh library/hello
42sh$ ~/workspace/registry_play.sh library/hello
42sh$ find
.
./rootfs
./rootfs/hello
42sh$ find
.
./rootfs
./rootfs/hello
42sh# chroot rootfs /hello
Hello from Docker!
[...]
42sh# chroot rootfs /hello
Hello from Docker!
[...]
```
</div>