diff options
| author | Carlos Konstanski <carlos.konstanski@verizonwireless.com> | 2019-10-30 14:33:05 -0600 |
|---|---|---|
| committer | Carlos Konstanski <carlos.konstanski@verizonwireless.com> | 2019-10-30 14:33:05 -0600 |
| commit | 7cab8996742b8128bed197f9457afd2af160cf5e (patch) | |
| tree | dfd5b40b99e0935ba65b34d973f6e79a6bb39b24 /salt/gentoo_baseimage/ci | |
initial commit
Diffstat (limited to 'salt/gentoo_baseimage/ci')
| -rw-r--r-- | salt/gentoo_baseimage/ci/files/build.sh | 23 | ||||
| -rw-r--r-- | salt/gentoo_baseimage/ci/files/cloudcfg.sh | 29 | ||||
| -rw-r--r-- | salt/gentoo_baseimage/ci/init.sls | 30 |
3 files changed, 82 insertions, 0 deletions
diff --git a/salt/gentoo_baseimage/ci/files/build.sh b/salt/gentoo_baseimage/ci/files/build.sh new file mode 100644 index 0000000..b42f01b --- /dev/null +++ b/salt/gentoo_baseimage/ci/files/build.sh @@ -0,0 +1,23 @@ +#!/bin/bash -e + +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}') + 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} + fi + done +} + +{% if pillar["ci"]["local_build"] != True %} +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 + +exit 0 diff --git a/salt/gentoo_baseimage/ci/files/cloudcfg.sh b/salt/gentoo_baseimage/ci/files/cloudcfg.sh new file mode 100644 index 0000000..400f7cf --- /dev/null +++ b/salt/gentoo_baseimage/ci/files/cloudcfg.sh @@ -0,0 +1,29 @@ +#!/bin/bash + +# Prepare the instance for ansible. This amounts to installing python2. + +python=$(which python || which python3 || which python2 || false) + +case "$(${python} -m platform)" in + *Ubuntu*) + export DEBIAN_FRONTEND=noninteractive + apt-get update + apt-get -y -o Dpkg::Options::="--force-confdef" -o Dpkg::Options::="--force-confold" dist-upgrade + apt-get -y install aptitude python python2.7 python3-netaddr ntp ntpdate language-pack-de + update-alternatives --install /usr/bin/python python /usr/bin/python2.7 1 + update-alternatives --install /usr/bin/python python /usr/bin/python3.6 1 + update-alternatives --set python /usr/bin/python3.6 + ;; + *centos*|*redhat*) + # RHEL systems still use python2 by default; nothing to do + ;; + *gentoo*) + if [ ! -d /usr/portage/sys-devel/gcc ]; then + emerge-webrsync + fi + emerge --oneshot --update dev-lang/python:2.7 app-portage/gentoolkit net-misc/chrony + rc-update add chrony default + ;; +esac + +exit 0 diff --git a/salt/gentoo_baseimage/ci/init.sls b/salt/gentoo_baseimage/ci/init.sls new file mode 100644 index 0000000..510af92 --- /dev/null +++ b/salt/gentoo_baseimage/ci/init.sls @@ -0,0 +1,30 @@ +{% for dir in pillar["ci"]["dirs"].items() %} +database_dirs_{{ dir[0] }}: + file.directory: +{% if dir[1]["relative_to_buildroot"] %} + - name: {{ pillar["ci"]["build_dir"] }}/{{ dir[1]["name"] }} +{% else %} + - name: {{ dir[1]["name"] }} +{% endif %} + - user: 0 + - group: 0 + - mode: {{ dir[1]["mode"] }} + - makedirs: True +{% endfor %} + +{% for file in pillar["ci"]["files"].items() %} +ci_files_{{ file[0] }}: + file.managed: +{% if file[1]["relative_to_buildroot"] %} + - name: {{ pillar["ci"]["build_dir"] }}/{{ file[1]["path"] }}/{{ file[1]["name"] }} +{% else %} + - name: {{ file[1]["path"] }}/{{ file[1]["name"] }} +{% endif %} + - source: salt://gentoo_baseimage/ci/files/{{ file[1]["source"] }} +{% if file[1]["is_template"] %} + - template: jinja +{% endif %} + - user: 0 + - group: 0 + - mode: {{ file[1]["mode"] }} +{% endfor %} |
