Skip to content

Commit

Permalink
Merge pull request #325 from buildpacks-community/Issue-249-local-sou…
Browse files Browse the repository at this point in the history
…rce-image

[Issue #249] Adds `local-path-destination-image` flag
  • Loading branch information
chenbh authored Aug 8, 2023
2 parents a4e591a + 8aae4ba commit f5cac04
Show file tree
Hide file tree
Showing 9 changed files with 179 additions and 157 deletions.
4 changes: 2 additions & 2 deletions cmd/docs/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
package main

import (
"io/ioutil"
"io"
"log"
"os"

Expand All @@ -14,7 +14,7 @@ import (
)

func main() {
log.SetOutput(ioutil.Discard)
log.SetOutput(io.Discard)

cmd := rootcommand.GetRootCommand()

Expand Down
4 changes: 2 additions & 2 deletions cmd/kp/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,15 @@
package main

import (
"io/ioutil"
"io"
"log"
"os"

"github.com/vmware-tanzu/kpack-cli/pkg/rootcommand"
)

func main() {
log.SetOutput(ioutil.Discard)
log.SetOutput(io.Discard)

cmd := rootcommand.GetRootCommand()
err := cmd.Execute()
Expand Down
61 changes: 32 additions & 29 deletions docs/kp_image_create.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ The flags for this command determine how the build will retrieve source code:
"--local-path" to use source code from the local machine

Local source code will be pushed to the same registry provided for the image resource tag.
--local-path-destination-image can be used to specify the repository of the source code image.
If not specified, the source code image will be pushed to the <image-tag-repo>-source repo.
Therefore, you must have credentials to access the registry on your machine.
--registry-ca-cert-path and --registry-verify-certs are only used for local source type.

Expand Down Expand Up @@ -47,35 +49,36 @@ kp image create my-image --tag my-registry.com/my-repo --blob https://my-blob-ho
### Options

```
--additional-tag stringArray additional tags to push the OCI image to
--blob string source code blob url
-b, --builder string builder name
--cache-size string cache size as a kubernetes quantity (default "2G")
-c, --cluster-builder string cluster builder name
--dry-run perform validation with no side-effects; no objects are sent to the server.
The --dry-run flag can be used in combination with the --output flag to
view the Kubernetes resource(s) without sending anything to the server.
--dry-run-with-image-upload similar to --dry-run, but with container image uploads allowed.
This flag is provided as a convenience for kp commands that can output Kubernetes
resource with generated container image references. A "kubectl apply -f" of the
resource from --output without image uploads will result in a reconcile failure.
-e, --env stringArray build time environment variables
--git string git repository url
--git-revision string git revision such as commit, tag, or branch (default "main")
-h, --help help for create
--local-path string path to local source code
-n, --namespace string kubernetes namespace
--output string print Kubernetes resources in the specified format; supported formats are: yaml, json.
The output can be used with the "kubectl apply -f" command. To allow this, the command
updates are redirected to stderr and only the Kubernetes resource(s) are written to stdout.
The APIVersion of the outputted resources will always be the latest APIVersion known to kp (currently: v1alpha2).
--registry-ca-cert-path string add CA certificate for registry API (format: /tmp/ca.crt)
--registry-verify-certs set whether to verify server's certificate chain and host name (default true)
--service-account string service account name to use (default "default")
-s, --service-binding stringArray build time service bindings
--sub-path string build code at the sub path located within the source code directory
-t, --tag string registry location where the OCI image will be created
-w, --wait wait for image create to be reconciled and tail resulting build logs
--additional-tag stringArray additional tags to push the OCI image to
--blob string source code blob url
-b, --builder string builder name
--cache-size string cache size as a kubernetes quantity (default "2G")
-c, --cluster-builder string cluster builder name
--dry-run perform validation with no side-effects; no objects are sent to the server.
The --dry-run flag can be used in combination with the --output flag to
view the Kubernetes resource(s) without sending anything to the server.
--dry-run-with-image-upload similar to --dry-run, but with container image uploads allowed.
This flag is provided as a convenience for kp commands that can output Kubernetes
resource with generated container image references. A "kubectl apply -f" of the
resource from --output without image uploads will result in a reconcile failure.
-e, --env stringArray build time environment variables
--git string git repository url
--git-revision string git revision such as commit, tag, or branch (default "main")
-h, --help help for create
--local-path string path to local source code
--local-path-destination-image string registry location of where the local source code will be uploaded to (default "<image-tag-repo>-source")
-n, --namespace string kubernetes namespace
--output string print Kubernetes resources in the specified format; supported formats are: yaml, json.
The output can be used with the "kubectl apply -f" command. To allow this, the command
updates are redirected to stderr and only the Kubernetes resource(s) are written to stdout.
The APIVersion of the outputted resources will always be the latest APIVersion known to kp (currently: v1alpha2).
--registry-ca-cert-path string add CA certificate for registry API (format: /tmp/ca.crt)
--registry-verify-certs set whether to verify server's certificate chain and host name (default true)
--service-account string service account name to use (default "default")
-s, --service-binding stringArray build time service bindings
--sub-path string build code at the sub path located within the source code directory
-t, --tag string registry location where the OCI image will be created
-w, --wait wait for image create to be reconciled and tail resulting build logs
```

### SEE ALSO
Expand Down
67 changes: 35 additions & 32 deletions docs/kp_image_save.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ The flags for this command determine how the build will retrieve source code:
"--local-path" to use source code from the local machine

Local source code will be pushed to the same registry provided for the image resource tag.
--local-path-destination-image can be used to specify the repository of the source code image.
If not specified, the source code image will be pushed to the <image-tag-repo>-source repo.
Therefore, you must have credentials to access the registry on your machine.

Environment variables may be provided by using the "--env" flag or deleted by using the "--delete-env" flag.
Expand Down Expand Up @@ -50,38 +52,39 @@ kp image save my-image --tag my-registry.com/my-repo --blob https://my-blob-host
### Options

```
--additional-tag stringArray additional tags to push the OCI image to
--blob string source code blob url
-b, --builder string builder name
--cache-size string cache size as a kubernetes quantity (default "2G")
-c, --cluster-builder string cluster builder name
--delete-additional-tag stringArray additional tags to remove
-d, --delete-env stringArray build time environment variables to remove
--delete-service-binding stringArray build time service bindings to remove
--dry-run perform validation with no side-effects; no objects are sent to the server.
The --dry-run flag can be used in combination with the --output flag to
view the Kubernetes resource(s) without sending anything to the server.
--dry-run-with-image-upload similar to --dry-run, but with container image uploads allowed.
This flag is provided as a convenience for kp commands that can output Kubernetes
resource with generated container image references. A "kubectl apply -f" of the
resource from --output without image uploads will result in a reconcile failure.
-e, --env stringArray build time environment variables
--git string git repository url
--git-revision string git revision such as commit, tag, or branch (default "main")
-h, --help help for save
--local-path string path to local source code
-n, --namespace string kubernetes namespace
--output string print Kubernetes resources in the specified format; supported formats are: yaml, json.
The output can be used with the "kubectl apply -f" command. To allow this, the command
updates are redirected to stderr and only the Kubernetes resource(s) are written to stdout.
The APIVersion of the outputted resources will always be the latest APIVersion known to kp (currently: v1alpha2).
--registry-ca-cert-path string add CA certificate for registry API (format: /tmp/ca.crt)
--registry-verify-certs set whether to verify server's certificate chain and host name (default true)
--service-account string service account name to use
-s, --service-binding stringArray build time service bindings to add/replace
--sub-path string build code at the sub path located within the source code directory
-t, --tag string registry location where the image will be created
-w, --wait wait for image create to be reconciled and tail resulting build logs
--additional-tag stringArray additional tags to push the OCI image to
--blob string source code blob url
-b, --builder string builder name
--cache-size string cache size as a kubernetes quantity (default "2G")
-c, --cluster-builder string cluster builder name
--delete-additional-tag stringArray additional tags to remove
-d, --delete-env stringArray build time environment variables to remove
--delete-service-binding stringArray build time service bindings to remove
--dry-run perform validation with no side-effects; no objects are sent to the server.
The --dry-run flag can be used in combination with the --output flag to
view the Kubernetes resource(s) without sending anything to the server.
--dry-run-with-image-upload similar to --dry-run, but with container image uploads allowed.
This flag is provided as a convenience for kp commands that can output Kubernetes
resource with generated container image references. A "kubectl apply -f" of the
resource from --output without image uploads will result in a reconcile failure.
-e, --env stringArray build time environment variables
--git string git repository url
--git-revision string git revision such as commit, tag, or branch (default "main")
-h, --help help for save
--local-path string path to local source code
--local-path-destination-image string registry location of where the local source code will be uploaded to (default "<image-tag-repo>-source")
-n, --namespace string kubernetes namespace
--output string print Kubernetes resources in the specified format; supported formats are: yaml, json.
The output can be used with the "kubectl apply -f" command. To allow this, the command
updates are redirected to stderr and only the Kubernetes resource(s) are written to stdout.
The APIVersion of the outputted resources will always be the latest APIVersion known to kp (currently: v1alpha2).
--registry-ca-cert-path string add CA certificate for registry API (format: /tmp/ca.crt)
--registry-verify-certs set whether to verify server's certificate chain and host name (default true)
--service-account string service account name to use
-s, --service-binding stringArray build time service bindings to add/replace
--sub-path string build code at the sub path located within the source code directory
-t, --tag string registry location where the image will be created
-w, --wait wait for image create to be reconciled and tail resulting build logs
```

### SEE ALSO
Expand Down
3 changes: 3 additions & 0 deletions pkg/commands/image/create.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,8 @@ The flags for this command determine how the build will retrieve source code:
"--local-path" to use source code from the local machine
Local source code will be pushed to the same registry provided for the image resource tag.
--local-path-destination-image can be used to specify the repository of the source code image.
If not specified, the source code image will be pushed to the <image-tag-repo>-source repo.
Therefore, you must have credentials to access the registry on your machine.
--registry-ca-cert-path and --registry-verify-certs are only used for local source type.
Expand Down Expand Up @@ -99,6 +101,7 @@ kp image create my-image --tag my-registry.com/my-repo --blob https://my-blob-ho
cmd.Flags().StringVar(&factory.GitRevision, "git-revision", "", "git revision such as commit, tag, or branch (default \"main\")")
cmd.Flags().StringVar(&factory.Blob, "blob", "", "source code blob url")
cmd.Flags().StringVar(&factory.LocalPath, "local-path", "", "path to local source code")
cmd.Flags().StringVar(&factory.LocalPathDestinationImage, "local-path-destination-image", "", "registry location of where the local source code will be uploaded to (default \"<image-tag-repo>-source\")")
cmd.Flags().StringVar(&subPath, "sub-path", "", "build code at the sub path located within the source code directory")
cmd.Flags().StringVarP(&factory.Builder, "builder", "b", "", "builder name")
cmd.Flags().StringVarP(&factory.ClusterBuilder, "cluster-builder", "c", "", "cluster builder name")
Expand Down
134 changes: 65 additions & 69 deletions pkg/commands/image/create_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -371,6 +371,71 @@ Image Resource "some-image" created
},
}.TestKpack(t, cmdFunc)

assert.Len(t, fakeImageWaiter.Calls, 0)
})
it("sets the repository source path on the image", func() {
expectedImage := &v1alpha2.Image{
TypeMeta: metav1.TypeMeta{
Kind: "Image",
APIVersion: "kpack.io/v1alpha2",
},
ObjectMeta: metav1.ObjectMeta{
Name: "some-image",
Namespace: defaultNamespace,
Annotations: map[string]string{},
},
Spec: v1alpha2.ImageSpec{
Tag: "some-registry.io/some-repo",
Builder: corev1.ObjectReference{
Kind: v1alpha2.ClusterBuilderKind,
Name: "default",
},
ServiceAccountName: "default",
Source: corev1alpha1.SourceConfig{
Registry: &corev1alpha1.Registry{
Image: "some-registry.io/some-repo-testing:source-id",
},
SubPath: "some-sub-path",
},
Build: &v1alpha2.ImageBuild{
Env: []corev1.EnvVar{
{
Name: "some-key",
Value: "some-val",
},
},
Services: v1alpha2.Services{
{
APIVersion: "v1",
Kind: "SomeResource",
Name: "some-binding",
},
},
},
},
}
require.NoError(t, setLastAppliedAnnotation(expectedImage))

testhelpers.CommandTest{
Args: []string{
"some-image",
"--tag", "some-registry.io/some-repo",
"--local-path", "some-local-path",
"--local-path-destination-image", "some-registry.io/some-repo-testing",
"--sub-path", "some-sub-path",
"--env", "some-key=some-val",
"--service-binding", "SomeResource:v1:some-binding",
},
ExpectedOutput: `Creating Image Resource...
Uploading to 'some-registry.io/some-repo-testing'...
Uploading 'some-registry.io/some-repo-testing:source-id'
Image Resource "some-image" created
`,
ExpectCreates: []runtime.Object{
expectedImage,
},
}.TestKpack(t, cmdFunc)

assert.Len(t, fakeImageWaiter.Calls, 0)
})
})
Expand Down Expand Up @@ -900,74 +965,5 @@ status: {}
})
})
})

