Skip to content

Commit e425c8f

Browse files
authored
src!: change all references of "repository" to "registry" for images (#156)
When dealing with images, instead of referring to an image repository, let's instead use the more correct term "registry", even though we're actually using "registry/namespace" in most case. Signed-off-by: Lance Ball <lball@redhat.com>
1 parent 6d30125 commit e425c8f

10 files changed

+129
-133
lines changed

client.go

+5-5
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ type Client struct {
2828
describer Describer
2929
dnsProvider DNSProvider // Provider of DNS services
3030
templates string // path to extensible templates
31-
repository string // default repo for OCI image tags
31+
registry string // default registry for OCI image tags
3232
domainSearchLimit int // max recursion when deriving domain
3333
progressListener ProgressListener // progress listener
3434
}
@@ -225,13 +225,13 @@ func WithTemplates(templates string) Option {
225225
}
226226
}
227227

228-
// WithRepository sets the default registry which is consulted when an image name/tag
228+
// WithRegistry sets the default registry which is consulted when an image name/tag
229229
// is not explocitly provided. Can be fully qualified, including the registry
230230
// (ex: 'quay.io/myname') or simply the namespace 'myname' which indicates the
231231
// the use of the default registry.
232-
func WithRepository(repository string) Option {
232+
func WithRegistry(registry string) Option {
233233
return func(c *Client) {
234-
c.repository = repository
234+
c.registry = registry
235235
}
236236
}
237237

@@ -377,7 +377,7 @@ func (c *Client) Build(path string) (err error) {
377377
}
378378

379379
// Derive Image from the path (precedence is given to extant config)
380-
if f.Image, err = DerivedImage(path, c.repository); err != nil {
380+
if f.Image, err = DerivedImage(path, c.registry); err != nil {
381381
return
382382
}
383383

client_test.go

+28-29
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,10 @@ import (
1111
"github.com/boson-project/faas/mock"
1212
)
1313

14-
// TestRepository for calculating destination image during tests.
14+
// TestRegistry for calculating destination image during tests.
1515
// Will be optional once we support in-cluster container registries
16-
// by default. See TestRepositoryRequired for details.
17-
const TestRepository = "quay.io/alice"
16+
// by default. See TestRegistryRequired for details.
17+
const TestRegistry = "quay.io/alice"
1818

1919
// TestCreate completes without error using all defaults and zero values. The base case.
2020
func TestCreate(t *testing.T) {
@@ -25,7 +25,7 @@ func TestCreate(t *testing.T) {
2525
}
2626
defer os.RemoveAll(root)
2727

28-
client := faas.New(faas.WithRepository(TestRepository))
28+
client := faas.New(faas.WithRegistry(TestRegistry))
2929

3030
if err := client.Create(faas.Function{Root: root}); err != nil {
3131
t.Fatal(err)
@@ -42,7 +42,7 @@ func TestCreateWritesTemplate(t *testing.T) {
4242
defer os.RemoveAll(root)
4343

4444
// Create the function at root
45-
client := faas.New(faas.WithRepository(TestRepository))
45+
client := faas.New(faas.WithRegistry(TestRegistry))
4646
if err := client.Create(faas.Function{Root: root}); err != nil {
4747
t.Fatal(err)
4848
}
@@ -125,7 +125,7 @@ func TestCreateDefaultRuntime(t *testing.T) {
125125
defer os.RemoveAll(root)
126126

127127
// Create a new function at root with all defaults.
128-
client := faas.New(faas.WithRepository(TestRepository))
128+
client := faas.New(faas.WithRegistry(TestRegistry))
129129
if err := client.Create(faas.Function{Root: root}); err != nil {
130130
t.Fatal(err)
131131
}
@@ -154,8 +154,7 @@ func TestCreateDefaultTrigger(t *testing.T) {
154154
// location is not defined herein but expected to be provided because, for
155155
// example, a CLI may want to use XDG_CONFIG_HOME. Assuming a repository path
156156
// $FAAS_TEMPLATES, a Go template named 'json' which is provided in the
157-
// repository repository 'boson-experimental', would be expected to be in the
158-
// location:
157+
// repository 'boson-experimental', would be expected to be in the location:
159158
// $FAAS_TEMPLATES/boson-experimental/go/json
160159
// See the CLI for full details, but a standard default location is
161160
// $HOME/.config/templates/boson-experimental/go/json
@@ -170,7 +169,7 @@ func TestExtensibleTemplates(t *testing.T) {
170169
// Create a new client with a path to the extensible templates
171170
client := faas.New(
172171
faas.WithTemplates("testdata/templates"),
173-
faas.WithRepository(TestRepository))
172+
faas.WithRegistry(TestRegistry))
174173

175174
// Create a Function specifying a template, 'json' that only exists in the extensible set
176175
if err := client.Create(faas.Function{Root: root, Trigger: "boson-experimental/json"}); err != nil {
@@ -243,7 +242,7 @@ func TestNamed(t *testing.T) {
243242
}
244243
defer os.RemoveAll(root)
245244

246-
client := faas.New(faas.WithRepository(TestRepository))
245+
client := faas.New(faas.WithRegistry(TestRegistry))
247246

248247
if err := client.Create(faas.Function{Root: root, Name: name}); err != nil {
249248
t.Fatal(err)
@@ -259,19 +258,19 @@ func TestNamed(t *testing.T) {
259258
}
260259
}
261260

262-
// TestRepository ensures that a repository is required, and is
261+
// TestRegistry ensures that a registry is required, and is
263262
// prepended with the DefaultRegistry if a single token.
264-
// Repository is the namespace at the container image registry.
263+
// Registry is the namespace at the container image registry.
265264
// If not prepended with the registry, it will be defaulted:
266265
// Examples: "docker.io/alice"
267266
// "quay.io/bob"
268267
// "charlie" (becomes [DefaultRegistry]/charlie
269-
// At this time a repository namespace is required as we rely on a third-party
268+
// At this time a registry namespace is required as we rely on a third-party
270269
// registry in all cases. When we support in-cluster container registries,
271270
// this configuration parameter will become optional.
272-
func TestRepositoryRequired(t *testing.T) {
271+
func TestRegistryRequired(t *testing.T) {
273272
// Create a root for the Function
274-
root := "testdata/example.com/testRepository"
273+
root := "testdata/example.com/testRegistry"
275274
if err := os.MkdirAll(root, 0700); err != nil {
276275
t.Fatal(err)
277276
}
@@ -285,7 +284,7 @@ func TestRepositoryRequired(t *testing.T) {
285284
}
286285

287286
// TestDeriveImage ensures that the full image (tag) of the resultant OCI
288-
// container is populated based of a derivation using configured repository
287+
// container is populated based of a derivation using configured registry
289288
// plus the service name.
290289
func TestDeriveImage(t *testing.T) {
291290
// Create the root Function directory
@@ -296,7 +295,7 @@ func TestDeriveImage(t *testing.T) {
296295
defer os.RemoveAll(root)
297296

298297
// Create the function which calculates fields such as name and image.
299-
client := faas.New(faas.WithRepository(TestRepository))
298+
client := faas.New(faas.WithRegistry(TestRegistry))
300299
if err := client.Create(faas.Function{Root: root}); err != nil {
301300
t.Fatal(err)
302301
}
@@ -307,14 +306,14 @@ func TestDeriveImage(t *testing.T) {
307306
t.Fatal(err)
308307
}
309308

310-
// In form: [Default Registry]/[Repository Namespace]/[Service Name]:latest
311-
expected := TestRepository + "/" + f.Name + ":latest"
309+
// In form: [Default Registry]/[Registry Namespace]/[Service Name]:latest
310+
expected := TestRegistry + "/" + f.Name + ":latest"
312311
if f.Image != expected {
313312
t.Fatalf("expected image '%v' got '%v'", expected, f.Image)
314313
}
315314
}
316315

317-
// TestDeriveImageDefaultRegistry ensures that a Repository which does not have
316+
// TestDeriveImageDefaultRegistry ensures that a Registry which does not have
318317
// a registry prefix has the DefaultRegistry prepended.
319318
// For example "alice" becomes "docker.io/alice"
320319
func TestDeriveImageDefaultRegistry(t *testing.T) {
@@ -326,9 +325,9 @@ func TestDeriveImageDefaultRegistry(t *testing.T) {
326325
defer os.RemoveAll(root)
327326

328327
// Create the function which calculates fields such as name and image.
329-
// Rather than use TestRepository, use a single-token name and expect
328+
// Rather than use TestRegistry, use a single-token name and expect
330329
// the DefaultRegistry to be prepended.
331-
client := faas.New(faas.WithRepository("alice"))
330+
client := faas.New(faas.WithRegistry("alice"))
332331
if err := client.Create(faas.Function{Root: root}); err != nil {
333332
t.Fatal(err)
334333
}
@@ -351,7 +350,7 @@ func TestDeriveImageDefaultRegistry(t *testing.T) {
351350
func TestCreateDelegates(t *testing.T) {
352351
var (
353352
root = "testdata/example.com/testCreateDelegates" // .. in which to initialize
354-
expectedName = "testCreateDelegates" // expected to be derived
353+
expectedName = "testCreateDelegates" // expected to be derived
355354
expectedImage = "quay.io/alice/testCreateDelegates:latest"
356355
builder = mock.NewBuilder()
357356
pusher = mock.NewPusher()
@@ -366,7 +365,7 @@ func TestCreateDelegates(t *testing.T) {
366365

367366
// Create a client with mocks for each of the subcomponents.
368367
client := faas.New(
369-
faas.WithRepository(TestRepository),
368+
faas.WithRegistry(TestRegistry),
370369
faas.WithBuilder(builder), // builds an image
371370
faas.WithPusher(pusher), // pushes images to a registry
372371
faas.WithDeployer(deployer), // deploys images as a running service
@@ -437,7 +436,7 @@ func TestRun(t *testing.T) {
437436

438437
// Create a client with the mock runner and the new test Function
439438
runner := mock.NewRunner()
440-
client := faas.New(faas.WithRepository(TestRepository), faas.WithRunner(runner))
439+
client := faas.New(faas.WithRegistry(TestRegistry), faas.WithRunner(runner))
441440
if err := client.Create(faas.Function{Root: root}); err != nil {
442441
t.Fatal(err)
443442
}
@@ -480,7 +479,7 @@ func TestUpdate(t *testing.T) {
480479

481480
// A client with mocks whose implementaton will validate input.
482481
client := faas.New(
483-
faas.WithRepository(TestRepository),
482+
faas.WithRegistry(TestRegistry),
484483
faas.WithBuilder(builder),
485484
faas.WithPusher(pusher),
486485
faas.WithDeployer(deployer))
@@ -554,7 +553,7 @@ func TestRemoveByPath(t *testing.T) {
554553
defer os.RemoveAll(root)
555554

556555
client := faas.New(
557-
faas.WithRepository(TestRepository),
556+
faas.WithRegistry(TestRegistry),
558557
faas.WithRemover(remover))
559558

560559
if err := client.Create(faas.Function{Root: root}); err != nil {
@@ -593,7 +592,7 @@ func TestRemoveByName(t *testing.T) {
593592
defer os.RemoveAll(root)
594593

595594
client := faas.New(
596-
faas.WithRepository(TestRepository),
595+
faas.WithRegistry(TestRegistry),
597596
faas.WithRemover(remover))
598597

599598
if err := client.Create(faas.Function{Root: root}); err != nil {
@@ -644,7 +643,7 @@ func TestRemoveUninitializedFails(t *testing.T) {
644643

645644
// Instantiate the client with the failing remover.
646645
client := faas.New(
647-
faas.WithRepository(TestRepository),
646+
faas.WithRegistry(TestRegistry),
648647
faas.WithRemover(remover))
649648

650649
// Attempt to remove by path (uninitialized), expecting an error.

cmd/build.go

+27-29
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,9 @@ func init() {
1515
root.AddCommand(buildCmd)
1616
buildCmd.Flags().StringP("builder", "b", "default", "Buildpacks builder")
1717
buildCmd.Flags().BoolP("confirm", "c", false, "Prompt to confirm all configuration options - $FAAS_CONFIRM")
18-
buildCmd.Flags().StringP("image", "i", "", "Optional full image name, in form [registry]/[namespace]/[name]:[tag] for example quay.io/myrepo/project.name:latest (overrides --repository) - $FAAS_IMAGE")
18+
buildCmd.Flags().StringP("image", "i", "", "Optional full image name, in form [registry]/[namespace]/[name]:[tag] for example quay.io/myrepo/project.name:latest (overrides --registry) - $FAAS_IMAGE")
1919
buildCmd.Flags().StringP("path", "p", cwd(), "Path to the Function project directory - $FAAS_PATH")
20-
buildCmd.Flags().StringP("repository", "r", "", "Repository for built images, ex 'docker.io/myuser' or just 'myuser'. Optional if --image provided. - $FAAS_REPOSITORY")
20+
buildCmd.Flags().StringP("registry", "r", "", "Registry for built images, ex 'docker.io/myuser' or just 'myuser'. Optional if --image provided. - $FAAS_REGISTRY")
2121

2222
err := buildCmd.RegisterFlagCompletionFunc("builder", CompleteBuilderList)
2323
if err != nil {
@@ -32,20 +32,20 @@ var buildCmd = &cobra.Command{
3232
3333
Builds the Function project in the current directory or in the directory
3434
specified by the --path flag. The faas.yaml file is read to determine the
35-
image name and repository. If both of these values are unset in the
36-
configuration file the --repository or -r flag should be provided and an image
35+
image name and registry. If both of these values are unset in the
36+
configuration file the --registry or -r flag should be provided and an image
3737
name will be derived from the project name.
3838
39-
Any value provided for --image or --repository will be persisted in the
40-
faas.yaml configuration file. On subsequent invocations of the "build" command
39+
Any value provided for the --image flag will be persisted in the faas.yaml
40+
configuration file. On subsequent invocations of the "build" command
4141
these values will be read from the configuration file.
4242
4343
It's possible to use a custom Buildpack builder with the --builder flag.
4444
The value may be image name e.g. "cnbs/sample-builder:bionic",
4545
or reference to builderMaps in the config file e.g. "default".
4646
`,
4747
SuggestFor: []string{"biuld", "buidl", "built"},
48-
PreRunE: bindEnv("image", "path", "builder", "repository", "confirm"),
48+
PreRunE: bindEnv("image", "path", "builder", "registry", "confirm"),
4949
RunE: runBuild,
5050
}
5151

@@ -57,12 +57,12 @@ func runBuild(cmd *cobra.Command, _ []string) (err error) {
5757
}
5858

5959
// If the Function does not yet have an image name, and one was not provided
60-
// on the command line AND a --repository was not provided, then we need to
61-
// prompt for a repository from which we can derive an image name.
62-
if function.Image == "" && config.Repository == "" {
63-
fmt.Print("A repository for Function images is required. For example, 'docker.io/tigerteam'.\n\n")
64-
config.Repository = prompt.ForString("Repository for Function images", "")
65-
if config.Repository == "" {
60+
// on the command line AND a --registry was not provided, then we need to
61+
// prompt for a registry from which we can derive an image name.
62+
if function.Image == "" && config.Registry == "" {
63+
fmt.Print("A registry for Function images is required. For example, 'docker.io/tigerteam'.\n\n")
64+
config.Registry = prompt.ForString("Registry for Function images", "")
65+
if config.Registry == "" {
6666
return fmt.Errorf("Unable to determine Function image name")
6767
}
6868
}
@@ -72,7 +72,7 @@ func runBuild(cmd *cobra.Command, _ []string) (err error) {
7272

7373
client := faas.New(
7474
faas.WithVerbose(config.Verbose),
75-
faas.WithRepository(config.Repository), // for deriving image name when --image not provided explicitly.
75+
faas.WithRegistry(config.Registry), // for deriving image name when --image not provided explicitly.
7676
faas.WithBuilder(builder))
7777

7878
config.Prompt()
@@ -82,21 +82,19 @@ func runBuild(cmd *cobra.Command, _ []string) (err error) {
8282

8383
type buildConfig struct {
8484
// Image name in full, including registry, repo and tag (overrides
85-
// image name derivation based on Repository and Function Name)
85+
// image name derivation based on Registry and Function Name)
8686
Image string
8787

8888
// Path of the Function implementation on local disk. Defaults to current
8989
// working directory of the process.
9090
Path string
9191

92-
// Push the resultnat image to the repository after building.
92+
// Push the resulting image to the registry after building.
9393
Push bool
9494

95-
// Repository at which interstitial build artifacts should be kept.
96-
// Registry is optional and is defaulted to faas.DefaultRegistry.
97-
// ex: "quay.io/myrepo" or "myrepo"
95+
// Registry at which interstitial build artifacts should be kept.
9896
// This setting is ignored if Image is specified, which includes the full
99-
Repository string
97+
Registry string
10098

10199
// Verbose logging.
102100
Verbose bool
@@ -109,20 +107,20 @@ type buildConfig struct {
109107

110108
func newBuildConfig() buildConfig {
111109
return buildConfig{
112-
Image: viper.GetString("image"),
113-
Path: viper.GetString("path"),
114-
Repository: viper.GetString("repository"),
115-
Verbose: viper.GetBool("verbose"), // defined on root
116-
Confirm: viper.GetBool("confirm"),
117-
Builder: viper.GetString("builder"),
110+
Image: viper.GetString("image"),
111+
Path: viper.GetString("path"),
112+
Registry: viper.GetString("registry"),
113+
Verbose: viper.GetBool("verbose"), // defined on root
114+
Confirm: viper.GetBool("confirm"),
115+
Builder: viper.GetString("builder"),
118116
}
119117
}
120118

121119
// Prompt the user with value of config members, allowing for interaractive changes.
122120
// Skipped if not in an interactive terminal (non-TTY), or if --confirm false (agree to
123121
// all prompts) was set (default).
124122
func (c buildConfig) Prompt() buildConfig {
125-
imageName := deriveImage(c.Image, c.Repository, c.Path)
123+
imageName := deriveImage(c.Image, c.Registry, c.Path)
126124
if !interactiveTerminal() || !c.Confirm {
127125
// If --confirm false or non-interactive, just print the image name
128126
fmt.Printf("Building image: %v\n", imageName)
@@ -132,7 +130,7 @@ func (c buildConfig) Prompt() buildConfig {
132130
Path: prompt.ForString("Path to project directory", c.Path),
133131
Image: prompt.ForString("Image name", imageName, prompt.WithRequired(true)),
134132
Verbose: c.Verbose,
135-
// Repository not prompted for as it would be confusing when combined with explicit image. Instead it is
136-
// inferred by the derived default for Image, which uses Repository for derivation.
133+
// Registry not prompted for as it would be confusing when combined with explicit image. Instead it is
134+
// inferred by the derived default for Image, which uses Registry for derivation.
137135
}
138136
}

0 commit comments

Comments
 (0)