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

Fix skaffold credits #3436

Merged
merged 3 commits into from
Jan 3, 2020
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
3 changes: 1 addition & 2 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -16,5 +16,4 @@ docs/node_modules
docs/themes
docs/package-lock.json
pkg/skaffold/color/debug.test
cmd/skaffold/app/cmd/credits/statik
cmd/skaffold/app/cmd/schema/statik
cmd/skaffold/app/cmd/statik/statik.go
8 changes: 5 additions & 3 deletions cmd/skaffold/app/cmd/credits/export.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,19 +26,21 @@ import (

"github.com/pkg/errors"
"github.com/rakyll/statik/fs"

"github.com/GoogleContainerTools/skaffold/cmd/skaffold/app/cmd/statik"
)

var Path string

// Export writes all the licenses and credit files to the `Path` folder.
func Export(out io.Writer) error {
statikFS, err := statikFS()
statikFS, err := statik.FS()
if err != nil {
return errors.Wrap(err, "opening embedded filesystem")
}

if err := fs.Walk(statikFS, "/", func(filePath string, fileInfo os.FileInfo, err error) error {
newPath := path.Join(Path, filePath)
if err := fs.Walk(statikFS, "/skaffold-credits", func(filePath string, fileInfo os.FileInfo, err error) error {
newPath := path.Join(Path, "..", filePath)
if fileInfo.IsDir() {
err := os.Mkdir(newPath, 0755)
if err != nil && !os.IsExist(err) {
Expand Down
28 changes: 0 additions & 28 deletions cmd/skaffold/app/cmd/credits/fs.go

This file was deleted.

28 changes: 0 additions & 28 deletions cmd/skaffold/app/cmd/credits/fs_dummy.go

This file was deleted.

28 changes: 0 additions & 28 deletions cmd/skaffold/app/cmd/schema/fs_dummy.go

This file was deleted.

11 changes: 7 additions & 4 deletions cmd/skaffold/app/cmd/schema/print.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,25 +18,28 @@ package schema

import (
"io"
"path"
"strings"

"github.com/pkg/errors"
"github.com/rakyll/statik/fs"

"github.com/GoogleContainerTools/skaffold/cmd/skaffold/app/cmd/statik"
)

// Print prints the json schema for a given version.
func Print(out io.Writer, version string) error {
statikFS, err := statikFS()
statikFS, err := statik.FS()
if err != nil {
return err
}

path := "/" + strings.TrimPrefix(version, "skaffold/") + ".json"
path := path.Join("/schemas", strings.TrimPrefix(version, "skaffold/")+".json")
content, err := fs.ReadFile(statikFS, path)
if err != nil {
return errors.Wrapf(err, "schema %q not found", version)
}

out.Write(content)
return nil
_, err = out.Write(content)
return err
}
7 changes: 4 additions & 3 deletions cmd/skaffold/app/cmd/schema/print_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import (
"os"
"testing"

"github.com/GoogleContainerTools/skaffold/cmd/skaffold/app/cmd/statik"
"github.com/GoogleContainerTools/skaffold/testutil"
)

Expand Down Expand Up @@ -57,12 +58,12 @@ func (f *fakeFile) Close() error {
func TestPrint(t *testing.T) {
fs := &fakeFileSystem{
Files: map[string][]byte{
"/v1.json": []byte("{SCHEMA}"),
"/schemas/v1.json": []byte("{SCHEMA}"),
},
}

testutil.Run(t, "found", func(t *testutil.T) {
t.Override(&statikFS, func() (http.FileSystem, error) { return fs, nil })
t.Override(&statik.FS, func() (http.FileSystem, error) { return fs, nil })

var out bytes.Buffer
err := Print(&out, "skaffold/v1")
Expand All @@ -72,7 +73,7 @@ func TestPrint(t *testing.T) {
})

testutil.Run(t, "not found", func(t *testutil.T) {
t.Override(&statikFS, func() (http.FileSystem, error) { return fs, nil })
t.Override(&statik.FS, func() (http.FileSystem, error) { return fs, nil })

var out bytes.Buffer
err := Print(&out, "skaffold/v0")
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
// +build release

/*
Copyright 2019 The Skaffold Authors

Expand All @@ -16,13 +14,11 @@ See the License for the specific language governing permissions and
limitations under the License.
*/

package schema
package statik

import (
"github.com/rakyll/statik/fs"
import "github.com/rakyll/statik/fs"

//required for rakyll/statik embedded content
_ "github.com/GoogleContainerTools/skaffold/cmd/skaffold/app/cmd/schema/statik"
// For testing
var (
FS = fs.New
)

var statikFS = fs.New
6 changes: 4 additions & 2 deletions hack/gen_statik.sh
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,10 @@ if ! [[ -f ${LICENSES} ]]; then
fi

TMP_DIR=$(mktemp -d)
trap "rm -rf $TMP_DIR" EXIT

${LICENSES} save "github.com/GoogleContainerTools/skaffold/cmd/skaffold" --save_path="${TMP_DIR}/skaffold-credits"
cp -R docs/content/en/schemas "${TMP_DIR}/schemas"

if ! [[ -f ${STATIK} ]]; then
pushd ${DIR}/tools
Expand All @@ -41,5 +44,4 @@ if ! [[ -f ${STATIK} ]]; then
popd
fi

${STATIK} -f -src=${TMP_DIR}/skaffold-credits/ -m -dest cmd/skaffold/app/cmd/credits
${STATIK} -f -src=docs/content/en/schemas -m -dest cmd/skaffold/app/cmd/schema
${STATIK} -f -src=${TMP_DIR} -m -dest cmd/skaffold/app/cmd
43 changes: 43 additions & 0 deletions integration/credits_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
/*
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 integration

import (
"io/ioutil"
"testing"

"github.com/GoogleContainerTools/skaffold/integration/skaffold"
"github.com/GoogleContainerTools/skaffold/testutil"
)

func TestCredits(t *testing.T) {
if testing.Short() || RunOnGCP() {
t.Skip("skipping kind integration test")
}

testutil.Run(t, "credits", func(t *testutil.T) {
tmpDir := t.NewTempDir().Chdir()

out, err := skaffold.Credits().RunWithCombinedOutput(t.T)
t.CheckNoError(err)
t.CheckContains("Successfully exported third party notices", string(out))

content, err := ioutil.ReadFile(tmpDir.Path("skaffold-credits/github.com/docker/docker/LICENSE"))
t.CheckNoError(err)
t.CheckContains("Apache License", string(content))
})
}
42 changes: 42 additions & 0 deletions integration/schema_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
/*
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 integration

import (
"testing"

"github.com/GoogleContainerTools/skaffold/integration/skaffold"
"github.com/GoogleContainerTools/skaffold/testutil"
)

func TestSchema(t *testing.T) {
if testing.Short() || RunOnGCP() {
t.Skip("skipping kind integration test")
}

testutil.Run(t, "list", func(t *testutil.T) {
out := skaffold.Schema("list").RunOrFailOutput(t.T)

t.CheckContains("skaffold/v1", string(out))
})

testutil.Run(t, "get", func(t *testutil.T) {
out := skaffold.Schema("get", "skaffold/v1").RunOrFailOutput(t.T)

t.CheckContains("#/definitions/SkaffoldConfig", string(out))
})
}
10 changes: 10 additions & 0 deletions integration/skaffold/helper.go
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,16 @@ func Diagnose(args ...string) *RunBuilder {
return &RunBuilder{command: "diagnose", args: args}
}

// Schema runs `skaffold schema` with the given arguments.
func Schema(args ...string) *RunBuilder {
return &RunBuilder{command: "schema", args: args}
}

// Credits runs `skaffold credits` with the given arguments.
func Credits(args ...string) *RunBuilder {
return &RunBuilder{command: "credits", args: args}
}

func GeneratePipeline(args ...string) *RunBuilder {
return &RunBuilder{command: "generate-pipeline", args: args}
}
Expand Down