def checkout_to(self, directory): # fetch into a bare repository so if we're on a host which has a cache we can # only get the new commits. fetch_git(self.bare_folder, self.url) # Warn if the ref_origin is set and gives a different sha1 than the # current ref. try: origin_commit = get_git_sha1(self.bare_folder, self.ref_origin) except Exception as ex: raise ValidationError("Unable to find sha1 of ref_origin {}: {}".format(self.ref_origin, ex)) if self.ref != origin_commit: logger.warning( "Current ref doesn't match the ref origin. " "Package ref should probably be updated to pick up " "new changes to the code:" + " Current: {}, Origin: {}".format(self.ref, origin_commit)) # Clone into `src/`. check_call(["git", "clone", "-q", self.bare_folder, directory]) # Checkout from the bare repo in the cache folder at the specific sha1 check_call([ "git", "--git-dir", directory + "/.git", "--work-tree", directory, "checkout", "-f", "-q", self.ref])
def _do_build_docker(name, path): path_sha = pkgpanda.build.hash_folder_abs(path, os.path.dirname(path)) container_name = 'dcos/dcos-builder:{}_dockerdir-{}'.format(name, path_sha) print("Attempting to pull docker:", container_name) pulled = False try: # TODO(cmaloney): Rather than pushing / pulling from Docker Hub upload as a build artifact. # the exported tarball. subprocess.check_call(['docker', 'pull', container_name]) pulled = True # TODO(cmaloney): Differentiate different failures of running the process better here except subprocess.CalledProcessError: pulled = False if not pulled: print("Pull failed, building instead:", container_name) # Pull failed, build it subprocess.check_call(['docker', 'build', '-t', container_name, path]) # TODO(cmaloney): Push the built docker image on successful package build to both # 1) commit-<commit_id> # 2) Dockerfile-<file_contents_sha1> # 3) bootstrap-<bootstrap_id> # So we can track back the builder id for a given commit or bootstrap id, and reproduce whatever # we need. The Dockerfile-<sha1> is useful for making sure we don't rebuild more than # necessary. try: subprocess.check_call(['docker', 'push', container_name]) except subprocess.CalledProcessError: logger.warning( "docker push of dcos-builder failed. This means it will be very difficult " "for this build to be reproduced (others will have a different / non-identical " "base docker for most packages.") pass # mark as latest so it will be used when building packages # extract the docker client version string try: docker_version = subprocess.check_output( ['docker', 'version', '-f', '{{.Client.Version}}']).decode() except subprocess.CalledProcessError: # If the above command fails then we know we have an older version of docker # Older versions of docker spit out an entirely different format docker_version = subprocess.check_output( ['docker', 'version']).decode().split("\n")[0].split()[2] # only use force tag if using docker version 1.9 or earlier container_name_t = 'dcos/dcos-builder:{}_dockerdir-latest'.format(name) if LooseVersion(docker_version) < LooseVersion('1.10'): args = ['docker', 'tag', '-f', container_name, container_name_t] else: args = ['docker', 'tag', container_name, container_name_t] subprocess.check_call(args)
def _do_build_docker(name, path): path_sha = pkgpanda.build.hash_folder_abs(path, os.path.dirname(path)) container_name = 'dcos/dcos-builder:{}_dockerdir-{}'.format(name, path_sha) print("Attempting to pull docker:", container_name) pulled = False try: # TODO(cmaloney): Rather than pushing / pulling from Docker Hub upload as a build artifact. # the exported tarball. subprocess.check_call(['docker', 'pull', container_name]) pulled = True # TODO(cmaloney): Differentiate different failures of running the process better here except subprocess.CalledProcessError: pulled = False if not pulled: print("Pull failed, building instead:", container_name) # Pull failed, build it subprocess.check_call(['docker', 'build', '-t', container_name, path]) # TODO(cmaloney): Push the built docker image on successful package build to both # 1) commit-<commit_id> # 2) Dockerfile-<file_contents_sha1> # 3) bootstrap-<bootstrap_id> # So we can track back the builder id for a given commit or bootstrap id, and reproduce whatever # we need. The Dockerfile-<sha1> is useful for making sure we don't rebuild more than # necessary. try: subprocess.check_call(['docker', 'push', container_name]) except subprocess.CalledProcessError: logger.warning("docker push of dcos-builder failed. This means it will be very difficult " "for this build to be reproduced (others will have a different / non-identical " "base docker for most packages.") pass # mark as latest so it will be used when building packages # extract the docker client version string try: docker_version = subprocess.check_output(['docker', 'version', '-f', '{{.Client.Version}}']).decode() except subprocess.CalledProcessError: # If the above command fails then we know we have an older version of docker # Older versions of docker spit out an entirely different format docker_version = subprocess.check_output(['docker', 'version']).decode().split("\n")[0].split()[2] # only use force tag if using docker version 1.9 or earlier container_name_t = 'dcos/dcos-builder:{}_dockerdir-latest'.format(name) if LooseVersion(docker_version) < LooseVersion('1.10'): args = ['docker', 'tag', '-f', container_name, container_name_t] else: args = ['docker', 'tag', container_name, container_name_t] subprocess.check_call(args)
def checkout_to(self, directory): # fetch into a bare repository so if we're on a host which has a cache we can # only get the new commits. fetch_git(self.bare_folder, self.url) # Warn if the ref_origin is set and gives a different sha1 than the # current ref. try: origin_commit = get_git_sha1(self.bare_folder, self.ref_origin) except Exception as ex: raise ValidationError("Unable to find sha1 of ref_origin {}: {}".format(self.ref_origin, ex)) if self.ref != origin_commit: logger.warning( "Current ref doesn't match the ref origin. " "Package ref should probably be updated to pick up " "new changes to the code:" + " Current: {}, Origin: {}".format(self.ref, origin_commit)) # Clone into `src/`. if is_windows: # Note: Mesos requires autocrlf to be set on Windows otherwise it does not build. check_call(["git", "clone", "-q", "--config", "core.autocrlf=true", self.bare_folder, directory]) else: check_call(["git", "clone", "-q", self.bare_folder, directory]) # Checkout from the bare repo in the cache folder at the specific sha1 check_call([ "git", "--git-dir", directory + "/.git", "--work-tree", directory, "checkout", "-f", "-q", self.ref])