Browse Source
Add download_always_pull check and sha256 for docker images
Add download_always_pull check and sha256 for docker images
Signed-off-by: Bogdan Dobrelya <bdobrelia@mirantis.com>pull/780/head
5 changed files with 113 additions and 22 deletions
Split View
Diff Options
-
42docs/downloads.md
-
10docs/large-deployments.md
-
23roles/download/defaults/main.yml
-
33roles/download/tasks/main.yml
-
27roles/download/tasks/set_docker_image_facts.yml
@ -0,0 +1,42 @@ |
|||
Downloading binaries and containers |
|||
=================================== |
|||
|
|||
Kargo supports several download/upload modes. The default is: |
|||
|
|||
* Each node downloads binaries and container images on its own, which is |
|||
``download_run_once: False``. |
|||
* For K8s apps, pull policy is ``k8s_image_pull_policy: IfNotPresent``. |
|||
* For system managed containers, like kubelet or etcd, pull policy is |
|||
``download_always_pull: False``, which is pull if only the wanted repo and |
|||
tag/sha256 digest differs from that the host has. |
|||
|
|||
There is also a "pull once, push many" mode as well: |
|||
|
|||
* Override the ``download_run_once: True`` to download container images only once |
|||
then push to cluster nodes in batches. The default delegate node |
|||
for pushing images is the first `kube-master`. |
|||
* If your ansible runner node (aka the admin node) have password-less sudo and |
|||
docker enabled, you may want to define the ``download_localhost: True``, which |
|||
makes that node a delegate for pushing images while running the deployment with |
|||
ansible. This maybe the case if cluster nodes cannot access each over via ssh |
|||
or you want to use local docker images as a cache for multiple clusters. |
|||
|
|||
Container images and binary files are described by the vars like ``foo_version``, |
|||
``foo_download_url``, ``foo_checksum`` for binaries and ``foo_image_repo``, |
|||
``foo_image_tag`` or optional ``foo_digest_checksum`` for containers. |
|||
|
|||
Container images may be defined by its repo and tag, for example: |
|||
`andyshinn/dnsmasq:2.72`. Or by repo and tag and sha256 digest: |
|||
`andyshinn/dnsmasq@sha256:7c883354f6ea9876d176fe1d30132515478b2859d6fc0cbf9223ffdc09168193`. |
|||
|
|||
Note, the sha256 digest and the image tag must be both specified and correspond |
|||
to each other. The given example above is represented by the following vars: |
|||
``` |
|||
dnsmasq_digest_checksum: 7c883354f6ea9876d176fe1d30132515478b2859d6fc0cbf9223ffdc09168193 |
|||
dnsmasq_image_repo: andyshinn/dnsmasq |
|||
dnsmasq_image_tag: '2.72' |
|||
``` |
|||
The full list of available vars may be found in the download's ansible role defaults. |
|||
Those also allow to specify custom urls and local repositories for binaries and container |
|||
images as well. See also the DNS stack docs for the related intranet configuration, |
|||
so the hosts can resolve those urls and repos. |
@ -0,0 +1,27 @@ |
|||
--- |
|||
- set_fact: |
|||
pull_by_digest: >- |
|||
{%- if download.sha256 is defined and download.sha256 != '' -%}true{%- else -%}false{%- endif -%} |
|||
|
|||
- set_fact: |
|||
pull_args: >- |
|||
{%- if pull_by_digest|bool %}{{download.repo}}@sha256:{{download.sha256}}{%- else -%}{{download.repo}}:{{download.tag}}{%- endif -%} |
|||
|
|||
- name: Register docker images info |
|||
shell: "{% raw %}/usr/bin/docker images -q | xargs /usr/bin/docker inspect -f '{{.RepoTags}},{{.RepoDigests}}'{% endraw %}" |
|||
register: docker_images_raw |
|||
ignore_errors: true |
|||
when: not download_always_pull|bool |
|||
|
|||
- set_fact: docker_images="{{docker_images_raw.stdout|regex_replace('\[|\]|\\n]','')|regex_replace('\s',',')}}" |
|||
when: not download_always_pull|bool |
|||
|
|||
- set_fact: |
|||
pull_required: >- |
|||
{%- if pull_args in docker_images.split(',') %}false{%- else -%}true{%- endif -%} |
|||
when: not download_always_pull|bool |
|||
|
|||
- name: Check the local digest sha256 corresponds to the given image tag |
|||
assert: |
|||
that: "{{download.repo}}:{{download.tag}} in docker_images.split(',')" |
|||
when: not download_always_pull|bool and not pull_required|bool and pull_by_digest|bool |
Write
Preview
Loading…
Cancel
Save