summaryrefslogtreecommitdiff
path: root/salt/gentoo_baseimage/ci/files/build.sh
blob: c80ce9be57c482556e687b1c55032df4c1511dae (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
#!/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 -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 -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"] == 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 %}
mark_for_gc "{{ pillar["gentoo_baseimage"]["image_name"] }}"
{% endif %}
{{ pillar["gentoo_baseimage"]["build_dir"] }}/build.sh
    
exit 0