From 0d6db333d6b4944a228848a9f451d6a647324b40 Mon Sep 17 00:00:00 2001 From: Solomon Hykes Date: Thu, 6 Jun 2013 19:05:21 +0200 Subject: [PATCH] docker-build contrib script is deprecated by the new 'build' command --- contrib/docker-build/MAINTAINERS | 1 - contrib/docker-build/README | 68 ------------ contrib/docker-build/docker-build | 142 ------------------------ contrib/docker-build/example.changefile | 13 --- contrib/docker-build/myscript | 3 - 5 files changed, 227 deletions(-) delete mode 100644 contrib/docker-build/MAINTAINERS delete mode 100644 contrib/docker-build/README delete mode 100755 contrib/docker-build/docker-build delete mode 100644 contrib/docker-build/example.changefile delete mode 100644 contrib/docker-build/myscript diff --git a/contrib/docker-build/MAINTAINERS b/contrib/docker-build/MAINTAINERS deleted file mode 100644 index e1c6f2ccfc..0000000000 --- a/contrib/docker-build/MAINTAINERS +++ /dev/null @@ -1 +0,0 @@ -Solomon Hykes diff --git a/contrib/docker-build/README b/contrib/docker-build/README deleted file mode 100644 index f648753b90..0000000000 --- a/contrib/docker-build/README +++ /dev/null @@ -1,68 +0,0 @@ -# docker-build: build your software with docker - -## Description - -docker-build is a script to build docker images from source. It will be deprecated once the 'build' feature is incorporated into docker itself (See https://github.com/dotcloud/docker/issues/278) - -Author: Solomon Hykes - - -## Install - -docker-builder requires: - -1) A reasonably recent Python setup (tested on 2.7.2). - -2) A running docker daemon at version 0.1.4 or more recent (http://www.docker.io/gettingstarted) - - -## Usage - -First create a valid Changefile, which defines a sequence of changes to apply to a base image. - - $ cat Changefile - # Start build from a know base image - from base:ubuntu-12.10 - # Update ubuntu sources - run echo 'deb http://archive.ubuntu.com/ubuntu quantal main universe multiverse' > /etc/apt/sources.list - run apt-get update - # Install system packages - run DEBIAN_FRONTEND=noninteractive apt-get install -y -q git - run DEBIAN_FRONTEND=noninteractive apt-get install -y -q curl - run DEBIAN_FRONTEND=noninteractive apt-get install -y -q golang - # Insert files from the host (./myscript must be present in the current directory) - copy myscript /usr/local/bin/myscript - - -Run docker-build, and pass the contents of your Changefile as standard input. - - $ IMG=$(./docker-build < Changefile) - -This will take a while: for each line of the changefile, docker-build will: - -1. Create a new container to execute the given command or insert the given file -2. Wait for the container to complete execution -3. Commit the resulting changes as a new image -4. Use the resulting image as the input of the next step - - -If all the steps succeed, the result will be an image containing the combined results of each build step. -You can trace back those build steps by inspecting the image's history: - - $ docker history $IMG - ID CREATED CREATED BY - 1e9e2045de86 A few seconds ago /bin/sh -c cat > /usr/local/bin/myscript; chmod +x /usr/local/bin/git - 77db140aa62a A few seconds ago /bin/sh -c DEBIAN_FRONTEND=noninteractive apt-get install -y -q golang - 77db140aa62a A few seconds ago /bin/sh -c DEBIAN_FRONTEND=noninteractive apt-get install -y -q curl - 77db140aa62a A few seconds ago /bin/sh -c DEBIAN_FRONTEND=noninteractive apt-get install -y -q git - 83e85d155451 A few seconds ago /bin/sh -c apt-get update - bfd53b36d9d3 A few seconds ago /bin/sh -c echo 'deb http://archive.ubuntu.com/ubuntu quantal main universe multiverse' > /etc/apt/sources.list - base 2 weeks ago /bin/bash - 27cf78414709 2 weeks ago - - -Note that your build started from 'base', as instructed by your Changefile. But that base image itself seems to have been built in 2 steps - hence the extra step in the history. - - -You can use this build technique to create any image you want: a database, a web application, or anything else that can be build by a sequence of unix commands - in other words, anything else. - diff --git a/contrib/docker-build/docker-build b/contrib/docker-build/docker-build deleted file mode 100755 index 654cc89793..0000000000 --- a/contrib/docker-build/docker-build +++ /dev/null @@ -1,142 +0,0 @@ -#!/usr/bin/env python - -# docker-build is a script to build docker images from source. -# It will be deprecated once the 'build' feature is incorporated into docker itself. -# (See https://github.com/dotcloud/docker/issues/278) -# -# Author: Solomon Hykes - - - -# First create a valid Changefile, which defines a sequence of changes to apply to a base image. -# -# $ cat Changefile -# # Start build from a know base image -# from base:ubuntu-12.10 -# # Update ubuntu sources -# run echo 'deb http://archive.ubuntu.com/ubuntu quantal main universe multiverse' > /etc/apt/sources.list -# run apt-get update -# # Install system packages -# run DEBIAN_FRONTEND=noninteractive apt-get install -y -q git -# run DEBIAN_FRONTEND=noninteractive apt-get install -y -q curl -# run DEBIAN_FRONTEND=noninteractive apt-get install -y -q golang -# # Insert files from the host (./myscript must be present in the current directory) -# copy myscript /usr/local/bin/myscript -# -# -# Run docker-build, and pass the contents of your Changefile as standard input. -# -# $ IMG=$(./docker-build < Changefile) -# -# This will take a while: for each line of the changefile, docker-build will: -# -# 1. Create a new container to execute the given command or insert the given file -# 2. Wait for the container to complete execution -# 3. Commit the resulting changes as a new image -# 4. Use the resulting image as the input of the next step - - -import sys -import subprocess -import json -import hashlib - -def docker(args, stdin=None): - print "# docker " + " ".join(args) - p = subprocess.Popen(["docker"] + list(args), stdin=stdin, stdout=subprocess.PIPE) - return p.stdout - -def image_exists(img): - return docker(["inspect", img]).read().strip() != "" - -def image_config(img): - return json.loads(docker(["inspect", img]).read()).get("config", {}) - -def run_and_commit(img_in, cmd, stdin=None, author=None, run=None): - run_id = docker(["run"] + (["-i", "-a", "stdin"] if stdin else ["-d"]) + [img_in, "/bin/sh", "-c", cmd], stdin=stdin).read().rstrip() - print "---> Waiting for " + run_id - result=int(docker(["wait", run_id]).read().rstrip()) - if result != 0: - print "!!! '{}' return non-zero exit code '{}'. Aborting.".format(cmd, result) - sys.exit(1) - return docker(["commit"] + (["-author", author] if author else []) + (["-run", json.dumps(run)] if run is not None else []) + [run_id]).read().rstrip() - -def insert(base, src, dst, author=None): - print "COPY {} to {} in {}".format(src, dst, base) - if dst == "": - raise Exception("Missing destination path") - stdin = file(src) - stdin.seek(0) - return run_and_commit(base, "cat > {0}; chmod +x {0}".format(dst), stdin=stdin, author=author) - -def add(base, src, dst, author=None): - print "PUSH to {} in {}".format(dst, base) - if src == ".": - tar = subprocess.Popen(["tar", "-c", "."], stdout=subprocess.PIPE).stdout - else: - tar = subprocess.Popen(["curl", src], stdout=subprocess.PIPE).stdout - if dst == "": - raise Exception("Missing argument to push") - return run_and_commit(base, "mkdir -p '{0}' && tar -C '{0}' -x".format(dst), stdin=tar, author=author) - -def main(): - base="" - maintainer="" - steps = [] - try: - for line in sys.stdin.readlines(): - line = line.strip() - # Skip comments and empty lines - if line == "" or line[0] == "#": - continue - op, param = line.split(None, 1) - print op.upper() + " " + param - if op == "from": - base = param - steps.append(base) - elif op == "maintainer": - maintainer = param - elif op == "run": - result = run_and_commit(base, param, author=maintainer) - steps.append(result) - base = result - print "===> " + base - elif op == "copy": - src, dst = param.split(" ", 1) - result = insert(base, src, dst, author=maintainer) - steps.append(result) - base = result - print "===> " + base - elif op == "add": - src, dst = param.split(" ", 1) - result = add(base, src, dst, author=maintainer) - steps.append(result) - base=result - print "===> " + base - elif op == "expose": - config = image_config(base) - if config.get("PortSpecs") is None: - config["PortSpecs"] = [] - portspec = param.strip() - config["PortSpecs"].append(portspec) - result = run_and_commit(base, "# (nop) expose port {}".format(portspec), author=maintainer, run=config) - steps.append(result) - base=result - print "===> " + base - elif op == "cmd": - config = image_config(base) - cmd = list(json.loads(param)) - config["Cmd"] = cmd - result = run_and_commit(base, "# (nop) set default command to '{}'".format(" ".join(cmd)), author=maintainer, run=config) - steps.append(result) - base=result - print "===> " + base - else: - print "Skipping uknown op " + op - except: - docker(["rmi"] + steps[1:]) - raise - print base - -if __name__ == "__main__": - main() diff --git a/contrib/docker-build/example.changefile b/contrib/docker-build/example.changefile deleted file mode 100644 index d76bbb4389..0000000000 --- a/contrib/docker-build/example.changefile +++ /dev/null @@ -1,13 +0,0 @@ -# Start build from a know base image -maintainer Solomon Hykes -from base:ubuntu-12.10 -# Update ubuntu sources -run echo 'deb http://archive.ubuntu.com/ubuntu quantal main universe multiverse' > /etc/apt/sources.list -run apt-get update -# Install system packages -run DEBIAN_FRONTEND=noninteractive apt-get install -y -q git -run DEBIAN_FRONTEND=noninteractive apt-get install -y -q curl -run DEBIAN_FRONTEND=noninteractive apt-get install -y -q golang -# Insert files from the host (./myscript must be present in the current directory) -copy myscript /usr/local/bin/myscript -push /src diff --git a/contrib/docker-build/myscript b/contrib/docker-build/myscript deleted file mode 100644 index a6ffda5f11..0000000000 --- a/contrib/docker-build/myscript +++ /dev/null @@ -1,3 +0,0 @@ -#!/bin/sh - -echo hello, world!