circleci: Create script for generating Dockerfiles.

[greg: updated Dockerfile comment]
This commit is contained in:
Vishnu Ks 2018-01-30 19:17:30 +00:00 committed by Greg Price
parent 9798bb51c8
commit be328b2c7b
4 changed files with 52 additions and 10 deletions

3
.gitignore vendored
View File

@ -29,6 +29,9 @@ package-lock.json
/.vagrant
/var
# Dockerfiles generated for CircleCI
/tools/circleci/images
# Static build
*.mo
npm-debug.log

View File

@ -1,4 +1,5 @@
# Dockerfile for a generic Ubuntu 14.04 image with just the basics we need
{generated_file_warning}
# Dockerfile for a generic Ubuntu image with just the basics we need
# to make it suitable for CI. In particular:
# * a non-root user to run as (a pain to try to do in setup,
# because by then we've already cloned the repo);
@ -20,14 +21,15 @@
# (but much simpler, with a couple of packages from the distro), and
# then borrows from the CircleCI Dockerfile.
# To rebuild from this file:
# 0. pick a new image name, like `gregprice/circleci:trusty-python-3.test`
# 1. $ sudo docker build tools/circleci/images/ --tag $NAME
# 2. $ sudo docker push $NAME
# 3. update .circleci/config.yml to refer to the new name
# To rebuild from this file for a given release, say trusty:
# 0. $ tools/circleci/generate-dockerfiles
# 1. pick a new image name, like `gregprice/circleci:trusty-python-3.test`
# 2. $ sudo docker build tools/circleci/images/$RELEASE/ --tag $NAME
# 3. $ sudo docker push $NAME
# 4. update .circleci/config.yml to refer to the new name
# TODO add xenial
FROM buildpack-deps:trusty-scm
FROM {base_image}
RUN echo 'APT::Get::Assume-Yes "true";' > /etc/apt/apt.conf.d/90circleci \
&& echo 'DPkg::Options "--force-confnew";' >> /etc/apt/apt.conf.d/90circleci
@ -40,7 +42,7 @@ RUN apt-get update \
netcat unzip zip jq \
python3-pip \
&& ln -sf /usr/share/zoneinfo/Etc/UTC /etc/localtime \
&& { locale-gen en_US.UTF-8 || true; } \
&& {{ locale-gen en_US.UTF-8 || true; }} \
&& echo "LC_ALL=en_US.UTF-8" | sudo tee -a /etc/default/locale
# Set the locale, together with the locale-related steps above.
@ -61,9 +63,9 @@ ENV LC_ALL en_US.UTF-8
# Docker core...
RUN set -e \
&& export DOCKER_VERSION=$(curl --silent --fail --retry 3 https://download.docker.com/linux/static/stable/x86_64/ | grep -o -e 'docker-[.0-9]*-ce\.tgz' | sort -r | head -n 1) \
&& DOCKER_URL="https://download.docker.com/linux/static/stable/x86_64/${DOCKER_VERSION}" \
&& DOCKER_URL="https://download.docker.com/linux/static/stable/x86_64/${{DOCKER_VERSION}}" \
&& echo Docker URL: $DOCKER_URL \
&& curl --silent --show-error --location --fail --retry 3 --output /tmp/docker.tgz "${DOCKER_URL}" \
&& curl --silent --show-error --location --fail --retry 3 --output /tmp/docker.tgz "${{DOCKER_URL}}" \
&& ls -lha /tmp/docker.tgz \
&& tar -xz -C /tmp -f /tmp/docker.tgz \
&& mv /tmp/docker/* /usr/bin \

View File

@ -0,0 +1,35 @@
#!/usr/bin/env python3
import errno
import os
import yaml
def generate_dockerfile_directories(dockerfile_path: str) -> None:
if not os.path.exists(os.path.dirname(dockerfile_path)):
try:
os.makedirs(os.path.dirname(dockerfile_path))
except OSError as e:
if e.errno != errno.EEXIST:
raise
if __name__ == "__main__":
os.chdir(os.path.abspath(os.path.dirname(__file__)))
with open("Dockerfile.template") as f:
docker_template = f.read()
with open("images.yml") as f:
dockerfile_settings = yaml.safe_load(f)
for distro in dockerfile_settings:
dockerfile_settings[distro]["generated_file_warning"] = """\
# THIS IS A GENERATED FILE. DO NOT EDIT.
# See template: tools/circleci/Dockerfile.template
"""
dockerfile_content = docker_template.format_map(dockerfile_settings[distro])
dockerfile_path = "images/{}/Dockerfile".format(distro)
generate_dockerfile_directories(dockerfile_path)
with open(dockerfile_path, "w") as f:
f.write(dockerfile_content)

View File

@ -0,0 +1,2 @@
trusty:
base_image: buildpack-deps:trusty-scm