From 94029bfeeabaf723e23786afc2bdc29a0a9d4e8b Mon Sep 17 00:00:00 2001 From: denverdino Date: Mon, 22 Jul 2024 18:19:07 +0800 Subject: [PATCH 1/2] Upgrade the ants goroutine pool to v2 Signed-off-by: denverdino --- go.mod | 3 ++- go.sum | 12 ++++++++++-- pkg/client/client.go | 6 +++--- 3 files changed, 15 insertions(+), 6 deletions(-) diff --git a/go.mod b/go.mod index c7f6896..e02f4c6 100644 --- a/go.mod +++ b/go.mod @@ -8,7 +8,7 @@ require ( github.com/fatih/color v1.16.0 github.com/opencontainers/go-digest v1.0.0 github.com/opencontainers/image-spec v1.1.0-rc5 - github.com/panjf2000/ants v1.3.0 + github.com/panjf2000/ants/v2 v2.10.0 github.com/sirupsen/logrus v1.9.3 github.com/spf13/cobra v1.8.0 github.com/stretchr/testify v1.8.4 @@ -54,6 +54,7 @@ require ( github.com/ulikunitz/xz v0.5.11 // indirect github.com/vbatts/tar-split v0.11.5 // indirect golang.org/x/exp v0.0.0-20231206192017-f3f8817b8deb // indirect + golang.org/x/sync v0.7.0 // indirect golang.org/x/sys v0.15.0 // indirect google.golang.org/appengine v1.6.8 // indirect google.golang.org/protobuf v1.31.0 // indirect diff --git a/go.sum b/go.sum index 8e7925a..e58a170 100644 --- a/go.sum +++ b/go.sum @@ -80,8 +80,8 @@ github.com/opencontainers/runc v1.1.10 h1:EaL5WeO9lv9wmS6SASjszOeQdSctvpbu0DdBQB github.com/opencontainers/runc v1.1.10/go.mod h1:+/R6+KmDlh+hOO8NkjmgkG9Qzvypzk0yXxAPYYR65+M= github.com/opencontainers/runtime-spec v1.1.0 h1:HHUyrt9mwHUjtasSbXSMvs4cyFxh+Bll4AjJ9odEGpg= github.com/opencontainers/runtime-spec v1.1.0/go.mod h1:jwyrGlmzljRJv/Fgzds9SsS/C5hL+LL3ko9hs6T5lQ0= -github.com/panjf2000/ants v1.3.0 h1:8pQ+8leaLc9lys2viEEr8md0U4RN6uOSUCE9bOYjQ9M= -github.com/panjf2000/ants v1.3.0/go.mod h1:AaACblRPzq35m1g3enqYcxspbbiOJJYaxU2wMpm1cXY= +github.com/panjf2000/ants/v2 v2.10.0 h1:zhRg1pQUtkyRiOFo2Sbqwjp0GfBNo9cUY2/Grpx1p+8= +github.com/panjf2000/ants/v2 v2.10.0/go.mod h1:7ZxyxsqE4vvW0M7LSD8aI3cKwgFhBHbxnlN8mDqHa1I= github.com/pkg/errors v0.9.1 h1:FEBLx1zS214owpjy7qsBeixbURkuhQAwrK5UwLGTwt4= github.com/pkg/errors v0.9.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0= github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM= @@ -98,8 +98,13 @@ github.com/spf13/cobra v1.8.0/go.mod h1:WXLWApfZ71AjXPya3WOlMsY9yMs7YeiHhFVlvLyh github.com/spf13/pflag v1.0.5 h1:iy+VFUOCP1a+8yFto/drg2CJ5u0yRoB7fZw3DKv/JXA= github.com/spf13/pflag v1.0.5/go.mod h1:McXfInJRrz4CZXVZOBLb0bTZqETkiAhM9Iw0y3An2Bg= github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= +github.com/stretchr/objx v0.4.0/go.mod h1:YvHI0jy2hoMjB+UWwv71VJQ9isScKT/TqJzVSSt89Yw= +github.com/stretchr/objx v0.5.0/go.mod h1:Yh+to48EsGEfYuaHDzXPcE3xhTkx73EhmCGUpEOglKo= github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI= github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg= +github.com/stretchr/testify v1.7.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg= +github.com/stretchr/testify v1.8.0/go.mod h1:yNjHg4UonilssWZ8iaSj1OCr/vHnekPRkoO+kdMU+MU= +github.com/stretchr/testify v1.8.2/go.mod h1:w2LPCIKwWwSfY2zedu0+kehJoqGctiVI29o6fzry7u4= github.com/stretchr/testify v1.8.4 h1:CcVxjf3Q8PM0mHUKJCdn+eZZtm5yQwehR5yeSVQQcUk= github.com/stretchr/testify v1.8.4/go.mod h1:sz/lmYIOXD/1dqDmKjjqLyZ2RngseejIcXlSw2iwfAo= github.com/syndtr/gocapability v0.0.0-20200815063812-42c35b437635 h1:kdXcSzyDtseVEc4yCz2qF8ZrQvIDBJLl4S1c3GCXmoI= @@ -128,6 +133,9 @@ golang.org/x/oauth2 v0.15.0 h1:s8pnnxNVzjWyrvYdFUQq5llS1PX2zhPXmccZv99h7uQ= golang.org/x/oauth2 v0.15.0/go.mod h1:q48ptWNTY5XWf+JNten23lcvHpLJ0ZSxF5ttTHKVCAM= golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= golang.org/x/sync v0.0.0-20220722155255-886fb9371eb4/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= +golang.org/x/sync v0.3.0/go.mod h1:FU7BRWz2tNW+3quACPkgCx/L+uEAv1htQ0V83Z9Rj+Y= +golang.org/x/sync v0.7.0 h1:YsImfSBoP9QPYL0xyKJPq0gcaJdG3rInoqxTWbfQu9M= +golang.org/x/sync v0.7.0/go.mod h1:Czt+wKu1gCyEFDUtn0jG5QVvpJ6rzVqr5aXyt9drQfk= golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= golang.org/x/sys v0.0.0-20201119102817-f84b799fce68/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20210615035016-665e8c7367d1/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= diff --git a/pkg/client/client.go b/pkg/client/client.go index 0d95157..e7cc2b2 100644 --- a/pkg/client/client.go +++ b/pkg/client/client.go @@ -7,7 +7,7 @@ import ( "time" "github.com/fatih/color" - "github.com/panjf2000/ants" + "github.com/panjf2000/ants/v2" "github.com/sirupsen/logrus" "gopkg.in/yaml.v2" @@ -138,7 +138,7 @@ func (c *Client) Run() error { defer routinePool.Release() if err = c.handleTasks(routinePool); err != nil { - return fmt.Errorf("failed to handle tasks: %v", err) + c.logger.Errorf("Failed to handle tasks: %v", err) } for times := 0; times < c.retries; times++ { @@ -153,7 +153,7 @@ func (c *Client) Run() error { // retry to handle task c.logger.Infof("Start to retry tasks, please wait ...") if err = c.handleTasks(routinePool); err != nil { - return fmt.Errorf("failed to handle tasks: %v", err) + c.logger.Errorf("Failed to handle tasks: %v", err) } } } From f6cc3592427f87ccbfd2c7874728b6ee08a75094 Mon Sep 17 00:00:00 2001 From: denverdino Date: Mon, 22 Jul 2024 21:09:56 +0800 Subject: [PATCH 2/2] Refine the docker build --- .DockerIgnore | 6 ++++++ .github/workflows/release.yml | 2 +- Dockerfile | 5 +++-- Dockerfile.arm64 | 13 ------------- 4 files changed, 10 insertions(+), 16 deletions(-) create mode 100644 .DockerIgnore delete mode 100644 Dockerfile.arm64 diff --git a/.DockerIgnore b/.DockerIgnore new file mode 100644 index 0000000..d12ef0c --- /dev/null +++ b/.DockerIgnore @@ -0,0 +1,6 @@ +*.md +*.yaml +*.json +.git/ +.github/ +images-syncer \ No newline at end of file diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 85166e9..60db50c 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -14,7 +14,7 @@ jobs: goarch: [amd64, arm64] steps: - uses: actions/checkout@v2 - - uses: wangyoucao577/go-release-action@v1.38 + - uses: wangyoucao577/go-release-action@v1.51 with: github_token: ${{ secrets.GITHUB_TOKEN }} goos: ${{ matrix.goos }} diff --git a/Dockerfile b/Dockerfile index ea540db..a9bf98e 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,7 +1,8 @@ -FROM golang:1.12.7 as builder +FROM golang:1.22.5 as builder WORKDIR /go/src/github.com/AliyunContainerService/image-syncer COPY ./ ./ -RUN CGO_ENABLED=0 GOOS=linux GOARCH=amd64 make +ENV GOPROXY=https://proxy.golang.com.cn,direct +RUN CGO_ENABLED=0 GOOS=linux make FROM alpine:latest WORKDIR /bin/ diff --git a/Dockerfile.arm64 b/Dockerfile.arm64 deleted file mode 100644 index 237d21f..0000000 --- a/Dockerfile.arm64 +++ /dev/null @@ -1,13 +0,0 @@ -FROM golang:1.12.7 as builder -WORKDIR /go/src/github.com/AliyunContainerService/image-syncer -COPY ./ ./ -RUN CGO_ENABLED=0 GOOS=linux GOARCH=arm64 make - -FROM arm64v8/alpine:latest -WORKDIR /bin/ -COPY --from=builder /go/src/github.com/AliyunContainerService/image-syncer/image-syncer ./ -RUN chmod +x ./image-syncer -RUN apk add -U --no-cache ca-certificates && rm -rf /var/cache/apk/* && mkdir -p /etc/ssl/certs \ - && update-ca-certificates --fresh -ENTRYPOINT ["image-syncer"] -CMD ["--config", "/etc/image-syncer/image-syncer.json"]