(t *testing.T, pool *dockertest.Pool, opts pushOptions)
| 527 | } |
| 528 | |
| 529 | func pushLocalImage(t *testing.T, pool *dockertest.Pool, opts pushOptions) RegistryImage { |
| 530 | t.Helper() |
| 531 | |
| 532 | const registryHost = "127.0.0.1" |
| 533 | name := filepath.Base(opts.RemoteImage) |
| 534 | repoTag := strings.Split(name, ":") |
| 535 | tag := "latest" |
| 536 | if len(repoTag) == 2 { |
| 537 | tag = repoTag[1] |
| 538 | } |
| 539 | |
| 540 | tw := &testWriter{ |
| 541 | t: t, |
| 542 | } |
| 543 | err := pool.Client.PullImage(docker.PullImageOptions{ |
| 544 | Repository: strings.Split(opts.RemoteImage, ":")[0], |
| 545 | Tag: tag, |
| 546 | OutputStream: tw, |
| 547 | }, docker.AuthConfiguration{}) |
| 548 | require.NoError(t, err) |
| 549 | |
| 550 | _, port, err := net.SplitHostPort(opts.Host) |
| 551 | require.NoError(t, err) |
| 552 | |
| 553 | err = pool.Client.TagImage(opts.RemoteImage, docker.TagImageOptions{ |
| 554 | Repo: fmt.Sprintf("%s:%s/%s", registryHost, port, name), |
| 555 | Tag: tag, |
| 556 | }) |
| 557 | require.NoError(t, err) |
| 558 | |
| 559 | type config struct { |
| 560 | Auths map[string]dockerutil.AuthConfig `json:"auths"` |
| 561 | } |
| 562 | |
| 563 | auth := base64.StdEncoding.EncodeToString([]byte(fmt.Sprintf("%s:%s", opts.Username, opts.Password))) |
| 564 | |
| 565 | cfg := config{ |
| 566 | Auths: map[string]dockerutil.AuthConfig{ |
| 567 | net.JoinHostPort(registryHost, port): { |
| 568 | Username: opts.Username, |
| 569 | Password: opts.Password, |
| 570 | Auth: auth, |
| 571 | }, |
| 572 | }, |
| 573 | } |
| 574 | b, err := json.Marshal(cfg) |
| 575 | require.NoError(t, err) |
| 576 | configPath := filepath.Join(opts.ConfigDir, "config.json") |
| 577 | WriteFile(t, configPath, string(b)) |
| 578 | |
| 579 | // Idk what to tell you but the pool.Client.PushImage |
| 580 | // function is bugged or I'm just dumb... |
| 581 | image := fmt.Sprintf("%s:%s/%s:%s", registryHost, port, name, tag) |
| 582 | //nolint:gosec |
| 583 | cmd := exec.Command("docker", "--config", opts.ConfigDir, "push", image) |
| 584 | cmd.Stderr = tw |
| 585 | cmd.Stdout = tw |
| 586 | err = cmd.Run() |
no test coverage detected