From 02bdbce99a32e5aa56f70b45538f6f7399a9ce70 Mon Sep 17 00:00:00 2001 From: Powerfool Date: Wed, 29 Nov 2023 20:00:43 +0800 Subject: [PATCH] Actions for building and releasing manifests (#107) * chore: workflows for building and release --- .github/workflows/build.yml | 39 +++++++++++++++ .github/workflows/golangci-lint.yml | 1 + .../{release.yml => release-charts.yml} | 18 +++---- .github/workflows/release-obagent.yml | 43 +++++++++++++++++ .github/workflows/release-obconfigserver.yml | 43 +++++++++++++++++ .github/workflows/release-obproxy.yml | 43 +++++++++++++++++ .github/workflows/release-observer.yml | 43 +++++++++++++++++ .github/workflows/release-operator.yml | 47 +++++++++++++++++++ distribution/ob-configserver/Dockerfile | 4 +- distribution/ob-configserver/build.sh | 3 +- distribution/obagent/Dockerfile | 4 +- distribution/obagent/build.sh | 3 +- distribution/obproxy/Dockerfile | 6 +-- distribution/obproxy/build.sh | 4 +- distribution/oceanbase/Dockerfile | 8 ++-- distribution/oceanbase/build.sh | 4 +- doc/development/development.md | 2 +- 17 files changed, 291 insertions(+), 24 deletions(-) create mode 100644 .github/workflows/build.yml rename .github/workflows/{release.yml => release-charts.yml} (63%) create mode 100644 .github/workflows/release-obagent.yml create mode 100644 .github/workflows/release-obconfigserver.yml create mode 100644 .github/workflows/release-obproxy.yml create mode 100644 .github/workflows/release-observer.yml create mode 100644 .github/workflows/release-operator.yml diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml new file mode 100644 index 000000000..62e579472 --- /dev/null +++ b/.github/workflows/build.yml @@ -0,0 +1,39 @@ +name: build ob-operator + +on: + push: + branches: + - '*_dev' + +env: + GO_VERSION: "1.20" + +jobs: + build-images: + runs-on: ubuntu-latest + + steps: + - name: Checkout repository + uses: actions/checkout@v3 + + - name: Set up Go 1.x + uses: actions/setup-go@v3 + with: + go-version: ${{ env.GO_VERSION }} + + - name: go mod vendor + run: go mod vendor + + - name: Set up QEMU + uses: docker/setup-qemu-action@v1 + + - name: Set up Docker Buildx + uses: docker/setup-buildx-action@v1 + + - name: Build Docker images + uses: docker/build-push-action@v2 + with: + context: . + platforms: linux/amd64,linux/arm64 + file: Dockerfile + push: false \ No newline at end of file diff --git a/.github/workflows/golangci-lint.yml b/.github/workflows/golangci-lint.yml index 38a0d0d8f..5303ba637 100644 --- a/.github/workflows/golangci-lint.yml +++ b/.github/workflows/golangci-lint.yml @@ -3,6 +3,7 @@ on: pull_request: branches: - 2.0.x_dev + - 2.x_dev permissions: contents: read diff --git a/.github/workflows/release.yml b/.github/workflows/release-charts.yml similarity index 63% rename from .github/workflows/release.yml rename to .github/workflows/release-charts.yml index 05aa1f138..0d9d2ff4a 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release-charts.yml @@ -1,14 +1,14 @@ -name: release helm chart +name: release helm charts -on: +on: push: - branches: - - 'master' - - '*release' - - 'helm-chart' + tags: + - '2.[0-9]+.[0-9]+' + - 'chart-2.[0-9]+.[0-9]+' jobs: - release: + release-chart: + permissions: write-all runs-on: ubuntu-latest steps: - name: Checkout @@ -22,6 +22,8 @@ jobs: git config user.email "$GITHUB_ACTOR@users.noreply.github.com" - name: Run chart-releaser - uses: helm/chart-releaser-action@v1.1.0 + uses: helm/chart-releaser-action@v1.6.0 env: CR_TOKEN: "${{ secrets.GITHUB_TOKEN }}" + with: + mark_as_latest: false \ No newline at end of file diff --git a/.github/workflows/release-obagent.yml b/.github/workflows/release-obagent.yml new file mode 100644 index 000000000..8c0a85ebb --- /dev/null +++ b/.github/workflows/release-obagent.yml @@ -0,0 +1,43 @@ +name: release obagent + +on: + push: + tags: + - "obagent-*" + +env: + tagName: ${{ github.ref_name }} + +jobs: + release-obagent: + runs-on: ubuntu-latest + steps: + - name: Log in to Docker hub + uses: docker/login-action@v2 + with: + username: ${{ secrets.DOCKER_USERNAME }} + password: ${{ secrets.DOCKER_PASSWORD }} + + - name: Checkout repository + uses: actions/checkout@v3 + + - name: Set up QEMU + uses: docker/setup-qemu-action@v2 + + - name: Set up Docker Buildx + uses: docker/setup-buildx-action@v2 + + - name: Set Version variables + id: set_version_vars + run: echo "version=$(echo $tagName | grep -P '(\d*\.\d*\.\d*-\d*)' --only-matching)" >> $GITHUB_OUTPUT + + - name: Build and push obagent w/o cache + uses: docker/build-push-action@v2 + with: + context: ./distribution/obagent + platforms: linux/amd64,linux/arm64 + file: ./distribution/obagent/Dockerfile + push: true + tags: ${{ vars.DOCKER_PUSH_BASE }}/obagent:${{ steps.set_version_vars.outputs.version }} + build-args: | + VERSION=${{ steps.set_version_vars.outputs.version }} \ No newline at end of file diff --git a/.github/workflows/release-obconfigserver.yml b/.github/workflows/release-obconfigserver.yml new file mode 100644 index 000000000..bb67c9296 --- /dev/null +++ b/.github/workflows/release-obconfigserver.yml @@ -0,0 +1,43 @@ +name: release obconfigserver + +on: + push: + tags: + - "obconfigserver-*" + +env: + tagName: ${{ github.ref_name }} + +jobs: + release-obconfigserver: + runs-on: ubuntu-latest + steps: + - name: Log in to Docker hub + uses: docker/login-action@v2 + with: + username: ${{ secrets.DOCKER_USERNAME }} + password: ${{ secrets.DOCKER_PASSWORD }} + + - name: Checkout repository + uses: actions/checkout@v3 + + - name: Set up QEMU + uses: docker/setup-qemu-action@v2 + + - name: Set up Docker Buildx + uses: docker/setup-buildx-action@v2 + + - name: Set Version variables + id: set_version_vars + run: echo "version=$(echo $tagName | grep -P '(\d*\.\d*\.\d*-\d*)' --only-matching)" >> $GITHUB_OUTPUT + + - name: Build and push obconfigserver w/o cache + uses: docker/build-push-action@v2 + with: + context: ./distribution/ob-configserver + platforms: linux/amd64,linux/arm64 + file: ./distribution/ob-configserver/Dockerfile + push: true + tags: ${{ vars.DOCKER_PUSH_BASE }}/obconfigserver:${{ steps.set_version_vars.outputs.version }} + build-args: | + VERSION=${{ steps.set_version_vars.outputs.version }} diff --git a/.github/workflows/release-obproxy.yml b/.github/workflows/release-obproxy.yml new file mode 100644 index 000000000..e0ec1b27b --- /dev/null +++ b/.github/workflows/release-obproxy.yml @@ -0,0 +1,43 @@ +name: release obproxy + +on: + push: + tags: + - "obproxy-*" + +env: + tagName: ${{ github.ref_name }} + +jobs: + release-obproxy: + runs-on: ubuntu-latest + steps: + - name: Log in to Docker hub + uses: docker/login-action@v2 + with: + username: ${{ secrets.DOCKER_USERNAME }} + password: ${{ secrets.DOCKER_PASSWORD }} + + - name: Checkout repository + uses: actions/checkout@v3 + + - name: Set up QEMU + uses: docker/setup-qemu-action@v2 + + - name: Set up Docker Buildx + uses: docker/setup-buildx-action@v2 + + - name: Set Version variables + id: set_version_vars + run: echo "version=$(echo $tagName | grep -P '(\d*\.\d*\.\d*\.\d*-\d*)' --only-matching)" >> $GITHUB_OUTPUT + + - name: Build and push obproxy w/o cache + uses: docker/build-push-action@v2 + with: + context: ./distribution/obproxy + platforms: linux/amd64,linux/arm64 + file: ./distribution/obproxy/Dockerfile + push: true + tags: ${{ vars.DOCKER_PUSH_BASE }}/obproxy:${{ steps.set_version_vars.outputs.version }} + build-args: | + VERSION=${{ steps.set_version_vars.outputs.version }} diff --git a/.github/workflows/release-observer.yml b/.github/workflows/release-observer.yml new file mode 100644 index 000000000..ff30e2324 --- /dev/null +++ b/.github/workflows/release-observer.yml @@ -0,0 +1,43 @@ +name: release observer + +on: + push: + tags: + - "observer-*" + +env: + tagName: ${{ github.ref_name }} + +jobs: + release-observer: + runs-on: ubuntu-latest + steps: + - name: Log in to Docker hub + uses: docker/login-action@v2 + with: + username: ${{ secrets.DOCKER_USERNAME }} + password: ${{ secrets.DOCKER_PASSWORD }} + + - name: Checkout repository + uses: actions/checkout@v3 + + - name: Set up QEMU + uses: docker/setup-qemu-action@v2 + + - name: Set up Docker Buildx + uses: docker/setup-buildx-action@v2 + + - name: Set Version variables + id: set_version_vars + run: echo "version=$(echo $tagName | grep -P '(\d*\.\d*\.\d*\.\d*-\d{18})' --only-matching)" >> $GITHUB_OUTPUT + + - name: Build and push observer w/o cache + uses: docker/build-push-action@v2 + with: + context: ./distribution/oceanbase + platforms: linux/amd64,linux/arm64 + file: ./distribution/oceanbase/Dockerfile + push: true + tags: ${{ vars.DOCKER_PUSH_BASE }}/oceanbase-cloud-native:${{ steps.set_version_vars.outputs.version }} + build-args: | + VERSION=${{ steps.set_version_vars.outputs.version }} \ No newline at end of file diff --git a/.github/workflows/release-operator.yml b/.github/workflows/release-operator.yml new file mode 100644 index 000000000..cf6f6ea39 --- /dev/null +++ b/.github/workflows/release-operator.yml @@ -0,0 +1,47 @@ +name: release operator + +on: + push: + tags: + - '2.[0-9]+.[0-9]+' + +jobs: + release-operator: + runs-on: ubuntu-latest + steps: + - name: Checkout repository + uses: actions/checkout@v3 + + - name: Set up QEMU + uses: docker/setup-qemu-action@v2 + + - name: Set up Docker Buildx + uses: docker/setup-buildx-action@v2 + + - name: Log in to Docker hub + uses: docker/login-action@v2 + with: + username: ${{ secrets.DOCKER_USERNAME }} + password: ${{ secrets.DOCKER_PASSWORD }} + + - name: Create and push manifests w/ cache + uses: docker/build-push-action@v2 + if: ${{ vars.ENABLE_DOCKER_CACHE }} + with: + context: . + platforms: linux/amd64,linux/arm64 + file: Dockerfile + push: true + tags: ${{ vars.DOCKER_PUSH_BASE }}/ob-operator:${{ github.ref_name }} + cache-from: type=registry,ref=${{ vars.DOCKER_PUSH_BASE }}/ob-operator:buildcache + cache-to: type=registry,ref=${{ vars.DOCKER_PUSH_BASE }}/ob-operator:buildcache,mode=max + + - name: Create and push manifests w/o cache + uses: docker/build-push-action@v2 + if: ${{ !vars.ENABLE_DOCKER_CACHE }} + with: + context: . + platforms: linux/amd64,linux/arm64 + file: Dockerfile + push: true + tags: ${{ vars.DOCKER_PUSH_BASE }}/ob-operator:${{ github.ref_name }} \ No newline at end of file diff --git a/distribution/ob-configserver/Dockerfile b/distribution/ob-configserver/Dockerfile index 9c65b40ab..14493292a 100644 --- a/distribution/ob-configserver/Dockerfile +++ b/distribution/ob-configserver/Dockerfile @@ -3,8 +3,8 @@ FROM openanolis/anolisos:8.8 RUN ln -sf /usr/share/zoneinfo/Asia/Shanghai /etc/localtime ARG VERSION -ARG ARCH=x86_64 -RUN yum install -y http://mirrors.aliyun.com/oceanbase/community/stable/el/8/${ARCH}/ob-configserver-${VERSION}.el8.${ARCH}.rpm +ARG TARGETPLATFORM +RUN if [[ ${TARGETPLATFORM} == 'linux/amd64' ]] ; then yum install -y http://mirrors.aliyun.com/oceanbase/community/stable/el/8/x86_64/ob-configserver-${VERSION}.el8.x86_64.rpm ; else yum install -y http://mirrors.aliyun.com/oceanbase/community/stable/el/8/aarch64/ob-configserver-${VERSION}.el8.aarch64.rpm ; fi ADD config.yaml.template /home/admin/ob-configserver/conf/ ADD start.sh /home/admin/ob-configserver WORKDIR /home/admin/ob-configserver diff --git a/distribution/ob-configserver/build.sh b/distribution/ob-configserver/build.sh index 556ed4f0f..6b10c912d 100755 --- a/distribution/ob-configserver/build.sh +++ b/distribution/ob-configserver/build.sh @@ -1,2 +1,3 @@ #!/bin/bash -docker build -t $1:$2 --build-arg VERSION=$2 --build-arg ARCH=$3 . +# @Params TARGETPLATFORM linux/amd64 or linux/arm64 +docker build -t $1:$2 --build-arg VERSION=$2 --build-arg TARGETPLATFORM=$3 . diff --git a/distribution/obagent/Dockerfile b/distribution/obagent/Dockerfile index a936e3456..7b3f0d0d8 100644 --- a/distribution/obagent/Dockerfile +++ b/distribution/obagent/Dockerfile @@ -1,8 +1,8 @@ FROM openanolis/anolisos:8.8 ARG VERSION -ARG ARCH=x86_64 +ARG TARGETPLATFORM WORKDIR /home/admin/obagent -RUN yum install -y http://mirrors.aliyun.com/oceanbase/community/stable/el/8/${ARCH}/obagent-${VERSION}.el8.${ARCH}.rpm +RUN if [[ ${TARGETPLATFORM} == 'linux/amd64' ]] ; then yum install -y http://mirrors.aliyun.com/oceanbase/community/stable/el/8/x86_64/obagent-${VERSION}.el8.x86_64.rpm ; else yum install -y http://mirrors.aliyun.com/oceanbase/community/stable/el/8/aarch64/obagent-${VERSION}.el8.aarch64.rpm ; fi ADD replace_properties.sh /home/admin/obagent RUN ln -sf /usr/share/zoneinfo/Asia/Shanghai /etc/localtime diff --git a/distribution/obagent/build.sh b/distribution/obagent/build.sh index 13046f72c..6b10c912d 100755 --- a/distribution/obagent/build.sh +++ b/distribution/obagent/build.sh @@ -1,2 +1,3 @@ #!/bin/bash - docker build -t $1:$2 --build-arg VERSION=$2 --build-arg ARCH=$3 . +# @Params TARGETPLATFORM linux/amd64 or linux/arm64 +docker build -t $1:$2 --build-arg VERSION=$2 --build-arg TARGETPLATFORM=$3 . diff --git a/distribution/obproxy/Dockerfile b/distribution/obproxy/Dockerfile index 271b73e47..01da7a839 100644 --- a/distribution/obproxy/Dockerfile +++ b/distribution/obproxy/Dockerfile @@ -3,11 +3,11 @@ FROM openanolis/anolisos:8.8 RUN ln -sf /usr/share/zoneinfo/Asia/Shanghai /etc/localtime ARG VERSION ARG RELEASE -ARG ARCH=x86_64 +ARG TARGETPLATFORM WORKDIR /home/admin RUN useradd -m admin -RUN rpm -ivh https://mirrors.aliyun.com/oceanbase/community/stable/el/8/${ARCH}/obproxy-ce-${VERSION}-${RELEASE}.el8.${ARCH}.rpm -RUN mv /home/admin/obproxy-${VERSION} /home/admin/obproxy +RUN if [[ ${TARGETPLATFORM} == 'linux/amd64' ]] ; then rpm -ivh https://mirrors.aliyun.com/oceanbase/community/stable/el/8/x86_64/obproxy-ce-${VERSION}.el8.x86_64.rpm ; else rpm -ivh https://mirrors.aliyun.com/oceanbase/community/stable/el/8/aarch64/obproxy-ce-${VERSION}.el8.aarch64.rpm ; fi +RUN mv /home/admin/obproxy-* /home/admin/obproxy RUN chown -R admin:admin /home/admin/obproxy ADD start.sh /home/admin diff --git a/distribution/obproxy/build.sh b/distribution/obproxy/build.sh index 2e50190ca..54749a9b0 100755 --- a/distribution/obproxy/build.sh +++ b/distribution/obproxy/build.sh @@ -1,2 +1,4 @@ #!/bin/bash -docker build -t $1:$2-$3 --build-arg VERSION=$2 --build-arg RELEASE=$3 --build-arg ARCH=$4 . +# @Params TARGETPLATFORM linux/amd64 or linux/arm64 +# VERSION: x.y.z-r e.g. 4.2.1-11 which merge old VERSION and RELEASE +docker build -t $1:$2 --build-arg VERSION=$2 --build-arg TARGETPLATFORM=$3 . diff --git a/distribution/oceanbase/Dockerfile b/distribution/oceanbase/Dockerfile index 4f4ecefd4..c30d354f9 100644 --- a/distribution/oceanbase/Dockerfile +++ b/distribution/oceanbase/Dockerfile @@ -6,13 +6,15 @@ RUN GO11MODULE=ON CGO_ENABLED=0 GOOS=linux go build -a -o oceanbase-helper main. FROM openanolis/anolisos:8.8 ARG VERSION -ARG ARCH=x86_64 +ARG TARGETPLATFORM +RUN echo TARGET_PLATFORM is ${TARGETPLATFORM} WORKDIR /home/admin/oceanbase RUN mkdir -p /home/admin/oceanbase/bin COPY --from=builder /workspace/oceanbase-helper /home/admin/oceanbase/bin RUN yum -y install python27 RUN pip2 install mysql-connector -i http://mirrors.aliyun.com/pypi/simple/ --trusted-host mirrors.aliyun.com -RUN yum install -y http://mirrors.aliyun.com/oceanbase/community/stable/el/8/${ARCH}/oceanbase-ce-libs-${VERSION}.el8.${ARCH}.rpm -RUN yum install -y http://mirrors.aliyun.com/oceanbase/community/stable/el/8/${ARCH}/oceanbase-ce-${VERSION}.el8.${ARCH}.rpm +# support docker platform linux/amd64 and linux/arm64, mapping platform to x86_64 or aarch64 +RUN if [[ ${TARGETPLATFORM} == 'linux/amd64' ]] ; then yum install -y http://mirrors.aliyun.com/oceanbase/community/stable/el/8/x86_64/oceanbase-ce-libs-${VERSION}.el8.x86_64.rpm ; else yum install -y http://mirrors.aliyun.com/oceanbase/community/stable/el/8/aarch64/oceanbase-ce-libs-${VERSION}.el8.aarch64.rpm ; fi +RUN if [[ ${TARGETPLATFORM} == 'linux/amd64' ]] ; then yum install -y http://mirrors.aliyun.com/oceanbase/community/stable/el/8/x86_64/oceanbase-ce-${VERSION}.el8.x86_64.rpm ; else yum install -y http://mirrors.aliyun.com/oceanbase/community/stable/el/8/aarch64/oceanbase-ce-${VERSION}.el8.aarch64.rpm ; fi RUN ln -sf /usr/share/zoneinfo/Asia/Shanghai /etc/localtime ENV LD_LIBRARY_PATH /home/admin/oceanbase/lib diff --git a/distribution/oceanbase/build.sh b/distribution/oceanbase/build.sh index 9acab6ebe..4dfeea76b 100755 --- a/distribution/oceanbase/build.sh +++ b/distribution/oceanbase/build.sh @@ -1,3 +1,3 @@ #!/bin/bash - -docker build -t $1:$2 --build-arg GOPROXY=${GOPROXY} --build-arg VERSION=$2 --build-arg ARCH=$3 . +# @Params TARGETPLATFORM linux/amd64 or linux/arm64 +docker build -t $1:$2 --build-arg GOPROXY=${GOPROXY} --build-arg VERSION=$2 --build-arg TARGETPLATFORM=$3 . diff --git a/doc/development/development.md b/doc/development/development.md index 60ffdfc8a..959fbfcaf 100644 --- a/doc/development/development.md +++ b/doc/development/development.md @@ -8,7 +8,7 @@ ob-operator requires [go 1.20 or above](https://go.dev/doc/install) to build, yo ob-operator uses [make](https://www.gnu.org/software/make/) for a variety of build and test actions, it's need to be installed before you go. 3. kubebuilder -ob-operator uses kubebuilder as operator framework, before you dive into the code, it's highly recommended to read [kubebuilder books](https://book.kubebuilder.io) +ob-operator uses kubebuilder as operator framework, before you dive into the code, it's highly recommended to read [kubebuilder books](https://book.kubebuilder.io). ## build ob-operator