when("cache size is not provided", func() {
it("does not set an empty field on the image", func() {
//note: this is to allow for defaults to be set by kpack webhook

expectedImage := &v1alpha2.Image{
TypeMeta: metav1.TypeMeta{
Kind: "Image",
APIVersion: "kpack.io/v1alpha2",
},
ObjectMeta: metav1.ObjectMeta{
Name: "some-image",
Namespace: defaultNamespace,
Annotations: map[string]string{},
},
Spec: v1alpha2.ImageSpec{
Tag: "some-registry.io/some-repo",
Builder: corev1.ObjectReference{
Kind: v1alpha2.ClusterBuilderKind,
Name: "default",
},
ServiceAccountName: "default",
Source: corev1alpha1.SourceConfig{
Git: &corev1alpha1.Git{
URL: "some-git-url",
Revision: "some-git-rev",
},
SubPath: "some-sub-path",
},
Build: &v1alpha2.ImageBuild{
Env: []corev1.EnvVar{
{
Name: "some-key",
Value: "some-val",
},
},
Services: v1alpha2.Services{
{
APIVersion: "v1",
Kind: "SomeResource",
Name: "some-binding",
},
},
},
},
}

require.NoError(t, setLastAppliedAnnotation(expectedImage))
testhelpers.CommandTest{
Args: []string{
"some-image",
"--tag", "some-registry.io/some-repo",
"--git", "some-git-url",
"--git-revision", "some-git-rev",
"--sub-path", "some-sub-path",
"--env", "some-key=some-val",
"--service-binding", "SomeResource:v1:some-binding",
},
ExpectedOutput: `Creating Image Resource...
Image Resource "some-image" created
`,
ExpectCreates: []runtime.Object{
expectedImage,
},
}.TestKpack(t, cmdFunc)

assert.Len(t, fakeImageWaiter.Calls, 0)
})
})
}
}
Loading

0 comments on commit f5cac04

Please sign in to comment.