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

skaffold credits #3138

Merged
merged 8 commits into from
Oct 31, 2019
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
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -16,3 +16,4 @@ docs/node_modules
docs/themes
docs/package-lock.json
pkg/skaffold/color/debug.test
cmd/skaffold/app/cmd/credits
18 changes: 11 additions & 7 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -50,9 +50,9 @@ LDFLAGS_linux = -static
LDFLAGS_darwin =
LDFLAGS_windows =

GO_BUILD_TAGS_linux := "osusergo netgo static_build"
GO_BUILD_TAGS_darwin := ""
GO_BUILD_TAGS_windows := ""
GO_BUILD_TAGS_linux := "osusergo netgo static_build release"
GO_BUILD_TAGS_darwin := "release"
GO_BUILD_TAGS_windows := "release"

GO_LDFLAGS = -X $(VERSION_PACKAGE).version=$(VERSION)
GO_LDFLAGS += -X $(VERSION_PACKAGE).buildDate=$(shell date +'%Y-%m-%dT%H:%M:%SZ')
Expand All @@ -69,7 +69,7 @@ GO_FILES := $(shell find . -type f -name '*.go' -not -path "./vendor/*")
$(BUILD_DIR)/$(PROJECT): $(BUILD_DIR)/$(PROJECT)-$(GOOS)-$(GOARCH)
cp $(BUILD_DIR)/$(PROJECT)-$(GOOS)-$(GOARCH) $@

$(BUILD_DIR)/$(PROJECT)-$(GOOS)-$(GOARCH): $(GO_FILES) $(BUILD_DIR)
$(BUILD_DIR)/$(PROJECT)-$(GOOS)-$(GOARCH): generate-licenses $(GO_FILES) $(BUILD_DIR)
GOOS=$(GOOS) GOARCH=$(GOARCH) CGO_ENABLED=1 go build -tags $(GO_BUILD_TAGS_$(GOOS)) -ldflags $(GO_LDFLAGS_$(GOOS)) -gcflags $(GO_GCFLAGS) -asmflags $(GO_ASMFLAGS) -o $@ $(BUILD_PACKAGE)

$(BUILD_DIR)/$(PROJECT)-%-$(GOARCH): $(GO_FILES) $(BUILD_DIR)
Expand All @@ -96,7 +96,7 @@ $(BUILD_DIR):
.PRECIOUS: $(foreach platform, $(SUPPORTED_PLATFORMS), $(BUILD_DIR)/$(PROJECT)-$(platform))

.PHONY: cross
cross: $(foreach platform, $(SUPPORTED_PLATFORMS), $(BUILD_DIR)/$(PROJECT)-$(platform).sha256)
cross: generate-licenses $(foreach platform, $(SUPPORTED_PLATFORMS), $(BUILD_DIR)/$(PROJECT)-$(platform).sha256)

.PHONY: test
test: $(BUILD_DIR)
Expand All @@ -117,7 +117,7 @@ quicktest:
go test -short -timeout=60s ./...

.PHONY: install
install: $(GO_FILES) $(BUILD_DIR)
install: generate-licenses $(GO_FILES) $(BUILD_DIR)
GOOS=$(GOOS) GOARCH=$(GOARCH) CGO_ENABLED=1 go install -tags $(GO_BUILD_TAGS_$(GOOS)) -ldflags $(GO_LDFLAGS_$(GOOS)) -gcflags $(GO_GCFLAGS) -asmflags $(GO_ASMFLAGS) $(BUILD_PACKAGE)

.PHONY: integration
Expand Down Expand Up @@ -179,7 +179,7 @@ release-build-in-docker:

.PHONY: clean
clean:
rm -rf $(BUILD_DIR)
rm -rf $(BUILD_DIR) hack/bin

.PHONY: kind-cluster
kind-cluster:
Expand Down Expand Up @@ -247,3 +247,7 @@ build-docs-preview:
.PHONY: generate-schemas
generate-schemas:
go run hack/schemas/main.go

