def test_get(self, mock_from): # The cache needs to calculate a digest from the base image. fake_base = mock.MagicMock() fake_base.digest.return_value = 'abc123' mock_img = mock.MagicMock() mock_from.return_value.__enter__.return_value = mock_img # Test when the image exists. mock_img.exists.return_value = True c = cache.Registry( repo='fake.gcr.io/google-appengine', namespace='namespace', creds=None, transport=None, ttl=constants.DEFAULT_TTL_WEEKS) self.assertEquals(c._getEntry('abc123'), mock_img) # Test when it does not exist mock_img.exists.return_value = False c = cache.Registry( repo='fake.gcr.io/google-appengine', namespace='namespace', creds=None, transport=None, ttl=constants.DEFAULT_TTL_WEEKS) self.assertIsNone(c._getEntry('abc123'))
def test_get(self, mock_from): # The cache needs to calculate a digest from the base image. fake_base = mock.MagicMock() fake_base.digest.return_value = 'abc123' mock_img = mock.MagicMock() mock_from.return_value.__enter__.return_value = mock_img # Test when the image exists. mock_img.exists.return_value = True create_timestamp = datetime.datetime.now().strftime( "%Y-%m-%dT%H:%M:%S") mock_img.config_file.return_value = '{{"created": "{}"}}'.format( create_timestamp) c = cache.Registry(repo='fake.gcr.io/google-appengine', namespace='namespace', creds=None, transport=None, ttl=constants.DEFAULT_TTL_HOURS) self.assertEquals(c._getEntry('abc123'), mock_img) # Test when it does not exist mock_img.exists.return_value = False c = cache.Registry(repo='fake.gcr.io/google-appengine', namespace='namespace', creds=None, transport=None, ttl=constants.DEFAULT_TTL_HOURS) self.assertIsNone(c._getEntry('abc123'))
def test_get(self, mock_from): # The cache needs to calculate a digest from the base image. fake_base = mock.MagicMock() fake_base.digest.return_value = 'abc123' mock_img = mock.MagicMock() mock_from.return_value.__enter__.return_value = mock_img # Test when the image exists. mock_img.exists.return_value = True c = cache.Registry('fake.gcr.io/google-appengine', None, None) self.assertEquals(c.Get(fake_base, 'namespace', 'abc123'), mock_img) # Test when it does not exist mock_img.exists.return_value = False c = cache.Registry('fake.gcr.io/google-appengine', None, None) self.assertIsNone(c.Get(fake_base, 'namespace', 'abc123'))
def main(): args = parser.parse_args() transport = transport_pool.Http(httplib2.Http, size=_THREADS) # TODO(mattmoor): Support digest base images. base_name = docker_name.Tag(args.base) base_creds = docker_creds.DefaultKeychain.Resolve(base_name) target_image = docker_name.Tag(args.name) target_creds = docker_creds.DefaultKeychain.Resolve(target_image) with context.Workspace(args.directory) as ctx: with cache.Registry(target_image.as_repository(), target_creds, transport, threads=_THREADS, mount=[base_name]) as cash: with builder.From(ctx) as bldr: with docker_image.FromRegistry(base_name, base_creds, transport) as base_image: # Create (or pull from cache) the base image with the package # descriptor installation overlaid. with bldr.CreatePackageBase(base_image, cash) as base_with_deps: # Construct the application layer from the context. app_layer = bldr.BuildAppLayer() with append.Layer(base_with_deps, app_layer) as app_image: with docker_session.Push(target_image, target_creds, transport, threads=_THREADS, mount=[base_name ]) as session: session.upload(app_image) print("Hi, One Build.")