Skip to content

Commit

Permalink
Fix skaffold credits
Browse files Browse the repository at this point in the history
Generate a single statik.go file that embeds
both credits and schemas.

Fixes #3428
  • Loading branch information
dgageot committed Dec 24, 2019
1 parent a11a36c commit efff827
Show file tree
Hide file tree
Showing 9 changed files with 26 additions and 107 deletions.
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

0 comments on commit efff827

Please sign in to comment.