This is an automated email from the ASF dual-hosted git repository. kezhenxu94 pushed a commit to branch docker in repository https://gitbox.apache.org/repos/asf/skywalking-eyes.git
commit a23a0a762a2f614d1d7500c9d2bb8149cbcfb97e Author: kezhenxu94 <[email protected]> AuthorDate: Sat Feb 8 20:54:55 2025 +0800 Bump up to go 1.23 and clean up Docker images --- .github/workflows/license-eye-check.yaml | 4 ++-- .golangci.yml | 18 +++++++----------- Dockerfile | 10 +--------- Makefile | 2 +- README.md | 12 ++++++++++++ action.yml | 4 ++-- commands/deps_check.go | 2 +- commands/deps_resolve.go | 14 ++++++++------ commands/header_check.go | 2 +- commands/header_fix.go | 2 +- commands/root.go | 2 +- dependency/action.yml | 4 ++-- examples/golang/Dockerfile | 15 +++++++++++++++ examples/java/Dockerfile | 12 ++++++++++++ examples/nodejs/Dockerfile | 9 +++++++++ go.mod | 2 +- header/action.yml | 4 ++-- pkg/deps/jar.go | 8 +++++++- pkg/deps/maven.go | 3 +-- pkg/header/check.go | 2 +- 20 files changed, 87 insertions(+), 44 deletions(-) diff --git a/.github/workflows/license-eye-check.yaml b/.github/workflows/license-eye-check.yaml index 72da41b..d7edee1 100644 --- a/.github/workflows/license-eye-check.yaml +++ b/.github/workflows/license-eye-check.yaml @@ -28,11 +28,11 @@ jobs: name: Build LicenseEye runs-on: ubuntu-latest steps: - - uses: actions/checkout@v2 + - uses: actions/checkout@v4 - uses: actions/setup-go@v5 with: - go-version: 1.18 + go-version: 1.23 - name: Lint Codes run: make lint diff --git a/.golangci.yml b/.golangci.yml index e5d7259..05aea22 100644 --- a/.golangci.yml +++ b/.golangci.yml @@ -33,10 +33,11 @@ linters-settings: min-len: 2 min-occurrences: 2 depguard: - list-type: blacklist - include-go-root: true - packages-with-error-messages: - fmt: "logging is allowed only by logutils.Log" + rules: + main: + deny: + - pkg: "fmt" + desc: "logging is allowed only by logutils.Log" misspell: locale: US ignore-words: @@ -94,11 +95,9 @@ linters-settings: linters: enable: - bodyclose - - deadcode - - depguard + - errcheck - dogsled - dupl - - errcheck - funlen - goconst - gocritic @@ -114,16 +113,13 @@ linters: - misspell - nakedret - staticcheck - - structcheck - - stylecheck - typecheck - unconvert - unparam - unused - - varcheck - whitespace service: - golangci-lint-version: 1.20.x + golangci-lint-version: 1.54.x prepare: - echo "here I can run custom commands, but no preparation needed for this repo" diff --git a/Dockerfile b/Dockerfile index 917ebb8..88e76e8 100644 --- a/Dockerfile +++ b/Dockerfile @@ -15,9 +15,7 @@ # specific language governing permissions and limitations # under the License. -# TODO: minimize the docker image size, now 524MB !!! - -FROM golang:1.18-alpine AS build +FROM golang:1.23-alpine AS build WORKDIR /license-eye @@ -29,12 +27,6 @@ FROM alpine:3 AS bin COPY --from=build /license-eye/bin/linux/license-eye /bin/license-eye -# Go -COPY --from=build /usr/local/go/bin/go /usr/local/go/bin/go -ENV PATH="/usr/local/go/bin:$PATH" -RUN apk add --no-cache bash gcc musl-dev npm cargo -# Go - WORKDIR /github/workspace/ ENTRYPOINT ["/bin/license-eye"] diff --git a/Makefile b/Makefile index eecfd7e..1bf1b60 100644 --- a/Makefile +++ b/Makefile @@ -74,7 +74,7 @@ build: windows linux darwin .PHONY: docker docker: - docker build . -t $(HUB)/$(PROJECT):$(VERSION) -t $(HUB)/$(PROJECT):latest + docker build --no-cache . -t $(HUB)/$(PROJECT):$(VERSION) -t $(HUB)/$(PROJECT):latest .PHONY: docker-push docker-push: diff --git a/README.md b/README.md index 8c67305..af6bd3d 100644 --- a/README.md +++ b/README.md @@ -109,6 +109,18 @@ docker run -it --rm -v $(pwd):/github/workspace apache/skywalking-eyes header ch docker run -it --rm -v $(pwd):/github/workspace apache/skywalking-eyes header fix ``` +#### Using Docker for License Dependency Checks + +To check dependencies' licenses in Docker, you'll need the appropriate language runtime and package managers in your environment. The base Docker image only includes the license-eye binary. To check dependencies, you can build a custom Docker image with your required language tools: + +```dockerfile +FROM apache/skywalking-eyes:latest + +# Install the tools you need +``` + +See the [examples directory](examples/) for more detailed examples and Dockerfiles for different languages. + ### Docker Image from the latest codes For users and developers who want to help to test the latest codes on main branch, we publish a Docker image to the GitHub diff --git a/action.yml b/action.yml index cb54c26..b2fadeb 100644 --- a/action.yml +++ b/action.yml @@ -44,10 +44,10 @@ inputs: runs: using: "composite" steps: - - name: Set up Go 1.18 + - name: Set up Go uses: actions/setup-go@v5 with: - go-version: 1.18 + go-version: 1.23 cache-dependency-path: ${{ github.action_path }}/go.sum - shell: bash run: make -C $GITHUB_ACTION_PATH install diff --git a/commands/deps_check.go b/commands/deps_check.go index 87aab07..934aa37 100644 --- a/commands/deps_check.go +++ b/commands/deps_check.go @@ -39,7 +39,7 @@ var DepsCheckCommand = &cobra.Command{ Use: "check", Aliases: []string{"c"}, Long: "resolves and check license compatibility in all dependencies of a module and their transitive dependencies", - RunE: func(cmd *cobra.Command, args []string) error { + RunE: func(_ *cobra.Command, _ []string) error { var errors []error configDeps := Config.Dependencies() for _, header := range Config.Headers() { diff --git a/commands/deps_resolve.go b/commands/deps_resolve.go index 2a5e8fe..51322b1 100644 --- a/commands/deps_resolve.go +++ b/commands/deps_resolve.go @@ -33,10 +33,12 @@ import ( "github.com/apache/skywalking-eyes/pkg/deps" ) -var outDir string -var licensePath string -var summaryTplPath string -var summaryTpl *template.Template +var ( + outDir string + licensePath string + summaryTplPath string + summaryTpl *template.Template +) func init() { DepsResolveCommand.PersistentFlags().StringVarP(&outDir, "output", "o", "", @@ -54,7 +56,7 @@ var DepsResolveCommand = &cobra.Command{ Use: "resolve", Aliases: []string{"r"}, Long: "resolves all dependencies of a module and their transitive dependencies", - PreRunE: func(cmd *cobra.Command, args []string) error { + PreRunE: func(_ *cobra.Command, _ []string) error { if outDir != "" { absPath, err := filepath.Abs(outDir) if err != nil { @@ -97,7 +99,7 @@ var DepsResolveCommand = &cobra.Command{ } return nil }, - RunE: func(cmd *cobra.Command, args []string) error { + RunE: func(_ *cobra.Command, _ []string) error { report := deps.Report{} configDeps := Config.Dependencies() diff --git a/commands/header_check.go b/commands/header_check.go index 19644ad..c1aefca 100644 --- a/commands/header_check.go +++ b/commands/header_check.go @@ -32,7 +32,7 @@ var CheckCommand = &cobra.Command{ Use: "check", Aliases: []string{"c"}, Long: "check command walks the specified paths recursively and checks if the specified files have the license header in the config file.", - RunE: func(cmd *cobra.Command, args []string) error { + RunE: func(_ *cobra.Command, args []string) error { hasErrors := false for _, h := range Config.Headers() { var result header.Result diff --git a/commands/header_fix.go b/commands/header_fix.go index 1e35889..ed5a7cb 100644 --- a/commands/header_fix.go +++ b/commands/header_fix.go @@ -31,7 +31,7 @@ var FixCommand = &cobra.Command{ Use: "fix", Aliases: []string{"f"}, Long: "fix command walks the specified paths recursively and fix the license header if the specified files don't have the license header.", - RunE: func(cmd *cobra.Command, args []string) error { + RunE: func(_ *cobra.Command, args []string) error { var errors []string for _, h := range Config.Headers() { var result header.Result diff --git a/commands/root.go b/commands/root.go index 6f74a91..1371894 100644 --- a/commands/root.go +++ b/commands/root.go @@ -37,7 +37,7 @@ var root = &cobra.Command{ Long: "A full-featured license guard to check and fix license headers and dependencies' licenses", SilenceUsage: true, SilenceErrors: true, - PersistentPreRunE: func(cmd *cobra.Command, args []string) error { + PersistentPreRunE: func(_ *cobra.Command, _ []string) error { level, err := logrus.ParseLevel(verbosity) if err != nil { return err diff --git a/dependency/action.yml b/dependency/action.yml index 82f6458..e9a87f1 100644 --- a/dependency/action.yml +++ b/dependency/action.yml @@ -42,10 +42,10 @@ inputs: runs: using: "composite" steps: - - name: Set up Go 1.18 + - name: Set up Go uses: actions/setup-go@v5 with: - go-version: 1.18 + go-version: 1.23 cache-dependency-path: ${{ github.action_path }}/go.sum - shell: bash run: make -C $GITHUB_ACTION_PATH/.. install diff --git a/examples/golang/Dockerfile b/examples/golang/Dockerfile new file mode 100644 index 0000000..2316a70 --- /dev/null +++ b/examples/golang/Dockerfile @@ -0,0 +1,15 @@ +FROM apache/skywalking-eyes:latest + +ARG GO_VERSION=1.23.1 +ARG TARGETARCH + +# Install Go +RUN wget https://golang.org/dl/go${GO_VERSION}.linux-${TARGETARCH}.tar.gz \ + && tar -C /usr/local -xzf go${GO_VERSION}.linux-${TARGETARCH}.tar.gz \ + && rm go${GO_VERSION}.linux-${TARGETARCH}.tar.gz + +ENV PATH=$PATH:/usr/local/go/bin +ENV GOPATH=/go +ENV PATH=$PATH:$GOPATH/bin + +WORKDIR /github/workspace diff --git a/examples/java/Dockerfile b/examples/java/Dockerfile new file mode 100644 index 0000000..016aa23 --- /dev/null +++ b/examples/java/Dockerfile @@ -0,0 +1,12 @@ +FROM apache/skywalking-eyes:latest + +ARG JAVA_VERSION=17 +ARG TARGETARCH + +# Install OpenJDK +RUN apk add --no-cache --update openjdk${JAVA_VERSION}-jdk + +ENV JAVA_HOME=/usr/lib/jvm/java-${JAVA_VERSION}-openjdk-${TARGETARCH} +ENV PATH=$PATH:$JAVA_HOME/bin + +WORKDIR /github/workspace diff --git a/examples/nodejs/Dockerfile b/examples/nodejs/Dockerfile new file mode 100644 index 0000000..cdc2766 --- /dev/null +++ b/examples/nodejs/Dockerfile @@ -0,0 +1,9 @@ +FROM apache/skywalking-eyes:latest + +ARG NODE_VERSION=22.13.1 +ARG TARGETARCH + +# Install Node.js +RUN apk add --no-cache --update nodejs=${NODE_VERSION}-r0 npm + +WORKDIR /github/workspace diff --git a/go.mod b/go.mod index 2ddce06..356b3b3 100644 --- a/go.mod +++ b/go.mod @@ -1,6 +1,6 @@ module github.com/apache/skywalking-eyes -go 1.18 +go 1.23 require ( github.com/Masterminds/sprig/v3 v3.2.3 diff --git a/header/action.yml b/header/action.yml index 513e67f..8ef7e17 100644 --- a/header/action.yml +++ b/header/action.yml @@ -44,10 +44,10 @@ inputs: runs: using: "composite" steps: - - name: Set up Go 1.18 + - name: Set up Go uses: actions/setup-go@v5 with: - go-version: 1.18 + go-version: 1.23 cache-dependency-path: ${{ github.action_path }}/go.sum - shell: bash run: make -C $GITHUB_ACTION_PATH/.. install diff --git a/pkg/deps/jar.go b/pkg/deps/jar.go index 0ef1eda..cd93624 100644 --- a/pkg/deps/jar.go +++ b/pkg/deps/jar.go @@ -23,6 +23,7 @@ import ( "bytes" "fmt" "io" + "math" "path/filepath" "regexp" "strings" @@ -126,7 +127,12 @@ func (resolver *JarResolver) ReadFileFromZip(archiveFile *zip.File) (*bytes.Buff buf := bytes.NewBuffer(nil) w := bufio.NewWriter(buf) - _, err = io.CopyN(w, file, int64(archiveFile.UncompressedSize64)) + + size := archiveFile.UncompressedSize64 + if size > math.MaxInt64 { + return nil, fmt.Errorf("file too large: size %d exceeds maximum supported size", size) + } + _, err = io.CopyN(w, file, int64(size)) if err != nil { return nil, err } diff --git a/pkg/deps/maven.go b/pkg/deps/maven.go index 4c223f1..946e1f3 100644 --- a/pkg/deps/maven.go +++ b/pkg/deps/maven.go @@ -21,7 +21,6 @@ import ( "encoding/xml" "fmt" "io" - "io/ioutil" "os" "os/exec" "path/filepath" @@ -125,7 +124,7 @@ func (resolver *MavenPomResolver) ResolveDeps() error { } func (resolver *MavenPomResolver) LoadDependencies(config *ConfigDeps) ([]*Dependency, error) { - depsFile, err := ioutil.TempFile(os.TempDir(), "maven-dependencies.txt") + depsFile, err := os.CreateTemp(os.TempDir(), "maven-dependencies.txt") if err != nil { return nil, err } diff --git a/pkg/header/check.go b/pkg/header/check.go index e930001..4ac1f8f 100644 --- a/pkg/header/check.go +++ b/pkg/header/check.go @@ -142,7 +142,7 @@ func walkFile(file string, seen map[string]bool) ([]string, error) { case mode.IsRegular(): files = append(files, file) case mode.IsDir(): - err := filepath.Walk(file, func(path string, info fs.FileInfo, err error) error { + err := filepath.Walk(file, func(path string, info fs.FileInfo, _ error) error { if path == file { // when path is symbolic link file, it causes infinite recursive calls return nil
