From 572e3cf7b49062fe87eaad6c0c34edb29b628a6c Mon Sep 17 00:00:00 2001 From: rick <1450685+LinuxSuRen@users.noreply.github.com> Date: Tue, 14 Dec 2021 15:53:38 +0800 Subject: [PATCH] Fix the action build base on the master branch --- .github/workflows/build-image.yml | 60 ------------------- .../{build-dev-image.yml => build.yaml} | 29 ++++++--- .github/workflows/pull-request.yml | 7 ++- formula.yaml | 3 +- 4 files changed, 28 insertions(+), 71 deletions(-) delete mode 100644 .github/workflows/build-image.yml rename .github/workflows/{build-dev-image.yml => build.yaml} (59%) diff --git a/.github/workflows/build-image.yml b/.github/workflows/build-image.yml deleted file mode 100644 index f754124..0000000 --- a/.github/workflows/build-image.yml +++ /dev/null @@ -1,60 +0,0 @@ -name: Build Image - -on: - push: - tags: - - v** - -jobs: - build: - runs-on: ubuntu-latest - steps: - - uses: actions/checkout@v2 - - name: Docker meta for kubesphere - id: meta - uses: docker/metadata-action@v3 - with: - images: | - kubespheredev/ks-jenkins - tags: | - type=schedule - type=ref,event=branch - type=ref,event=pr - type=semver,pattern=v{{major}}.{{minor}}.{{patch}} - - name: Cache - uses: actions/cache@v1.1.2 - with: - path: ~/.m2 - key: maven - restore-keys: maven - - name: Dependency - run: | - wget https://bitbucket.org/ariya/phantomjs/downloads/phantomjs-2.1.1-linux-x86_64.tar.bz2 - tar xvjf phantomjs-2.1.1-linux-x86_64.tar.bz2 - ls -ahl - - name: Build - run: | - docker login --username ${{ secrets.DOCKER_HUB_USER }} --password ${{secrets.DOCKER_HUB_TOKEN}} - - mkdir -p ~/.m2 - echo "${{secrets.MVN_SETTINGS}}" > ~/.m2/settings.xml - curl -L https://github.com/jenkins-zh/jenkins-cli/releases/latest/download/jcli-linux-amd64.tar.gz|tar xzv - export PATH=.:$PATH:phantomjs/bin - jcli cwp --install-artifacts --config-path formula.yaml \ - --value-set version=${{ fromJSON(steps.meta.outputs.json).labels['org.opencontainers.image.version'] }} - - # there's no a release for the multi-arch building but https://github.com/jenkinsci/custom-war-packager/releases/tag/v2.0-alpha-6 - wget https://github.com/LinuxSuRen/custom-war-packager/releases/download/v2.0-alpha-6/custom-war-packager-cli-2.0-alpha-7-20210527.031403-1-jar-with-dependencies.jar - mv custom-war-packager-cli-2.0-alpha-7-20210527.031403-1-jar-with-dependencies.jar ~/.jenkins-cli/cwp-cli.jar - jcli cwp --install-artifacts --config-path formula-arm.yaml --value-set output=push \ - --value-set version=${{ fromJSON(steps.meta.outputs.json).labels['org.opencontainers.image.version'] }} - - name: Push Image - run: | - version=${{ fromJSON(steps.meta.outputs.json).labels['org.opencontainers.image.version'] }} - docker push kubespheredev/ks-jenkins:$version - - name: Push Image ghcr.io - run: | - version=${{ fromJSON(steps.meta.outputs.json).labels['org.opencontainers.image.version'] }} - docker login ghcr.io --username ${{ secrets.GH_USER }} --password ${{secrets.GH_TOKEN}} - docker tag kubespheredev/ks-jenkins:$version ghcr.io/kubesphere/ks-jenkins:$version - docker push ghcr.io/kubesphere/ks-jenkins:$version diff --git a/.github/workflows/build-dev-image.yml b/.github/workflows/build.yaml similarity index 59% rename from .github/workflows/build-dev-image.yml rename to .github/workflows/build.yaml index 381b5ce..fd87458 100644 --- a/.github/workflows/build-dev-image.yml +++ b/.github/workflows/build.yaml @@ -1,10 +1,12 @@ -name: Build Dev Image +name: Build Image on: push: branches: - master - "release-**" + tags: + - v** jobs: build: @@ -33,20 +35,33 @@ jobs: wget https://bitbucket.org/ariya/phantomjs/downloads/phantomjs-2.1.1-linux-x86_64.tar.bz2 tar xvjf phantomjs-2.1.1-linux-x86_64.tar.bz2 ls -ahl + + # v2.0-alpha-6 is a pre-release, jcli is not able to download it automatically. + mkdir -p ~/.jenkins-cli + curl https://github.com/LinuxSuRen/custom-war-packager/releases/download/v2.0-alpha-6/custom-war-packager-cli-2.0-alpha-7-20210527.031403-1-jar-with-dependencies.jar \ + -L --output ~/.jenkins-cli/cwp-cli.jar + - name: Set up QEMU + uses: docker/setup-qemu-action@v1 + - name: Set up Docker Buildx + uses: docker/setup-buildx-action@v1 + - name: Build env + id: build_env + shell: bash + run: | + echo "::set-output name=version::${{ fromJSON(steps.meta.outputs.json).labels['org.opencontainers.image.version'] }}" - name: Build run: | docker login --username ${{ secrets.DOCKER_HUB_USER }} --password ${{secrets.DOCKER_HUB_TOKEN}} curl -L https://github.com/jenkins-zh/jenkins-cli/releases/latest/download/jcli-linux-amd64.tar.gz|tar xzv - export PATH=.:$PATH:phantomjs/bin - # there's no a release for the multi-arch building but https://github.com/jenkinsci/custom-war-packager/releases/tag/v2.0-alpha-6 - wget https://github.com/LinuxSuRen/custom-war-packager/releases/download/v2.0-alpha-6/custom-war-packager-cli-2.0-alpha-7-20210527.031403-1-jar-with-dependencies.jar - mv custom-war-packager-cli-2.0-alpha-7-20210527.031403-1-jar-with-dependencies.jar ~/.jenkins-cli/cwp-cli.jar jcli cwp --install-artifacts --config-path formula.yaml --value-set output=push \ - --value-set version=kubespheredev/ks-jenkins:${{ steps.meta.outputs.version }} + --value-set tag=kubespheredev/ks-jenkins:${{ steps.build_env.outputs.version }} \ + --value-set platform=linux/amd64,linux/arm64 - name: Push Image ghcr.io run: | + docker login ghcr.io --username ${{ secrets.GH_USER }} --password ${{secrets.GH_TOKEN}} jcli cwp --install-artifacts --config-path formula.yaml --value-set output=push \ - --value-set tag=ghcr.io/kubesphere/ks-jenkins:${{ steps.meta.outputs.version }} + --value-set tag=ghcr.io/kubesphere/ks-jenkins:${{ steps.build_env.outputs.version }} \ + --value-set platform=linux/amd64,linux/arm64 diff --git a/.github/workflows/pull-request.yml b/.github/workflows/pull-request.yml index 2d45c8b..8a3adb4 100644 --- a/.github/workflows/pull-request.yml +++ b/.github/workflows/pull-request.yml @@ -47,14 +47,15 @@ jobs: run: | echo "::set-output name=version::${{ fromJSON(steps.meta.outputs.json).labels['org.opencontainers.image.version'] }}" - name: Build + shell: bash run: | curl -L https://github.com/jenkins-zh/jenkins-cli/releases/latest/download/jcli-linux-amd64.tar.gz|tar xzv export PATH=.:$PATH:phantomjs/bin - wget https://github.com/LinuxSuRen/custom-war-packager/releases/download/v2.0-alpha-6/custom-war-packager-cli-2.0-alpha-7-20210527.031403-1-jar-with-dependencies.jar - mv custom-war-packager-cli-2.0-alpha-7-20210527.031403-1-jar-with-dependencies.jar ~/.jenkins-cli/cwp-cli.jar + jcli cwp --install-artifacts --config-path formula.yaml \ --value-set output=load \ - --value-set tag=kubespheredev/ks-jenkins:${{ steps.build_env.outputs.version }} + --value-set tag=kubespheredev/ks-jenkins:${{ steps.build_env.outputs.version }} \ + --value-set platform=linux/amd64 - name: Run Trivy vulnerability scanner uses: aquasecurity/trivy-action@0.2.0 if: github.event_name == 'pull_request' diff --git a/formula.yaml b/formula.yaml index 28b5954..5bce397 100644 --- a/formula.yaml +++ b/formula.yaml @@ -7,7 +7,8 @@ buildSettings: docker: base: jenkins/jenkins:2.319.1 tag: {{.tag}} - platform: linux/amd64,linux/arm64 + output: {{.output}} + platform: {{.platform}} buildx: true build: true war: