Created
June 26, 2018 23:35
-
-
Save brianv0/a65441a0d8534ccd71e8f8f830f5a7ea to your computer and use it in GitHub Desktop.
Bootstrap Dockerfile Environment vars for SCL sources
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/bin/bash | |
| yum update -q -e 0 -y && \ | |
| yum install -q -e 0 -y --setopt=tsflags='' epel-release centos-release-scl-rh python-setuptools 2&> /dev/null && \ | |
| yum install -q -e 0 -y --setopt=tsflags='' $@ 2&> /dev/null | |
| easy_install jinja2 2&> /dev/null | |
| cat >> env.py <<EOF | |
| import os, subprocess as sp, json, sys | |
| from jinja2 import Template | |
| args = ' '.join(sys.argv[1:]) | |
| source = 'source scl_source enable ' + args | |
| dump = '/usr/bin/python -c "import os, json;print(json.dumps(dict(os.environ)))"' | |
| pipe = sp.Popen(['/bin/bash', '-c', '%s && %s' %(source,dump)], stdout=sp.PIPE) | |
| env = json.loads(pipe.stdout.read()) | |
| loaded_env = {} | |
| for key, var in env.items(): | |
| for product in sys.argv[1:]: | |
| if product in var: | |
| loaded_env[key] = var | |
| template_data = open("Dockerfile.template", "r").read() | |
| template = Template(template_data) | |
| print(template.render(env=loaded_env, deps=sys.argv[1:])) | |
| EOF | |
| python env.py $@ | |
| rm env.py |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| FROM centos:6 | |
| RUN yum update -y && \ | |
| yum install -y --setopt=tsflags='' epel-release centos-release-scl-rh && \ | |
| yum install -y --setopt=tsflags='' {% for dep in deps -%}{{ dep }} {% endfor %} && \ | |
| yum clean all | |
| {% for key, var in env.items() -%} | |
| ENV {{ key }}={{ var }} | |
| {% endfor %} |
Author
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
docker run -it --rm -v /path/to/bootstrap:/bootstrap.sh -v /path/to/template:/Dockerfile.template centos:6 ./bootstrap.sh > Dockerfile