Skip to content

Commit

Permalink
generating licenses and retrieving them via skaffold credits
Browse files Browse the repository at this point in the history
  • Loading branch information
balopat committed Oct 30, 2019
1 parent a83e30e commit 578780c
Show file tree
Hide file tree
Showing 88 changed files with 3,453 additions and 393 deletions.
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
10 changes: 7 additions & 3 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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 @@ -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", ".", "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")
}
86 changes: 86 additions & 0 deletions cmd/skaffold/app/cmd/credits_release.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
// +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)
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
}
size := int(fileInfo.Size())
buf := make([]byte, size)
n, err := file.Read(buf)
if err != nil {
log.Fatalf("error reading %s in embedded filesystem: %s", filePath, err)
return err
}
if n < size {
log.Fatalf("failed to read %d bytes, only read %d", n, size)
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='.': 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
13 changes: 6 additions & 7 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ require (
github.com/google/go-containerregistry v0.0.0-20191017210159-68bc585818ee
github.com/google/go-github v17.0.0+incompatible
github.com/google/go-querystring v1.0.0 // indirect
github.com/google/trillian v1.3.2-0.20191028154214-c93851d711b5 // indirect
github.com/google/uuid v1.1.1
github.com/grpc-ecosystem/grpc-gateway v1.11.3
github.com/hinshun/vt10x v0.0.0-20180809195222-d55458df857c // indirect
Expand All @@ -59,14 +60,14 @@ require (
github.com/krishicks/yaml-patch v0.0.10
github.com/markbates/inflect v1.0.4 // indirect
github.com/mattbaird/jsonpatch v0.0.0-20171005235357-81af80346b1a // indirect
github.com/mattn/go-colorable v0.1.2 // indirect
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.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 @@ -75,15 +76,13 @@ require (
github.com/spf13/pflag v1.0.5
github.com/tektoncd/pipeline v0.5.1-0.20190731183258-9d7e37e85bf8
go.opencensus.io v0.22.1 // indirect
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

0 comments on commit 578780c

Please sign in to comment.