diff --git a/.github/workflows/build.yaml b/.github/workflows/build.yaml deleted file mode 100644 index b341406..0000000 --- a/.github/workflows/build.yaml +++ /dev/null @@ -1,21 +0,0 @@ -name: Build -on: - pull_request: - push: - branches: [ "main", "release/v*" ] - tags: - - 'v*' -jobs: - build: - runs-on: ubuntu-latest - steps: - - name: Checkout code - uses: actions/checkout@v4 - - name: Install Go - uses: actions/setup-go@v5 - with: - go-version: 1.22.x - - name: Build - run: | - go test -v -count=1 -cover ./... - ./scripts/build.sh diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml new file mode 100644 index 0000000..4fb41a5 --- /dev/null +++ b/.github/workflows/ci.yaml @@ -0,0 +1,46 @@ +name: CI +on: + pull_request: + push: + branches: + - main + - release/* +jobs: + ci: + runs-on: ubuntu-latest + steps: + - name: Checkout code + uses: actions/checkout@v4 + - name: Install Go + uses: actions/setup-go@v5 + with: + go-version: 1.22.x + - name: Setup QEMU + uses: docker/setup-qemu-action@v3 + - name: Setup Docker Buildx + uses: docker/setup-buildx-action@v3 + - name: Lint + uses: golangci/golangci-lint-action@v6 + with: + version: v1.61 + - name: Verify + run: | + make verify + - name: Test + run: | + make test + - name: Build + env: + TAG: ${{ github.ref_name }} + COMMIT: ${{ github.sha }} + uses: goreleaser/goreleaser-action@v6 + with: + distribution: goreleaser + version: "~> v2" + args: build --clean --snapshot + - name: Image Build + run: | + make image + env: + TAG: dev + REPO: cnrancher diff --git a/.github/workflows/lint.yaml b/.github/workflows/lint.yaml deleted file mode 100644 index 277d5d7..0000000 --- a/.github/workflows/lint.yaml +++ /dev/null @@ -1,21 +0,0 @@ -name: Lint -on: - pull_request: - push: - branches: [ "main", "release/v*" ] - tags: - - 'v*' -jobs: - lint: - runs-on: ubuntu-latest - steps: - - name: Checkout code - uses: actions/checkout@v4 - - name: Install Go - uses: actions/setup-go@v5 - with: - go-version: 1.22.x - - name: Analysis - uses: golangci/golangci-lint-action@a4f60bb28d35aeee14e6880718e0c85ff1882e64 # v6.0.1 - with: - args: -v diff --git a/.github/workflows/release.yaml b/.github/workflows/release.yaml new file mode 100644 index 0000000..770c4a3 --- /dev/null +++ b/.github/workflows/release.yaml @@ -0,0 +1,69 @@ +name: Release + +on: + push: + tags: + - 'v*' +jobs: + release: + permissions: + contents: write # required for creating GH release + id-token: write # required for reading vault secrets + runs-on: ubuntu-latest + steps: + - name: Login to DockerHub + uses: docker/login-action@v3 + with: + registry: ${{ vars.PUBLIC_REGISTRY }} + username: ${{ secrets.DOCKERHUB_USERNAME }} + password: ${{ secrets.DOCKERHUB_TOKEN }} + - name: Setup QEMU + uses: docker/setup-qemu-action@v3 + - name: Setup Docker Buildx + uses: docker/setup-buildx-action@v3 + - name: Checkout code + uses: actions/checkout@v4 + with: + fetch-depth: 0 + ref: ${{ github.ref_name}} + - name: Install Go + uses: actions/setup-go@v5 + with: + go-version: 1.22.x + - name: Lint + uses: golangci/golangci-lint-action@v6 + with: + version: v1.61 + - name: Verify + run: | + make verify + - name: Test + run: | + make test + - name: Go Release + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} # required for creating GH release + TAG: ${{ github.ref_name }} + COMMIT: ${{ github.sha }} + uses: goreleaser/goreleaser-action@v6 + with: + distribution: goreleaser + version: "~> v2" + args: release --clean --verbose + - name: Image Push + run: | + make image-push + env: + TAG: ${{ github.ref_name }} + REPO: ${{ vars.PUBLIC_REGISTRY }}/${{ secrets.DOCKERHUB_USERNAME }} + - name: Upload Charts + env: + TAG: ${{ github.ref_name }} + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} # required for updating GH release + run: | + make chart + for f in $(find dist/artifacts/ -name '*.tgz'); do + echo "Uploading $f to GitHub release $TAG" + gh release upload $TAG $f + done + echo "Charts successfully uploaded to GitHub release $TAG" diff --git a/.gitignore b/.gitignore index 76a7c3e..94c066c 100644 --- a/.gitignore +++ b/.gitignore @@ -30,6 +30,7 @@ go.work # Build files /bin/ +/build/ /dist/ /cce-operator diff --git a/.goreleaser.yaml b/.goreleaser.yaml new file mode 100644 index 0000000..3729da0 --- /dev/null +++ b/.goreleaser.yaml @@ -0,0 +1,51 @@ +# This is an example .goreleaser.yml file with some sensible defaults. +# Make sure to check the documentation at https://goreleaser.com + +# The lines below are called `modelines`. See `:help modeline` +# Feel free to remove those if you don't want/need to use them. +# yaml-language-server: $schema=https://goreleaser.com/static/schema.json +# vim: set ts=2 sw=2 tw=0 fo=cnqoj + +version: 2 + +before: + hooks: + - go mod tidy + +builds: +- env: + - CGO_ENABLED=0 + goos: + - linux + goarch: + - amd64 + - arm64 + ldflags: + - -extldflags -static + - -s -w + - -X github.com/cnrancher/cce-operator/pkg/utils.GitCommit={{.Env.COMMIT}} + - -X github.com/cnrancher/cce-operator/pkg/utils.Version={{.Env.TAG}} + main: ./main.go + id: cce-operator + binary: cce-operator + +release: + prerelease: auto + +archives: + - format: tar.gz + # this name template makes the OS and Arch compatible with the results of `uname`. + name_template: >- + {{ .ProjectName }}_ + {{- title .Os }}_ + {{- if eq .Arch "amd64" }}x86_64 + {{- else if eq .Arch "386" }}i386 + {{- else }}{{ .Arch }}{{ end }} + {{- if .Arm }}v{{ .Arm }}{{ end }} + +changelog: + sort: asc + filters: + exclude: + - "^docs:" + - "^test:" diff --git a/Dockerfile.dapper b/Dockerfile.dapper deleted file mode 100644 index 6dc5535..0000000 --- a/Dockerfile.dapper +++ /dev/null @@ -1,29 +0,0 @@ -FROM registry.suse.com/bci/golang:1.22 - -ARG DAPPER_HOST_ARCH -ENV ARCH ${DAPPER_HOST_ARCH} - -RUN zypper ref && \ - zypper -n up && \ - zypper -n in vim wget git tar gzip && \ - zypper clean - -RUN curl -sL https://get.helm.sh/helm-v3.3.0-linux-${ARCH}.tar.gz | \ - tar xvzf - -C /usr/local/bin --strip-components=1 - -RUN if [ "${ARCH}" = "amd64" ]; then \ - curl -sL https://install.goreleaser.com/github.com/golangci/golangci-lint.sh | sh -s v1.59.0; \ -fi - -ENV DAPPER_ENV REPO TAG DRONE_TAG CROSS -ENV DAPPER_SOURCE /go/src/github.com/cnrancher/cce-operator/ -ENV DAPPER_OUTPUT ./bin ./dist -ENV DAPPER_DOCKER_SOCKET true -WORKDIR ${DAPPER_SOURCE} - -# pre-copy/cache go.mod for pre-downloading dependencies -COPY go.mod go.sum ./ -RUN go env -w GOPROXY=https://goproxy.cn,direct && go mod download && go mod verify - -ENTRYPOINT ["./scripts/entry.sh"] -CMD ["ci"] diff --git a/Makefile b/Makefile index 382fce9..24c21f3 100755 --- a/Makefile +++ b/Makefile @@ -1,24 +1,49 @@ -SCRIPTS := build test ci validate -.PHONY: $(SCRIPTS) clean generate help +TAG?=$(shell git describe --abbrev=0 --tags 2>/dev/null || echo "v0.0.0" ) +COMMIT?=$(shell git rev-parse HEAD) -.dapper: - @echo Downloading dapper - @curl -sL https://releases.rancher.com/dapper/latest/dapper-`uname -s`-`uname -m` > .dapper.tmp - @chmod +x .dapper.tmp - @./.dapper.tmp -v - @mv .dapper.tmp .dapper +default: build -$(SCRIPTS): .dapper - @./.dapper $@ +.PHONY: generate +generate: + @go generate + +.PHONY: build +build: + COMMIT=$(COMMIT) TAG=$(TAG) goreleaser build --snapshot --clean +.PHONY: test +test: + CGO_ENABLED=0 go test -cover --count=1 ./... + +.PHONY: clean clean: - @./scripts/clean.sh + ./scripts/clean.sh -generate: - @go generate ./main.go +.PHONY: verify +verify: + ./scripts/verify.sh + +.PHONY: chart +chart: + TAG=$(TAG) ./scripts/chart.sh + +.PHONY: image +image: + TAG=$(TAG) ./scripts/image.sh + +.PHONY: image-push +image-push: + TAG=$(TAG) BUILDX_OPTIONS="--push" ./scripts/image.sh +.PHONY: help help: @echo "Usage:" - @echo " make build - Build executable files in 'bin' folder" - @echo " make test - Run unit test" - @echo " make generate - Generate codes & CRDs" + @echo " make build build binary files" + @echo " make test run unit tests" + @echo " make generate run code generator" + @echo " make verify verify modules" + @echo " make chart package helm charts" + @echo " make image build container images" + @echo " make image-push build container images and push" + @echo " make clean clean up built files" + @echo " make help show this message" diff --git a/go.mod b/go.mod index e2837bc..cec6697 100644 --- a/go.mod +++ b/go.mod @@ -7,9 +7,9 @@ toolchain go1.22.3 require ( github.com/Masterminds/semver/v3 v3.2.1 github.com/antonfisher/nested-logrus-formatter v1.3.1 - github.com/huaweicloud/huaweicloud-sdk-go-v3 v0.1.104 - github.com/rancher/lasso v0.0.0-20240603075835-701e919d08b7 - github.com/rancher/wrangler/v3 v3.0.0-rc2 + github.com/huaweicloud/huaweicloud-sdk-go-v3 v0.1.118 + github.com/rancher/lasso v0.0.0-20240705194423-b2a060d103c1 + github.com/rancher/wrangler/v3 v3.0.0 github.com/sirupsen/logrus v1.9.3 github.com/stretchr/testify v1.9.0 k8s.io/api v0.30.1 @@ -51,14 +51,14 @@ require ( github.com/spf13/pflag v1.0.5 // indirect github.com/tjfoc/gmsm v1.4.1 // indirect go.mongodb.org/mongo-driver v1.12.0 // indirect - golang.org/x/crypto v0.22.0 // indirect + golang.org/x/crypto v0.23.0 // indirect golang.org/x/mod v0.17.0 // indirect golang.org/x/net v0.24.0 // indirect golang.org/x/oauth2 v0.16.0 // indirect golang.org/x/sync v0.7.0 // indirect - golang.org/x/sys v0.19.0 // indirect - golang.org/x/term v0.19.0 // indirect - golang.org/x/text v0.14.0 // indirect + golang.org/x/sys v0.20.0 // indirect + golang.org/x/term v0.20.0 // indirect + golang.org/x/text v0.15.0 // indirect golang.org/x/time v0.3.0 // indirect golang.org/x/tools v0.20.0 // indirect google.golang.org/appengine v1.6.7 // indirect diff --git a/go.sum b/go.sum index 6223150..1b2ba17 100644 --- a/go.sum +++ b/go.sum @@ -89,8 +89,8 @@ github.com/google/uuid v1.6.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+ github.com/grpc-ecosystem/grpc-gateway v1.16.0 h1:gmcG1KaJ57LophUzW0Hy8NmPhnMZb4M0+kPpLofRdBo= github.com/grpc-ecosystem/grpc-gateway/v2 v2.16.0 h1:YBftPWNWd4WwGqtY2yeZL2ef8rHAxPBD8KFhJpmcqms= github.com/grpc-ecosystem/grpc-gateway/v2 v2.16.0/go.mod h1:YN5jB8ie0yfIUg6VvR9Kz84aCaG7AsGZnLjhHbUqwPg= -github.com/huaweicloud/huaweicloud-sdk-go-v3 v0.1.104 h1:mCjW876Kx+y7LYxvbXVUxacN42AH2EJe715iZyPP1Fk= -github.com/huaweicloud/huaweicloud-sdk-go-v3 v0.1.104/go.mod h1:lhdEO9Bbb3hZ0wG+JeK9/GqMOp/sgc92mFmVk5tNSCk= +github.com/huaweicloud/huaweicloud-sdk-go-v3 v0.1.118 h1:YHcixaT7Le4PxuxN07KQ5j9nPeH4ZdyXtMTSgA+Whh8= +github.com/huaweicloud/huaweicloud-sdk-go-v3 v0.1.118/go.mod h1:JWz2ujO9X3oU5wb6kXp+DpR2UuDj2SldDbX8T0FSuhI= github.com/imdario/mergo v0.3.12 h1:b6R2BslTbIEToALKP7LxUvijTsNI9TAe80pLWN2g/HU= github.com/imdario/mergo v0.3.12/go.mod h1:jmQim1M+e3UYxmgPu/WyfjB3N3VflVyUjjjwH0dnCYA= github.com/josharian/intern v1.0.0 h1:vlS4z54oSdjm0bgjRigI+G1HpF+tI+9rE5LLzOg8HmY= @@ -137,10 +137,10 @@ github.com/prometheus/common v0.44.0 h1:+5BrQJwiBB9xsMygAB3TNvpQKOwlkc25LbISbrdO github.com/prometheus/common v0.44.0/go.mod h1:ofAIvZbQ1e/nugmZGz4/qCb9Ap1VoSTIO7x0VV9VvuY= github.com/prometheus/procfs v0.10.1 h1:kYK1Va/YMlutzCGazswoHKo//tZVlFpKYh+PymziUAg= github.com/prometheus/procfs v0.10.1/go.mod h1:nwNm2aOCAYw8uTR/9bWRREkZFxAUcWzPHWJq+XBB/FM= -github.com/rancher/lasso v0.0.0-20240603075835-701e919d08b7 h1:E5AeOkylBXf4APhnHgDvePdtpxOfIjhKnxfjm4sDIEk= -github.com/rancher/lasso v0.0.0-20240603075835-701e919d08b7/go.mod h1:v0FJLrmL4m6zdWfIB0/qo7qN5QIjVMFyvFGaw8uyWsA= -github.com/rancher/wrangler/v3 v3.0.0-rc2 h1:XGSPPp6GXELqlLvwJp5MsdqyCPu6SCA4UKJ7rQJzE40= -github.com/rancher/wrangler/v3 v3.0.0-rc2/go.mod h1:f54hh7gFkwwbjsieT2b63FowzTU8FvrBonPe//0CIXo= +github.com/rancher/lasso v0.0.0-20240705194423-b2a060d103c1 h1:vv1jDlYbd4KhGbPNxmjs8CYgEHUrQm2bMtmULfXJ6iw= +github.com/rancher/lasso v0.0.0-20240705194423-b2a060d103c1/go.mod h1:A/y3BLQkxZXYD60MNDRwAG9WGxXfvd6Z6gWR/a8wPw8= +github.com/rancher/wrangler/v3 v3.0.0 h1:IHHCA+vrghJDPxjtLk4fmeSCFhNe9fFzLFj3m2B0YpA= +github.com/rancher/wrangler/v3 v3.0.0/go.mod h1:Dfckuuq7MJk2JWVBDywRlZXMxEyPxHy4XqGrPEzu5Eg= github.com/rogpeppe/go-internal v1.11.0 h1:cWPaGQEPrBb5/AsnsZesgZZ9yb1OQ+GOISoDNXVBh4M= github.com/rogpeppe/go-internal v1.11.0/go.mod h1:ddIwULY96R17DhadqLgMfk9H9tvdUzkipdSkR5nkCZA= github.com/sirupsen/logrus v1.9.3 h1:dueUQJ1C2q9oE3F7wvmSGAaVtTmUizReu6fjN8uqzbQ= @@ -194,9 +194,8 @@ golang.org/x/crypto v0.0.0-20201012173705-84dcc777aaee/go.mod h1:LzIPMQfyMNhhGPh golang.org/x/crypto v0.0.0-20210921155107-089bfa567519/go.mod h1:GvvjBRRGRdwPK5ydBHafDWAxML/pGHZbMvKqRZ5+Abc= golang.org/x/crypto v0.0.0-20220622213112-05595931fe9d/go.mod h1:IxCIyHEi3zRg3s0A5j5BB6A9Jmi73HwBIUl50j+osU4= golang.org/x/crypto v0.19.0/go.mod h1:Iy9bg/ha4yyC70EfRS8jz+B6ybOBKMaSxLj6P6oBDfU= -golang.org/x/crypto v0.21.0/go.mod h1:0BP7YvVV9gBbVKyeTG0Gyn+gZm94bibOW5BjDEYAOMs= -golang.org/x/crypto v0.22.0 h1:g1v0xeRhjcugydODzvb3mEM9SQ0HGp9s/nh3COQ/C30= -golang.org/x/crypto v0.22.0/go.mod h1:vr6Su+7cTlO45qkww3VDJlzDn0ctJvRgYbC2NvXHt+M= +golang.org/x/crypto v0.23.0 h1:dIJU/v2J8Mdglj/8rJ6UUOM3Zc9zLZxVZwwxMooUSAI= +golang.org/x/crypto v0.23.0/go.mod h1:CKFgDieR+mRhux2Lsu27y0fO304Db0wZe70UKqHu0v8= golang.org/x/exp v0.0.0-20190121172915-509febef88a4/go.mod h1:CJ0aWSM057203Lf6IL+f9T1iT9GByDxfZKAQTCR3kQA= golang.org/x/exp v0.0.0-20220722155223-a9213eeb770e h1:+WEEuIdZHnUeJJmEUjyYC2gfUMj69yZXw17EnHg/otA= golang.org/x/exp v0.0.0-20220722155223-a9213eeb770e/go.mod h1:Kr81I6Kryrl9sr8s2FK3vxD90NdsKWRuOIl2O4CvYbA= @@ -253,17 +252,15 @@ golang.org/x/sys v0.0.0-20220722155257-8c9f86f7a55f/go.mod h1:oPkhp1MJrh7nUepCBc golang.org/x/sys v0.5.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.8.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.17.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA= -golang.org/x/sys v0.18.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA= -golang.org/x/sys v0.19.0 h1:q5f1RH2jigJ1MoAWp2KTp3gm5zAGFUTarQZ5U386+4o= -golang.org/x/sys v0.19.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA= +golang.org/x/sys v0.20.0 h1:Od9JTbYCk261bKm4M/mw7AklTlFYIa0bIp9BgSm1S8Y= +golang.org/x/sys v0.20.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA= golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo= golang.org/x/term v0.0.0-20210927222741-03fcf44c2211/go.mod h1:jbD1KX2456YbFQfuXm/mYQcufACuNUgVhRMnK/tPxf8= golang.org/x/term v0.5.0/go.mod h1:jMB1sMXY+tzblOD4FWmEbocvup2/aLOaQEp7JmGp78k= golang.org/x/term v0.8.0/go.mod h1:xPskH00ivmX89bAKVGSKKtLOWNx2+17Eiy94tnKShWo= golang.org/x/term v0.17.0/go.mod h1:lLRBjIVuehSbZlaOtGMbcMncT+aqLLLmKrsjNrUguwk= -golang.org/x/term v0.18.0/go.mod h1:ILwASektA3OnRv7amZ1xhE/KTR+u50pbXfZ03+6Nx58= -golang.org/x/term v0.19.0 h1:+ThwsDv+tYfnJFhF4L8jITxu1tdTWRTZpdsWgEgjL6Q= -golang.org/x/term v0.19.0/go.mod h1:2CuTdWZ7KHSQwUzKva0cbMg6q2DMI3Mmxp+gKJbskEk= +golang.org/x/term v0.20.0 h1:VnkxpohqXaOBYJtBmEppKUG6mXpi+4O6purfc2+sMhw= +golang.org/x/term v0.20.0/go.mod h1:8UkIAJTvZgivsXaD6/pH6U9ecQzZ45awqEOzuCvwpFY= golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= golang.org/x/text v0.3.2/go.mod h1:bEr9sfX3Q8Zfm5fL9x+3itogRgK3+ptLWKqgva+5dAk= golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ= @@ -272,8 +269,9 @@ golang.org/x/text v0.3.7/go.mod h1:u+2+/6zg+i71rQMx5EYifcz6MCKuco9NR6JIITiCfzQ= golang.org/x/text v0.3.8/go.mod h1:E6s5w1FMmriuDzIBO73fBruAKo1PCIq6d2Q6DHfQ8WQ= golang.org/x/text v0.7.0/go.mod h1:mrYo+phRRbMaCq/xk9113O4dZlRixOauAjOtrjsXDZ8= golang.org/x/text v0.9.0/go.mod h1:e1OnstbJyHTd6l/uOt8jFFHp6TRDWZR/bV3emEE/zU8= -golang.org/x/text v0.14.0 h1:ScX5w1eTa3QqT8oi6+ziP7dTV1S2+ALU0bI+0zXKWiQ= golang.org/x/text v0.14.0/go.mod h1:18ZOQIKpY8NJVqYksKHtTdi31H5itFRjB5/qKTNYzSU= +golang.org/x/text v0.15.0 h1:h1V/4gjBv8v9cjcR6+AR5+/cIYK5N/WAgiv4xlsEtAk= +golang.org/x/text v0.15.0/go.mod h1:18ZOQIKpY8NJVqYksKHtTdi31H5itFRjB5/qKTNYzSU= golang.org/x/time v0.3.0 h1:rg5rLMjNzMS1RkNLzCG38eapWhnYLFYXDXj2gOlr8j4= golang.org/x/time v0.3.0/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ= golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ= diff --git a/package/Dockerfile b/package/Dockerfile index 9b9aa89..4a85fc9 100755 --- a/package/Dockerfile +++ b/package/Dockerfile @@ -1,4 +1,4 @@ -FROM registry.suse.com/bci/bci-base:15.5 +FROM registry.suse.com/bci/bci-base:15.6 RUN zypper update -y && \ zypper in -y -f vim && \ @@ -7,6 +7,6 @@ RUN zypper update -y && \ RUN useradd --uid 1007 cce-operator ENV KUBECONFIG /home/cce-operator/.kube/config -COPY bin/cce-operator /usr/bin/ +COPY dist/cce-operator_linux_${TARGETARCH}*/ /usr/bin/ USER 1007 ENTRYPOINT ["cce-operator", "--debug"] diff --git a/scripts/build.sh b/scripts/build.sh deleted file mode 100755 index d5383fb..0000000 --- a/scripts/build.sh +++ /dev/null @@ -1,24 +0,0 @@ -#!/usr/bin/env bash - -set -euo pipefail - -cd $(dirname $0)/../ -WORKINGDIR=$(pwd) - -source ./scripts/version.sh -echo "Build version: ${VERSION}" - -BUILD_FLAG="" -if [[ -z "${DEBUG:-}" ]]; then - BUILD_FLAG="-extldflags -static -s -w" -fi -if [[ "${COMMIT}" != "UNKNOW" ]]; then - BUILD_FLAG="${BUILD_FLAG} -X 'github.com/cnrancher/cce-operator/pkg/utils.GitCommit=${COMMIT}'" -fi -BUILD_FLAG="${BUILD_FLAG} -X 'github.com/cnrancher/cce-operator/pkg/utils.Version=${VERSION}'" - -mkdir -p bin && cd bin -CGO_ENABLED=0 go build -ldflags "${BUILD_FLAG}" -o cce-operator .. -echo "--------------------" -ls -alh cce-operator -echo "--------------------" diff --git a/scripts/chart.sh b/scripts/chart.sh new file mode 100755 index 0000000..98288a1 --- /dev/null +++ b/scripts/chart.sh @@ -0,0 +1,31 @@ +#!/usr/bin/env bash + +set -euo pipefail + +if ! hash helm 2>/dev/null; then + exit 0 +fi + +cd $(dirname $0)/.. +WORKINGDIR=$(pwd) + +rm -rf build/charts &> /dev/null || true +mkdir -p build dist/artifacts &> /dev/null || true +cp -rf charts build/ &> /dev/null || true + +sed -i \ + -e 's/^version:.*/version: '${TAG/v/}'/' \ + -e 's/appVersion:.*/appVersion: '${TAG/v/}'/' \ + build/charts/cce-operator/Chart.yaml + +sed -i \ + -e 's/tag:.*/tag: '${TAG}'/' \ + build/charts/cce-operator/values.yaml + +sed -i \ + -e 's/^version:.*/version: '${TAG/v/}'/' \ + -e 's/appVersion:.*/appVersion: '${TAG/v/}'/' \ + build/charts/cce-operator-crd/Chart.yaml + +helm package -d ./dist/artifacts ./build/charts/cce-operator +helm package -d ./dist/artifacts ./build/charts/cce-operator-crd diff --git a/scripts/ci.sh b/scripts/ci.sh deleted file mode 100755 index 6051609..0000000 --- a/scripts/ci.sh +++ /dev/null @@ -1,11 +0,0 @@ -#!/usr/bin/env bash - -set -euo pipefail - -cd $(dirname $0) - -./validate.sh -./test.sh -./build.sh -./package.sh -./package-helm.sh diff --git a/scripts/clean.sh b/scripts/clean.sh index d14d96d..8c0d9ac 100755 --- a/scripts/clean.sh +++ b/scripts/clean.sh @@ -8,6 +8,7 @@ WORKINGDIR=$(pwd) files=( "cce-operator" "bin/" + "build/" "dist/" ) diff --git a/scripts/entry.sh b/scripts/entry.sh deleted file mode 100755 index 955d017..0000000 --- a/scripts/entry.sh +++ /dev/null @@ -1,14 +0,0 @@ -#!/usr/bin/env bash - -set -euo pipefail - -cd $(dirname $0)/../ -mkdir -p ./bin -mkdir -p ./dists/artifacts -if [[ -e ./scripts/$1.sh ]]; then - ./scripts/$1.sh -else - exec "$@" -fi - -chown -R $DAPPER_UID:$DAPPER_GID . diff --git a/scripts/image.sh b/scripts/image.sh new file mode 100755 index 0000000..27bd449 --- /dev/null +++ b/scripts/image.sh @@ -0,0 +1,39 @@ +#!/bin/bash + +set -euo pipefail + +cd $(dirname $0)/../ + +REPO=${REPO:-'cnrancher'} +TAG=${TAG:-'latest'} +BUILDER='rancher-cce-operator' +TARGET_PLATFORMS='linux/arm64,linux/amd64' + +# FYI: https://docs.docker.com/build/buildkit/toml-configuration/#buildkitdtoml +BUILDX_CONFIG_DIR=${BUILDX_CONFIG_DIR:-"$HOME/.config/buildkit/"} +BUILDX_CONFIG=${BUILDX_CONFIG:-"$HOME/.config/buildkit/buildkitd.toml"} +BUILDX_OPTIONS=${BUILDX_OPTIONS:-''} # Set to '--push' to upload images + +if [[ ! -e "${BUILDX_CONFIG}" ]]; then + mkdir -p ${BUILDX_CONFIG_DIR} + touch ${BUILDX_CONFIG} +fi + +docker buildx ls | grep ${BUILDER} || \ + docker buildx create \ + --config ${BUILDX_CONFIG} \ + --driver-opt network=host \ + --name=${BUILDER} \ + --platform=${TARGET_PLATFORMS} + +echo "Start build images" +set -x + +docker buildx build -f package/Dockerfile \ + --builder ${BUILDER} \ + -t "${REPO}/cce-operator:${TAG}" \ + --platform=${TARGET_PLATFORMS} ${BUILDX_OPTIONS} . + +set +x + +echo "Image: Done" diff --git a/scripts/package-helm.sh b/scripts/package-helm.sh deleted file mode 100755 index 72a0324..0000000 --- a/scripts/package-helm.sh +++ /dev/null @@ -1,32 +0,0 @@ -#!/usr/bin/env bash - -set -euo pipefail - -if ! hash helm 2>/dev/null; then - exit 0 -fi - -cd $(dirname $0)/.. -WORKINGDIR=$(pwd) -source ./scripts/version.sh - -rm -rf build/charts &> /dev/null || echo -n "" -mkdir -p build dist/artifacts &> /dev/null || echo -n "" -cp -rf charts build/ &> /dev/null || echo -n "" - -sed -i \ - -e 's/^version:.*/version: '${HELM_VERSION}'/' \ - -e 's/appVersion:.*/appVersion: '${HELM_VERSION}'/' \ - build/charts/cce-operator/Chart.yaml - -sed -i \ - -e 's/tag:.*/tag: '${HELM_TAG}'/' \ - build/charts/cce-operator/values.yaml - -sed -i \ - -e 's/^version:.*/version: '${HELM_VERSION}'/' \ - -e 's/appVersion:.*/appVersion: '${HELM_VERSION}'/' \ - build/charts/cce-operator-crd/Chart.yaml - -helm package -d ./dist/artifacts ./build/charts/cce-operator -helm package -d ./dist/artifacts ./build/charts/cce-operator-crd diff --git a/scripts/package.sh b/scripts/package.sh deleted file mode 100755 index 95ff4eb..0000000 --- a/scripts/package.sh +++ /dev/null @@ -1,12 +0,0 @@ -#!/usr/bin/env bash - -set -euo pipefail - -source $(dirname $0)/version.sh -cd $(dirname $0)/.. -WORKINGDIR=$(pwd) - -mkdir -p dist/artifacts -cp bin/cce-operator dist/artifacts/cce-operator${SUFFIX} - -./scripts/package-helm.sh diff --git a/scripts/validate.sh b/scripts/verify.sh similarity index 78% rename from scripts/validate.sh rename to scripts/verify.sh index 1df5276..dc841a9 100755 --- a/scripts/validate.sh +++ b/scripts/verify.sh @@ -4,6 +4,12 @@ set -euo pipefail cd $(dirname $0)/.. WORKINGDIR=$(pwd) +if [ -n "$(git status --porcelain --untracked-files=no)" ]; then + echo 'Ensure git directory is clean before run this script:' + git status --short + exit 1 +fi + echo 'Running: go mod verify' go mod verify diff --git a/scripts/version.sh b/scripts/version.sh deleted file mode 100755 index b3b6f00..0000000 --- a/scripts/version.sh +++ /dev/null @@ -1,44 +0,0 @@ -#!/usr/bin/env bash - -set -euo pipefail - -# Ensure git installed -type git > /dev/null - -DIRTY="" -if [[ -n "$(git status --porcelain --untracked-files=no)" ]]; then - DIRTY="-dirty" -fi - -COMMIT=$(git rev-parse --short HEAD) -GIT_TAG=${DRONE_TAG:-$(git tag -l --contains HEAD | head -n 1)} - -if [[ -z "$DIRTY" && -n "$GIT_TAG" ]]; then - VERSION=$GIT_TAG -else - VERSION="v0.0.0-${COMMIT}${DIRTY}" -fi - -if [[ -z "${ARCH:-}" ]]; then - ARCH=$(go env GOHOSTARCH) -fi -if [[ -z "${OS:-}" ]]; then - OS=$(go env GOHOSTOS) -fi - -SUFFIX="-${OS}-${ARCH}" -HELM_TAG=${TAG:-"${VERSION}"} -HELM_VERSION=${HELM_TAG/v/} -TAG=${TAG:-${VERSION}${SUFFIX}} -REPO=${REPO:-cnrancher} - -if [[ $TAG = v0.0.0-* ]]; then - TAG=dev - HELM_TAG=dev - HELM_VERSION="0.0.0-dev" - DEBUG="true" -fi - -if [[ ${VERSION} = *rc* ]] || [[ ${VERSION} = *alpha* ]] || [[ ${VERSION} = *beta* ]]; then - DEBUG="true" -fi