def test_force_push_uuid_tag(fake_process): """Check that the push command actually attempts to tag and push.""" project_id = "project" image_id = "imageid" tag = p._image_tag_for_project(project_id, image_id) fake_process.register_subprocess(["docker", "tag", image_id, tag]) fake_process.register_subprocess(["docker", "push", tag]) assert p.push_uuid_tag(project_id, image_id, force=True) == tag
def test_already_pushed_uuid_tag(fake_process): """Check that push_uuid_tag does NOT attempt to push if the process already exists..""" project_id = "project" image_id = "imageid" base_tag = p._image_tag_for_project(project_id, image_id, include_tag=False) tag = p._image_tag_for_project(project_id, image_id) register_list_tags(fake_process, project_id, base_tag, stdout="[{\"metadata\": []}]") assert p.push_uuid_tag(project_id, image_id) == tag
def generate_image_tag(project_id, docker_args, dry_run: bool = False): """Generates a new Docker image and pushes an image to the user's GCloud Container Repository, tagged using the UUID of the generated image. If dry_run is true, logs the Docker image build parameters and returns a bogus tag. """ logging.info("Generating Docker image with parameters:") logging.info(t.yellow(pformat(docker_args))) if dry_run: logging.info("Dry run - skipping actual 'docker build' and 'docker push'.") image_tag = "dry_run_tag" else: image_id = db.build_image(**docker_args) image_tag = dp.push_uuid_tag(project_id, image_id) return image_tag
def test_push_uuid_tag_if_no_remote_image(fake_process): """Check that push_uuid_tag DOES attempt to push if the image doesn't exist in the remote container registry already. """ project_id = "project" image_id = "imageid" base_tag = p._image_tag_for_project(project_id, image_id, include_tag=False) tag = p._image_tag_for_project(project_id, image_id) register_list_tags(fake_process, project_id, base_tag, stdout="[]") fake_process.register_subprocess(["docker", "tag", image_id, tag]) fake_process.register_subprocess(["docker", "push", tag]) assert p.push_uuid_tag(project_id, image_id) == tag
def _rebuild_containers( jobs: Iterable[Job], project_id: Optional[str] = None, ) -> Dict[Job, str]: '''this utility rebuilds all the needed containers for the given jobs This also tags and uploads the containers to the appropriate project cloud registry if necessary. Args: jobs: iterable of jobs for which to rebuild containers project_id: project id Returns: dictionary mapping jobs to new image tags ''' image_id_map = {} container_specs = set([j.experiment.container_spec for j in jobs]) for c in container_specs: image_id = build_image(**c.spec) cs_jobs = filter(lambda x: x.experiment.container_spec == c, jobs) image_tag = None for j in cs_jobs: if j.spec.platform in [Platform.CAIP, Platform.GKE]: assert project_id != None, 'project id must be specified for CAIP, GKE jobs' if image_tag is None: image_tag = push_uuid_tag(project_id, image_id) image_id_map[j] = image_tag else: image_id_map[j] = image_id return image_id_map