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 | |
initial commit
Diffstat (limited to 'salt/gentoo_baseimage')
| -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 | ||||
| -rw-r--r-- | salt/gentoo_baseimage/gentoo_baseimage/files/Dockerfile | 6 | ||||
| -rw-r--r-- | salt/gentoo_baseimage/gentoo_baseimage/files/build.sh | 46 | ||||
| -rw-r--r-- | salt/gentoo_baseimage/gentoo_baseimage/files/gentoo.conf | 8 | ||||
| -rw-r--r-- | salt/gentoo_baseimage/gentoo_baseimage/files/installdeps.sh | 16 | ||||
| -rw-r--r-- | salt/gentoo_baseimage/gentoo_baseimage/files/make.conf | 18 | ||||
| -rw-r--r-- | salt/gentoo_baseimage/gentoo_baseimage/files/package.use | 2 | ||||
| -rw-r--r-- | salt/gentoo_baseimage/gentoo_baseimage/init.sls | 30 |
10 files changed, 208 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 %} diff --git a/salt/gentoo_baseimage/gentoo_baseimage/files/Dockerfile b/salt/gentoo_baseimage/gentoo_baseimage/files/Dockerfile new file mode 100644 index 0000000..67c9f23 --- /dev/null +++ b/salt/gentoo_baseimage/gentoo_baseimage/files/Dockerfile @@ -0,0 +1,6 @@ +FROM gentoo/stage3-amd64 +MAINTAINER Carlos Konstanski <carlos.konstanski@verizonwireless.com> +ADD docker-start.tar.xz / +RUN /installdeps.sh +ENTRYPOINT [ "/bin/bash" ] +CMD [] diff --git a/salt/gentoo_baseimage/gentoo_baseimage/files/build.sh b/salt/gentoo_baseimage/gentoo_baseimage/files/build.sh new file mode 100644 index 0000000..beffb0c --- /dev/null +++ b/salt/gentoo_baseimage/gentoo_baseimage/files/build.sh @@ -0,0 +1,46 @@ +#!/bin/bash -e + +# Do not call directly. Meant to be called from CI build script. + +pushd {{ pillar["gentoo_baseimage"]["build_dir"] }} 2>/dev/null + +echo "Creating tmp directory" +rm -rf tmp +mkdir tmp +rm -f docker-start.tar.xz + +echo "Populating with custom files" +rsync -aq data/ tmp/ + +echo "Repackaging into .xz file" +tar Jcvf docker-start.tar.xz -C tmp/ . + +echo "Stopping existing docker containers" +for cont in $(docker ps | grep -F '{{ pillar["gentoo_baseimage"]["container_name"] }}' | awk '{print $1}'); do + docker stop ${cont} +done +docker container prune -f + +echo "Deleting existing docker images" +for image in $(docker images | grep -F '{{ pillar["gentoo_baseimage"]["image_name"] }}' | awk '{print $3}'); do + docker rmi --force ${image} +done +for image in $(docker images | grep -F 'gentoo' | awk '{print $3}'); do + docker rmi --force ${image} +done + +echo "Building docker image" +docker build -t {{ pillar["gentoo_baseimage"]["image_name"] }}:{{ pillar["ci"]["tag"] }} . + +{% if pillar["ci"]["local_build"] != True %} +echo "Push docker image to the registry" +docker tag {{ pillar["gentoo_baseimage"]["image_name"] }}:{{ pillar["ci"]["tag"] }} {{ pillar["registry"]["url"] }}/{{ pillar["gentoo_baseimage"]["image_name"] }}:{{ pillar["ci"]["tag"] }} +docker push {{ pillar["registry"]["url"] }}/{{ pillar["gentoo_baseimage"]["image_name"] }}:{{ pillar["ci"]["tag"] }} +{% endif %} + +echo "Cleaning up" +rm -rf tmp +rm -f docker-start.tar.xz + +popd 2>/dev/null +exit 0 diff --git a/salt/gentoo_baseimage/gentoo_baseimage/files/gentoo.conf b/salt/gentoo_baseimage/gentoo_baseimage/files/gentoo.conf new file mode 100644 index 0000000..7e42017 --- /dev/null +++ b/salt/gentoo_baseimage/gentoo_baseimage/files/gentoo.conf @@ -0,0 +1,8 @@ +[DEFAULT] +main-repo = gentoo + +[gentoo] +location = /usr/portage +sync-type = webrsync +auto-sync = yes +sync-rsync-verify-metamanifest = no diff --git a/salt/gentoo_baseimage/gentoo_baseimage/files/installdeps.sh b/salt/gentoo_baseimage/gentoo_baseimage/files/installdeps.sh new file mode 100644 index 0000000..e154656 --- /dev/null +++ b/salt/gentoo_baseimage/gentoo_baseimage/files/installdeps.sh @@ -0,0 +1,16 @@ +#!/bin/bash + +emaint sync -a +eselect profile set default/linux/amd64/17.1 +emerge -1 portage ; emerge --metadata +USE="-filecaps" emerge --deep --newuse --update @world +emerge --deep --newuse --update @world +emerge gentoolkit +revdep-rebuild +perl-cleaner --all +env-update +source /etc/profile +eselect news read all +eselect news purge + +exit 0 diff --git a/salt/gentoo_baseimage/gentoo_baseimage/files/make.conf b/salt/gentoo_baseimage/gentoo_baseimage/files/make.conf new file mode 100644 index 0000000..de50ae9 --- /dev/null +++ b/salt/gentoo_baseimage/gentoo_baseimage/files/make.conf @@ -0,0 +1,18 @@ +CHOST="x86_64-pc-linux-gnu" +CFLAGS="-O2 -pipe" +CXXFLAGS="${CFLAGS}" +FCFLAGS="${CFLAGS}" +FFLAGS="${CFLAGS}" +USE="-X -webstart -alsa -cups -gtk -vala -introspection" +ABI_X86="64 32" +EMERGE_DEFAULT_OPTS="--quiet-build=y --with-bdeps=y --nospinner --verbose-conflicts --changed-deps-report=n --keep-going=y" +FEATURES="-preserve-libs" +ACCEPT_LICENSE="* -@EULA" +MAKEOPTS="-j{{ grains["num_cpus"] }}" +PORTAGE_NICENESS="19" +FEATURES="-preserve-libs metadata-transfer -sandbox -network-sandbox -usersandbox" +PORTDIR="/usr/portage" +DISTDIR="/usr/portage/distfiles" +PKGDIR="/usr/portage/packages" +PORTAGE_ELOG_SYSTEM="save" +PORTAGE_GPG_DIR="/root/.gnupg" diff --git a/salt/gentoo_baseimage/gentoo_baseimage/files/package.use b/salt/gentoo_baseimage/gentoo_baseimage/files/package.use new file mode 100644 index 0000000..fc40a05 --- /dev/null +++ b/salt/gentoo_baseimage/gentoo_baseimage/files/package.use @@ -0,0 +1,2 @@ +x11-libs/cairo X +app-text/ghostscript-gpl cups diff --git a/salt/gentoo_baseimage/gentoo_baseimage/init.sls b/salt/gentoo_baseimage/gentoo_baseimage/init.sls new file mode 100644 index 0000000..b312018 --- /dev/null +++ b/salt/gentoo_baseimage/gentoo_baseimage/init.sls @@ -0,0 +1,30 @@ +{% for dir in pillar["gentoo_baseimage"]["dirs"].items() %} +gentoo_baseimage_dirs_{{ dir[0] }}: + file.directory: +{% if dir[1]["relative_to_buildroot"] %} + - name: {{ pillar["gentoo_baseimage"]["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["gentoo_baseimage"]["files"].items() %} +gentoo_baseimage_files_{{ file[0] }}: + file.managed: +{% if file[1]["relative_to_buildroot"] %} + - name: {{ pillar["gentoo_baseimage"]["build_dir"] }}/{{ file[1]["path"] }}/{{ file[1]["name"] }} +{% else %} + - name: {{ file[1]["path"] }}/{{ file[1]["name"] }} +{% endif %} + - source: salt://gentoo_baseimage/gentoo_baseimage/files/{{ file[1]["source"] }} +{% if file[1]["is_template"] %} + - template: jinja +{% endif %} + - user: 0 + - group: 0 + - mode: {{ file[1]["mode"] }} +{% endfor %} |
