diff --git a/cmd/pipectl/BUILD.bazel b/cmd/pipectl/BUILD.bazel index 8b4191a675..a34f29f7f8 100644 --- a/cmd/pipectl/BUILD.bazel +++ b/cmd/pipectl/BUILD.bazel @@ -9,6 +9,7 @@ go_library( deps = [ "//pkg/app/pipectl/cmd/application:go_default_library", "//pkg/app/pipectl/cmd/deployment:go_default_library", + "//pkg/app/pipectl/cmd/image:go_default_library", "//pkg/cli:go_default_library", ], ) diff --git a/cmd/pipectl/main.go b/cmd/pipectl/main.go index 4abd622dc9..b6d7b29c78 100644 --- a/cmd/pipectl/main.go +++ b/cmd/pipectl/main.go @@ -20,6 +20,7 @@ import ( "github.com/pipe-cd/pipe/pkg/app/pipectl/cmd/application" "github.com/pipe-cd/pipe/pkg/app/pipectl/cmd/deployment" + "github.com/pipe-cd/pipe/pkg/app/pipectl/cmd/image" "github.com/pipe-cd/pipe/pkg/cli" ) @@ -32,6 +33,7 @@ func main() { app.AddCommands( application.NewCommand(), deployment.NewCommand(), + image.NewCommand(), ) if err := app.Run(); err != nil { diff --git a/docs/content/en/docs/user-guide/command-line-tool.md b/docs/content/en/docs/user-guide/command-line-tool.md index 2532af4ebd..aa98d57aa4 100644 --- a/docs/content/en/docs/user-guide/command-line-tool.md +++ b/docs/content/en/docs/user-guide/command-line-tool.md @@ -16,7 +16,7 @@ You can use pipectl to add and sync applications, wait for a deployment status. 1. Download the appropriate version for your platform from [PipeCD Releases](https://github.com/pipe-cd/pipe/releases). We recommend using the latest version of pipectl to avoid unforeseen issues. - Please set `${VERSION}` to the same format like `v0.9.2`. + Please set `${VERSION}` to the same format like `v0.9.4`. ``` console curl -Lo ./pipectl https://github.com/pipe-cd/pipe/releases/download/${VERSION}/pipectl_${VERSION}_darwin_amd64 @@ -186,6 +186,18 @@ pipectl deployment wait-status \ --status=DEPLOYMENT_SUCCESS ``` +### Pushing an image reference + +Push a new container image reference that can be used by ImageWatcher. + +``` console +pipectl image push-reference \ + --address=CONTROL_PLANE_API_ADDRESS \ + --api-key=API_KEY \ + --repo-name=gcr.io/pipecd/example \ + --tag=v0.1.0 +``` + ### You want more? We always want to add more needed commands into pipectl. Please let us know what command do you want to add by creating issues in the [pipe-cd/pipe ](https://github.com/pipe-cd/pipe/issues) repository. We also welcome your pull request to add the command. diff --git a/pkg/app/pipectl/cmd/image/BUILD.bazel b/pkg/app/pipectl/cmd/image/BUILD.bazel new file mode 100644 index 0000000000..d977106023 --- /dev/null +++ b/pkg/app/pipectl/cmd/image/BUILD.bazel @@ -0,0 +1,17 @@ +load("@io_bazel_rules_go//go:def.bzl", "go_library") + +go_library( + name = "go_default_library", + srcs = [ + "image.go", + "pushreference.go", + ], + importpath = "github.com/pipe-cd/pipe/pkg/app/pipectl/cmd/image", + visibility = ["//visibility:public"], + deps = [ + "//pkg/app/api/service/apiservice:go_default_library", + "//pkg/app/pipectl/client:go_default_library", + "//pkg/cli:go_default_library", + "@com_github_spf13_cobra//:go_default_library", + ], +) diff --git a/pkg/app/pipectl/cmd/image/image.go b/pkg/app/pipectl/cmd/image/image.go new file mode 100644 index 0000000000..8c486a2a04 --- /dev/null +++ b/pkg/app/pipectl/cmd/image/image.go @@ -0,0 +1,43 @@ +// Copyright 2021 The PipeCD Authors. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +package image + +import ( + "github.com/spf13/cobra" + + "github.com/pipe-cd/pipe/pkg/app/pipectl/client" +) + +type command struct { + clientOptions *client.Options +} + +func NewCommand() *cobra.Command { + c := &command{ + clientOptions: &client.Options{}, + } + cmd := &cobra.Command{ + Use: "image", + Short: "Manage image resources.", + } + + cmd.AddCommand( + newPushReferenceCommand(c), + ) + + c.clientOptions.RegisterPersistentFlags(cmd) + + return cmd +} diff --git a/pkg/app/pipectl/cmd/image/pushreference.go b/pkg/app/pipectl/cmd/image/pushreference.go new file mode 100644 index 0000000000..ea6c38aee9 --- /dev/null +++ b/pkg/app/pipectl/cmd/image/pushreference.go @@ -0,0 +1,74 @@ +// Copyright 2021 The PipeCD Authors. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +package image + +import ( + "context" + "fmt" + + "github.com/spf13/cobra" + + "github.com/pipe-cd/pipe/pkg/app/api/service/apiservice" + "github.com/pipe-cd/pipe/pkg/cli" +) + +type pushReference struct { + root *command + + repoName string + tags []string + digest string +} + +func newPushReferenceCommand(root *command) *cobra.Command { + c := &pushReference{ + root: root, + } + cmd := &cobra.Command{ + Use: "push-reference", + Short: "Push a container image reference.", + RunE: cli.WithContext(c.run), + } + + cmd.Flags().StringVar(&c.repoName, "repo-name", c.repoName, "The repository name of container image. e.g. gcr.io/pipecd/pipecd, envoyproxy/envoy-alpine...") + cmd.Flags().StringSliceVar(&c.tags, "tag", c.tags, "The image tag; Can be used multiple times to set multiple tags.") + cmd.Flags().StringVar(&c.digest, "digest", c.digest, "The image digest.") + + cmd.MarkFlagRequired("repo-name") + cmd.MarkFlagRequired("tag") + + return cmd +} + +func (c *pushReference) run(ctx context.Context, t cli.Telemetry) error { + cli, err := c.root.clientOptions.NewClient(ctx) + if err != nil { + return fmt.Errorf("failed to initialize client: %w", err) + } + defer cli.Close() + + req := &apiservice.PushImageReferenceRequest{ + RepoName: c.repoName, + Tags: c.tags, + Digest: c.digest, + } + + if _, err := cli.PushImageReference(ctx, req); err != nil { + return fmt.Errorf("failed to push image reference: %w", err) + } + + t.Logger.Info("Successfully pushed image reference") + return nil +} diff --git a/pkg/app/piped/cloudprovider/lambda/BUILD.bazel b/pkg/app/piped/cloudprovider/lambda/BUILD.bazel index 0f5c166e54..8f34ca3fe4 100644 --- a/pkg/app/piped/cloudprovider/lambda/BUILD.bazel +++ b/pkg/app/piped/cloudprovider/lambda/BUILD.bazel @@ -4,14 +4,13 @@ go_library( name = "go_default_library", srcs = [ "client.go", - "lambda.go", "function.go", + "lambda.go", ], importpath = "github.com/pipe-cd/pipe/pkg/app/piped/cloudprovider/lambda", visibility = ["//visibility:public"], deps = [ "//pkg/config:go_default_library", - "@io_k8s_sigs_yaml//:go_default_library", "@com_github_aws_aws_sdk_go//aws:go_default_library", "@com_github_aws_aws_sdk_go//aws/awserr:go_default_library", "@com_github_aws_aws_sdk_go//aws/credentials:go_default_library", @@ -19,6 +18,7 @@ go_library( "@com_github_aws_aws_sdk_go//aws/ec2metadata:go_default_library", "@com_github_aws_aws_sdk_go//aws/session:go_default_library", "@com_github_aws_aws_sdk_go//service/lambda:go_default_library", + "@io_k8s_sigs_yaml//:go_default_library", "@org_golang_x_sync//singleflight:go_default_library", "@org_uber_go_zap//:go_default_library", ],