Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

support ccp image call #3607

Merged
merged 3 commits into from
Sep 20, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion dashboard/src/components/image-selector/TagList.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ export default class TagList extends Component<PropsType, StateType> {
const [latestImage] = tags.splice(latestImageIndex, 1);
tags.unshift(latestImage);
}
this.setState({ tags: tags.map((tag) => tag.tag), loading: false });
this.setState({ tags: tags.map((tag) => tag.tag), loading: false, error: false });
})
.catch((err) => {
console.log(err);
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ require (
github.com/matryer/is v1.4.0
github.com/nats-io/nats.go v1.24.0
github.com/open-policy-agent/opa v0.44.0
github.com/porter-dev/api-contracts v0.1.5
github.com/porter-dev/api-contracts v0.1.6
github.com/riandyrn/otelchi v0.5.1
github.com/santhosh-tekuri/jsonschema/v5 v5.0.1
github.com/stefanmcshane/helm v0.0.0-20221213002717-88a4a2c6e77d
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -1516,8 +1516,8 @@ github.com/pmezard/go-difflib v0.0.0-20151028094244-d8ed2627bdf0/go.mod h1:iKH77
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
github.com/polyfloyd/go-errorlint v0.0.0-20210722154253-910bb7978349/go.mod h1:wi9BfjxjF/bwiZ701TzmfKu6UKC357IOAtNr0Td0Lvw=
github.com/porter-dev/api-contracts v0.1.5 h1:Nz0bEIXedKHYfC0YzOj579ABXHxDaH4DXjKcstvWR8A=
github.com/porter-dev/api-contracts v0.1.5/go.mod h1:fX6JmP5QuzxDLvqP3evFOTXjI4dHxsG0+VKNTjImZU8=
github.com/porter-dev/api-contracts v0.1.6 h1:nMP/+M53Mohwe/1mNq/HYEnfIKEiDHEFItZwjLmPZ+8=
github.com/porter-dev/api-contracts v0.1.6/go.mod h1:fX6JmP5QuzxDLvqP3evFOTXjI4dHxsG0+VKNTjImZU8=
github.com/porter-dev/switchboard v0.0.3 h1:dBuYkiVLa5Ce7059d6qTe9a1C2XEORFEanhbtV92R+M=
github.com/porter-dev/switchboard v0.0.3/go.mod h1:xSPzqSFMQ6OSbp42fhCi4AbGbQbsm6nRvOkrblFeXU4=
github.com/posener/complete v1.1.1/go.mod h1:em0nMJCgc9GFtwrmVmEMR/ZL6WyhyjMBndrE9hABlRI=
Expand Down
44 changes: 44 additions & 0 deletions internal/registry/registry.go
Original file line number Diff line number Diff line change
Expand Up @@ -1026,6 +1026,17 @@ func (r *Registry) ListImages(
repo repository.Repository,
conf *config.Config,
) ([]*ptypes.Image, error) {
ctx, span := telemetry.NewSpan(ctx, "list-repositories")
defer span.End()

telemetry.WithAttributes(span,
telemetry.AttributeKV{Key: "registry-name", Value: r.Name},
telemetry.AttributeKV{Key: "registry-id", Value: r.ID},
telemetry.AttributeKV{Key: "registry-url", Value: r.URL},
telemetry.AttributeKV{Key: "project-id", Value: r.ProjectID},
telemetry.AttributeKV{Key: "repo-name", Value: repoName},
)

// switch on the auth mechanism to get a token
if r.AWSIntegrationID != 0 {
aws, err := repo.AWSIntegration().ReadAWSIntegration(
Expand Down Expand Up @@ -1064,6 +1075,39 @@ func (r *Registry) ListImages(
}

if project.GetFeatureFlag(models.CapiProvisionerEnabled, conf.LaunchDarklyClient) {

if strings.Contains(r.URL, ".azurecr.") || strings.Contains(r.URL, "-docker.pkg.dev") {
req := connect.NewRequest(&porterv1.ListImagesForRepositoryRequest{
ProjectId: int64(r.ProjectID),
RegistryUri: r.URL,
RepoName: repoName,
})

resp, err := conf.ClusterControlPlaneClient.ListImagesForRepository(ctx, req)
if err != nil {
return nil, telemetry.Error(ctx, span, err, "error calling ccp list images")
}

res := make([]*ptypes.Image, 0)

for _, image := range resp.Msg.Images {
if image.UpdatedAt == nil {
continue
}
lastUpdateTime := image.UpdatedAt.AsTime()

res = append(res, &ptypes.Image{
Digest: image.Digest,
Tag: image.Tag,
Manifest: "",
RepositoryName: image.RepositoryName,
PushedAt: &lastUpdateTime,
})
}

return res, nil
}

uri := strings.TrimPrefix(r.URL, "https://")
splits := strings.Split(uri, ".")
accountID := splits[0]
Expand Down