diff options
| author | ckonstanski <ckonstanski@pippiandcarlos.com> | 2020-01-16 17:21:23 +0000 |
|---|---|---|
| committer | ckonstanski <ckonstanski@pippiandcarlos.com> | 2020-01-16 17:21:23 +0000 |
| commit | b1f9d41bf26ba68e1c559467caeb1935dab0d1bb (patch) | |
| tree | d905c4b83776dda3008db922fbf60bd12a739c5e /salt/gentoo_baseimage/ci/files/build.sh | |
| parent | 656ee56e637d5b7c2e09124069b1ceaffbf6911e (diff) | |
Improve local builds and support docker-registry with no creds
Diffstat (limited to 'salt/gentoo_baseimage/ci/files/build.sh')
| -rw-r--r-- | salt/gentoo_baseimage/ci/files/build.sh | 13 |
1 files changed, 7 insertions, 6 deletions
diff --git a/salt/gentoo_baseimage/ci/files/build.sh b/salt/gentoo_baseimage/ci/files/build.sh index b42f01b..547d0d2 100644 --- a/salt/gentoo_baseimage/ci/files/build.sh +++ b/salt/gentoo_baseimage/ci/files/build.sh @@ -1,21 +1,22 @@ #!/bin/bash -e +basic_auth='{% if pillar["registry"]["username"] != None %}-u \'{{ pillar["registry"]["username"] }}:{{ pillar["registry"]["password"] }}\'{% endif %}' + mark_for_gc() { image_name="${1}" - for tag in $(curl -u '{{ pillar["registry"]["username"] }}:{{ pillar["registry"]["password"] }}' -H 'Accept: application/vnd.docker.distribution.manifest.v2+json' https://{{ pillar["registry"]["url"] }}/v2/${image_name}/tags/list | jq '.tags' | grep -o -P '[a-fA-F0-9]+'); do - digest=$(curl -u '{{ pillar["registry"]["username"] }}:{{ pillar["registry"]["password"] }}' -H 'Accept: application/vnd.docker.distribution.manifest.v2+json' https://{{ pillar["registry"]["url"] }}/v2/${image_name}/manifests/${tag} | jq '.config.digest' | awk -F\" '{print $2}') + for tag in $(curl -k ${basic_auth} -H 'Accept: application/vnd.docker.distribution.manifest.v2+json' https://{{ pillar["registry"]["url"] }}/v2/${image_name}/tags/list | jq '.tags' | grep -o -P '[a-fA-F0-9]+'); do + digest=$(curl -k ${basic_auth} -H 'Accept: application/vnd.docker.distribution.manifest.v2+json' https://{{ pillar["registry"]["url"] }}/v2/${image_name}/manifests/${tag} | jq '.config.digest' | awk -F\" '{print $2}') if [ "${digest}" != "" ]; then - curl -u '{{ pillar["registry"]["username"] }}:{{ pillar["registry"]["password"] }}' -H 'Accept: application/vnd.docker.distribution.manifest.v2+json' -X DELETE https://{{ pillar["registry"]["url"] }}/v2/${image_name}/manifests/${digest} + curl -k ${basic_auth} -H 'Accept: application/vnd.docker.distribution.manifest.v2+json' -X DELETE https://{{ pillar["registry"]["url"] }}/v2/${image_name}/manifests/${digest} fi done } -{% if pillar["ci"]["local_build"] != True %} +{% if pillar["ci"]["local_build"] == False %} +{% if pillar["registry"]["username"] != None %} echo "Login to docker registry" echo '{{ pillar["registry"]["password"] }}' | docker login --username {{ pillar["registry"]["username"] }} --password-stdin {{ pillar["registry"]["url"] }} {% endif %} - -{% if pillar["ci"]["local_build"] != True %} mark_for_gc "{{ pillar["gentoo_baseimage"]["image_name"] }}" {% endif %} {{ pillar["gentoo_baseimage"]["build_dir"] }}/build.sh |
