From f59ada0913ff5a139f7ccafd064fb4dbdf851529 Mon Sep 17 00:00:00 2001 From: Kenneth Reitz Date: Tue, 2 Oct 2018 14:33:11 -0400 Subject: [PATCH] push --- .vscode/settings.json | 3 +++ Dockerfile | 42 +++++++++++++++++++++++++++++++++++++++++- README.md | 8 ++++---- bob/__main__.py | 17 +++++++++++------ bob/builds.py | 28 ++++++++++++++++++---------- 5 files changed, 77 insertions(+), 21 deletions(-) create mode 100644 .vscode/settings.json diff --git a/.vscode/settings.json b/.vscode/settings.json new file mode 100644 index 0000000..a7838b0 --- /dev/null +++ b/.vscode/settings.json @@ -0,0 +1,3 @@ +{ + "python.pythonPath": "C:\\Users\\me\\.virtualenvs\\bruce-operator-UKafV52I\\Scripts\\python.exe" +} \ No newline at end of file diff --git a/Dockerfile b/Dockerfile index e46a669..d748ec5 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1 +1,41 @@ -from heroku/heroku:18-build +FROM heroku/heroku:18-build + +ENV DEBIAN_FRONTEND noninteractive +ENV LC_ALL C.UTF-8 +ENV LANG C.UTF-8 + +# -- Install Pipenv: +RUN apt update && apt upgrade -y && apt install python3.7-dev -y +RUN curl --silent https://bootstrap.pypa.io/get-pip.py | python3.7 + +# Backwards compatility. +RUN rm -fr /usr/bin/python3 && ln /usr/bin/python3.7 /usr/bin/python3 + +RUN pip3 install pipenv + +# -- Install Application into container: +RUN set -ex && mkdir /bob +WORKDIR /bob + +# -- Adding Pipfiles +COPY Pipfile Pipfile +COPY Pipfile.lock Pipfile.lock + +# Install Docker. +RUN apt install -y docker.io + +# Install daemontools +# RUN apt-get update -qq && apt-get install -qq -y daemontools && apt-get -qq -y --allow-downgrades --allow-remove-essential --allow-change-held-packages dist-upgrade && apt-get clean && rm -rf /var/cache/apt/archives/* /var/lib/apt/lists/* /var/tmp/* + +# Install Herokuish. +# RUN curl --location --silent https://github.com/gliderlabs/herokuish/releases/download/v0.4.4/herokuish_0.4.4_linux_x86_64.tgz | tar -xzC /bin + +# -- Install dependencies: +RUN set -ex && pipenv install --deploy --system + +COPY . /bob +RUN pip3 install -e . + +CMD bob-builder /app +VOLUME /var/lib/docker +VOLUME /app diff --git a/README.md b/README.md index 120c1b5..d62b8c2 100644 --- a/README.md +++ b/README.md @@ -5,12 +5,12 @@ UNDER DEVELOPMENT ## Usage # Build a Dockerfile-based image. - $ bob-builder + $ bob-builder Building with orca-build. - # Build a Heroku-style repo. - $ bob-builder + # Build a Buildpack-style repo. + $ bob-builder Building with Heroku-ish. # Push to registry too. - $ bob-builder --push registry:80 + $ bob-builder --push diff --git a/bob/__main__.py b/bob/__main__.py index 34dc38d..20dfa33 100644 --- a/bob/__main__.py +++ b/bob/__main__.py @@ -1,7 +1,7 @@ """bob-builder: builds things. Usage: - bob-builder [--push ] [--insecure] [--username= --password=] + bob-builder [--push] [--username= --password=] [--insecure] """ from docopt import docopt @@ -11,15 +11,20 @@ from .builds import Build def main(): args = docopt(__doc__) - name = args[""] - codepath = args[""] - push = args[""] if args["--push"] else False + image_name = args[""] + codepath = args[""] + do_push = args["--push"] (username, password) = (args["--username"], args["--password"]) - insecure = args["--insecure"] + allow_insecure = args["--insecure"] build = Build( - name=name, codepath=codepath, push=push, username=username, password=password + image_name=image_name, + codepath=codepath, + do_push=do_push, + username=username, + password=password, + allow_insecure=allow_insecure, ) diff --git a/bob/builds.py b/bob/builds.py index 294781d..26c1110 100644 --- a/bob/builds.py +++ b/bob/builds.py @@ -13,20 +13,22 @@ class Build: def __init__( self, *, - name, + image_name, codepath, - push=False, + do_push=False, + allow_insecure=False, username=None, password=None, trigger_build=True, trigger_push=True, ): self.uuid = uuid4().hex - self.name = name + self.image_name = image_name self.codepath = Path(codepath) - self.push_to = push + self.do_push = do_push self.username = username self.password = password + self.allow_insecure = allow_insecure self.was_built = None assert os.path.exists(self.codepath) @@ -42,21 +44,23 @@ class Build: return all([self.username, self.password]) @property - def tag(self): - if not self.push_to: - return f"{self.name}:{self.uuid}" + def docker_tag(self): + if ":" in self.image_name: + return self.image_name else: - return f"{self.push_to}/{self.name}:{self.uuid}" + return f"{self.image_name}:{self.uuid}" @property def has_dockerfile(self): return os.path.isfile((self.codepath / "Dockerfile").resolve()) def ensure_docker(self): + # Start docker service. c = delegator.run("service docker start") time.sleep(0.3) try: + # Login to Docker. if self.requires_login: c = delegator.run(f"docker login -u {self.username} -p {self.password}") assert c.ok @@ -70,7 +74,11 @@ class Build: self.ensure_docker() - c = delegator.run(f"docker build {self.codepath} --tag {self.tag}") + c = delegator.run( + f"docker build {self.codepath} --tag {self.docker_tag}", block=False + ) + for line in c.err: + print(line) self.logger.debug(c.out) self.logger.debug(c.err) assert c.ok @@ -91,7 +99,7 @@ class Build: assert self.was_built assert self.push - c = delegator.run(f"docker push {self.tag}") + c = delegator.run(f"docker push {self.docker_tag}") self.logger.debug(c.out) self.logger.debug(c.err) assert c.ok