mirror of
https://github.com/kennethreitz/bob-builder.git
synced 2026-06-05 23:20:17 +00:00
push
This commit is contained in:
Vendored
+3
@@ -0,0 +1,3 @@
|
||||
{
|
||||
"python.pythonPath": "C:\\Users\\me\\.virtualenvs\\bruce-operator-UKafV52I\\Scripts\\python.exe"
|
||||
}
|
||||
+41
-1
@@ -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
|
||||
|
||||
@@ -5,12 +5,12 @@ UNDER DEVELOPMENT
|
||||
## Usage
|
||||
|
||||
# Build a Dockerfile-based image.
|
||||
$ bob-builder <path-to-code>
|
||||
$ bob-builder <code-path> <image-name>
|
||||
Building with orca-build.
|
||||
|
||||
# Build a Heroku-style repo.
|
||||
$ bob-builder <path-to-code>
|
||||
# Build a Buildpack-style repo.
|
||||
$ bob-builder <code-path> <image-name>
|
||||
Building with Heroku-ish.
|
||||
|
||||
# Push to registry too.
|
||||
$ bob-builder <path-to-code> --push registry:80
|
||||
$ bob-builder <path-to-code> <image-name> --push
|
||||
|
||||
+11
-6
@@ -1,7 +1,7 @@
|
||||
"""bob-builder: builds things.
|
||||
|
||||
Usage:
|
||||
bob-builder <name> <path-to-code> [--push <docker-push>] [--insecure] [--username=<username> --password=<password>]
|
||||
bob-builder <code_path> <image-name> [--push] [--username=<username> --password=<password>] [--insecure]
|
||||
"""
|
||||
|
||||
from docopt import docopt
|
||||
@@ -11,15 +11,20 @@ from .builds import Build
|
||||
|
||||
def main():
|
||||
args = docopt(__doc__)
|
||||
name = args["<name>"]
|
||||
codepath = args["<path-to-code>"]
|
||||
push = args["<docker-push>"] if args["--push"] else False
|
||||
image_name = args["<image-name>"]
|
||||
codepath = args["<code_path>"]
|
||||
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,
|
||||
)
|
||||
|
||||
|
||||
|
||||
+18
-10
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user