.PHONY: generate-licenses
generate-licenses:
hack/gen_licenses.sh
1 change: 1 addition & 0 deletions cmd/skaffold/app/cmd/cmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,7 @@ func NewSkaffoldCommand(out, err io.Writer) *cobra.Command {
rootCmd.AddCommand(NewCmdFindConfigs())
rootCmd.AddCommand(NewCmdDiagnose())
rootCmd.AddCommand(NewCmdOptions())
rootCmd.AddCommand(NewCmdCredits())

rootCmd.AddCommand(NewCmdGeneratePipeline())

Expand Down
34 changes: 34 additions & 0 deletions cmd/skaffold/app/cmd/credits.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
/*
Copyright 2019 The Skaffold 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 cmd

import (
"github.com/spf13/cobra"
"github.com/spf13/pflag"
)

var creditsPath string

func NewCmdCredits() *cobra.Command {
return NewCmd("credits").
WithDescription("Export third party notices to given path (./skaffold-credits by default)").
WithExample("export third party licenses to ~/skaffold-credits", "credits -d ~/skaffold-credits").
WithFlags(func(f *pflag.FlagSet) {
f.StringVarP(&creditsPath, "dir", "d", "./skaffold-credits", "destination directory to place third party licenses")
}).
NoArgs(exportCredits)
}
31 changes: 31 additions & 0 deletions cmd/skaffold/app/cmd/credits_dummy.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
// +build !release

/*
Copyright 2019 The Skaffold 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 cmd

import (
"errors"
"io"
)

// exportCredits with !release build tag is just here for compilation purposes
// this file does not depend on the generated statik.go file that is not checked
// in by default to git
func exportCredits(out io.Writer) error {
return errors.New("not implemented, skaffold should be built with make ('release' build tag)")
}
79 changes: 79 additions & 0 deletions cmd/skaffold/app/cmd/credits_release.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
// +build release

/*
Copyright 2019 The Skaffold 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 cmd

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

"github.com/rakyll/statik/fs"

//required for rakyll/statik embedded content
_ "github.com/GoogleContainerTools/skaffold/cmd/skaffold/app/cmd/credits/statik"
)

func exportCredits(out io.Writer) error {
statikFS, err := fs.New()
if err != nil {
log.Fatalf("error opening embedded filesystem: %s", err)
balopat marked this conversation as resolved.
Show resolved Hide resolved
return err
}
err = fs.Walk(statikFS, "/", func(filePath string, fileInfo os.FileInfo, err error) error {
newPath := path.Join(creditsPath, filePath)
if fileInfo.IsDir() {
err := os.Mkdir(newPath, 0755)
if err != nil && !os.IsExist(err) {
log.Fatalf("error creating directory %s: %s", newPath, err)
return err
}
}
if !fileInfo.IsDir() {
file, err := statikFS.Open(filePath)
if err != nil {
log.Fatalf("error opening %s in embedded filesystem: %s", filePath, err)
return err
}
buf, err := ioutil.ReadAll(file)
if err != nil {
log.Fatalf("error reading %s in embedded filesystem: %s", filePath, err)
return err
}
err = ioutil.WriteFile(newPath, buf, 0664)
if err != nil {
log.Fatalf("error writing %s to %s: %s", filePath, newPath, err)
return err
}
}
return nil
})
if err != nil {
log.Fatal(err)
return err
}
s, err := filepath.Abs(creditsPath)
if err != nil {
log.Printf("Successfully exported third party notices to %s", creditsPath)
}
log.Printf("Successfully exported third party notices to %s", s)
return nil
}
26 changes: 26 additions & 0 deletions docs/content/en/docs/references/cli/_index.md
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@ Getting started with a new project:
Other Commands:
completion Output shell completion for the given shell (bash or zsh)
config Interact with the Skaffold configuration
credits Export third party notices to given path (./skaffold-credits by default)
diagnose Run a diagnostic on Skaffold
version Print the version information

Expand Down Expand Up @@ -282,6 +283,31 @@ Env vars:
* `SKAFFOLD_GLOBAL` (same as `--global`)
* `SKAFFOLD_KUBE_CONTEXT` (same as `--kube-context`)

### skaffold credits

Export third party notices to given path (./skaffold-credits by default)

```


Examples:
# export third party licenses to ~/skaffold-credits
skaffold credits -d ~/skaffold-credits

Options:
-d, --dir='./skaffold-credits': destination directory to place third party licenses

Usage:
skaffold credits [options]

Use "skaffold options" for a list of global command-line options (applies to all commands).


```
Env vars:

* `SKAFFOLD_DIR` (same as `--dir`)

### skaffold debug

Run a pipeline in debug mode
Expand Down
10 changes: 6 additions & 4 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -63,10 +63,11 @@ require (
github.com/mattn/go-isatty v0.0.9 // indirect
github.com/mitchellh/go-homedir v1.1.0
github.com/moby/buildkit v0.6.2
github.com/opencontainers/go-digest v1.0.0-rc1
github.com/opencontainers/go-digest v1.0.0-rc1.0.20190228220655-ac19fd6e7483
github.com/opencontainers/image-spec v1.0.1
github.com/pkg/errors v0.8.1
github.com/prometheus/procfs v0.0.4 // indirect
github.com/rakyll/statik v0.1.6
github.com/rjeczalik/notify v0.9.2
github.com/segmentio/textio v1.2.0
github.com/shurcooL/sanitized_anchor_name v1.0.0 // indirect
Expand All @@ -78,12 +79,13 @@ require (
go.uber.org/atomic v1.4.0 // indirect
go.uber.org/multierr v1.1.0 // indirect
go.uber.org/zap v1.10.0 // indirect
golang.org/x/crypto v0.0.0-20191011191535-87dc89f01550
golang.org/x/crypto v0.0.0-20191028145041-f83a4685e152
golang.org/x/exp v0.0.0-20191014171548-69215a2ee97e // indirect
golang.org/x/net v0.0.0-20191014212845-da9a3fd4c582 // indirect
golang.org/x/net v0.0.0-20191028085509-fe3aa8a45271 // indirect
golang.org/x/oauth2 v0.0.0-20190604053449-0f29369cfe45
golang.org/x/sync v0.0.0-20190911185100-cd5d95a43a6e
golang.org/x/tools v0.0.0-20191018000036-341939e08647 // indirect
golang.org/x/sys v0.0.0-20191028164358-195ce5e7f934 // indirect
golang.org/x/tools v0.0.0-20191028215554-80f3f9ca0853 // indirect
google.golang.org/api v0.11.0
google.golang.org/appengine v1.6.5 // indirect
google.golang.org/genproto v0.0.0-20191009194640-548a555dbc03
Expand Down
Loading