diff --git a/.cid/DTSE-HDN-swr-multiplatform-build-workflow-samples.yml b/.cid/DTSE-HDN-swr-multiplatform-build-workflow-samples.yml index 1cd25c81c646c41ded49e18b52b2c0dc2397a644..90d725974af895da612d7d586f210d318af046f6 100644 --- a/.cid/DTSE-HDN-swr-multiplatform-build-workflow-samples.yml +++ b/.cid/DTSE-HDN-swr-multiplatform-build-workflow-samples.yml @@ -17,6 +17,7 @@ machine: # 构建脚本 scripts: + - sed -i "s#openjdk:19-jdk#swr.cn-north-6.myhuaweicloud.com/codeci/maven:openjdk-19#" Dockerfile - mvn package -Dmaven.test.skip=true - docker build -t registry-cbu.huawei.com/dtse-hdn/swr-multiplatform-build-workflow-samples:${CID_SHORT_UID} . diff --git a/.cid/cid.yml b/.cid/cid.yml index d4e2a0472c0a802ffa07ccffb2e7fd1b0afe6b91..e306d276905cca90a6fffd19daecd95d2b0c7498 100644 --- a/.cid/cid.yml +++ b/.cid/cid.yml @@ -14,6 +14,7 @@ machine: euler: - default scripts: + - sed -i "s#openjdk:19-jdk#swr.cn-north-6.myhuaweicloud.com/codeci/maven:openjdk-19#" Dockerfile - mvn package -Dmaven.test.skip=true - >- docker build -t diff --git a/.github/workflows/build-nginx-for-multiplatform.yml b/.github/workflows/build-nginx-for-multiplatform.yml index 33c7b543979579e8a01391f5318e651ef865027d..75fa51995ccb984d3792fb93828fedf9ecdc478f 100644 --- a/.github/workflows/build-nginx-for-multiplatform.yml +++ b/.github/workflows/build-nginx-for-multiplatform.yml @@ -1,4 +1,4 @@ -name: "commit-master" +name: Build Nginx for multiplatform on: push: @@ -9,19 +9,19 @@ jobs: runs-on: ubuntu-latest steps: - - name: Check Out + - name: Checkout uses: actions/checkout@v2 # docker login,设置登陆到华为的swr - - name: Log in to HuaweiCloud SWR - uses: huaweicloud/swr-login@v1 + - name: Log in to Huawei Cloud SWR + uses: huaweicloud/swr-login@v2.0.0 with: - region: cn-north-4 - access-key-id: ${{ secrets.ACCESSKEY }} - access-key-secret: ${{ secrets.SECRETACCESSKEY }} + region: cn-north-4 + access-key-id: ${{ secrets.ACCESSKEY }} + access-key-secret: ${{ secrets.SECRETACCESSKEY }} - - name: "build nginx image for linux/386,linux/amd64,linux/arm/v5,linux/arm/v7,linux/arm64/v8,linux/mips64le,linux/ppc64le,linux/s390x" - uses: huaweicloud/swr-multiplatform-build-action@v1.0.0 + - name: Build Nginx image for linux/386,linux/amd64,linux/arm/v5,linux/arm/v7,linux/arm64/v8,linux/mips64le,linux/ppc64le,linux/s390x + uses: huaweicloud/swr-multiplatform-build-action@v1.1.0 with: image_tag: swr.cn-north-4.myhuaweicloud.com/hcloudcli/nginx:nginx-12-v1.0.0.1 platforms: linux/386,linux/amd64,linux/arm/v5,linux/arm/v7,linux/arm64/v8,linux/mips64le,linux/ppc64le,linux/s390x diff --git a/.github/workflows/build-local-for-test.yml b/.github/workflows/build-simple-demo.yml similarity index 58% rename from .github/workflows/build-local-for-test.yml rename to .github/workflows/build-simple-demo.yml index 67ef1c96c5f579220a8e418024d1c9d9fd92a532..b7c082312154c5608121e90ccc3fbf8d5a14fee5 100644 --- a/.github/workflows/build-local-for-test.yml +++ b/.github/workflows/build-simple-demo.yml @@ -1,4 +1,4 @@ -name: "commit-master" +name: Build simple demo on: push: @@ -9,19 +9,19 @@ jobs: runs-on: ubuntu-latest steps: - - name: Check Out + - name: Checkout uses: actions/checkout@v2 - - name: Set up JDK 19 for maven build + - name: Set up JDK 8 for Maven build uses: actions/setup-java@v1 with: - java-version: 19 + java-version: 8 # 完成java项目打包 - - name: build maven project + - name: Build Maven project run: mvn clean -U package -Dmaven.test.skip - - name: "build springcloud demo for linux/amd64" - uses: huaweicloud/swr-multiplatform-build-action@v1.0.0 + - name: Build Spring Cloud demo for linux/amd64 + uses: huaweicloud/swr-multiplatform-build-action@v1.1.0 with: image_tag: swr.cn-north-4.myhuaweicloud.com/hcloudcli/jdkdemo:jdk19-v1.0.0.4 \ No newline at end of file diff --git a/.github/workflows/build-springclouddemo-for-multiplatform.yml b/.github/workflows/build-springclouddemo-for-multiplatform.yml index 4d5f5534ddfcec381dcdda36855f94409101246a..e65c6ebfa7bca443c36b8ff238f9a689c7820b9c 100644 --- a/.github/workflows/build-springclouddemo-for-multiplatform.yml +++ b/.github/workflows/build-springclouddemo-for-multiplatform.yml @@ -1,4 +1,4 @@ -name: "commit-master" +name: Build Spring Cloud demo for multiplatform on: push: @@ -10,32 +10,32 @@ jobs: runs-on: ubuntu-latest steps: - - name: Check Out + - name: Checkout uses: actions/checkout@v2 - - name: Set up JDK 19 for maven build + - name: Set up JDK 8 for Maven build uses: actions/setup-java@v1 with: - java-version: 19 + java-version: 8 # 完成java项目打包 - - name: build maven project + - name: Build Maven project run: mvn clean -U package -Dmaven.test.skip # docker login,设置登陆到华为的swr - - name: Log in to HuaweiCloud SWR - uses: huaweicloud/swr-login@v1 + - name: Log in to Huawei Cloud SWR + uses: huaweicloud/swr-login@v2.0.0 with: - region: cn-north-4 - access-key-id: ${{ secrets.ACCESSKEY }} - access-key-secret: ${{ secrets.SECRETACCESSKEY }} + region: cn-north-4 + access-key-id: ${{ secrets.ACCESSKEY }} + access-key-secret: ${{ secrets.SECRETACCESSKEY }} # 设置 docker 环境 - name: Set up Docker Buildx id: buildx uses: docker/setup-buildx-action@v1 - - name: "build springcloud demo for linux/amd64,linux/arm64/v8,windows/amd64" - uses: huaweicloud/swr-multiplatform-build-action@v1.0.0 + - name: Build Spring Cloud demo for linux/amd64,linux/arm64/v8,windows/amd64 + uses: huaweicloud/swr-multiplatform-build-action@v1.1.0 with: image_tag: swr.cn-north-4.myhuaweicloud.com/hcloudcli/jdkdemo:jdk19-v1.0.0.4 platforms: linux/amd64,linux/arm64/v8,windows/amd64 diff --git a/Dockerfile b/Dockerfile index f1427192300508e70c4d08b207a1ee69d08135c7..9edf8cd04f73ccf48dfce84be4afca0225c11332 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,3 +1,3 @@ -FROM swr.cn-north-6.myhuaweicloud.com/codeci/maven:openjdk-19 +FROM openjdk:19-jdk ADD ./target/demoapp.jar /usr/local/ CMD [ "java", "-jar", "/usr/local/demoapp.jar" ] \ No newline at end of file diff --git a/LICENSE b/LICENSE index c281b50f52b3589a60e91858fb2debc058862f92..19dc35b2433851a0e8fd866a5d323b2ba18c12ed 100644 --- a/LICENSE +++ b/LICENSE @@ -1,21 +1,175 @@ -MIT License - -Copyright (c) 2022 米饭程序park - -Permission is hereby granted, free of charge, to any person obtaining a copy -of this software and associated documentation files (the "Software"), to deal -in the Software without restriction, including without limitation the rights -to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -copies of the Software, and to permit persons to whom the Software is -furnished to do so, subject to the following conditions: - -The above copyright notice and this permission notice shall be included in all -copies or substantial portions of the Software. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE -SOFTWARE. + + Apache License + Version 2.0, January 2004 + http://www.apache.org/licenses/ + + TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION + + 1. Definitions. + + "License" shall mean the terms and conditions for use, reproduction, + and distribution as defined by Sections 1 through 9 of this document. + + "Licensor" shall mean the copyright owner or entity authorized by + the copyright owner that is granting the License. + + "Legal Entity" shall mean the union of the acting entity and all + other entities that control, are controlled by, or are under common + control with that entity. For the purposes of this definition, + "control" means (i) the power, direct or indirect, to cause the + direction or management of such entity, whether by contract or + otherwise, or (ii) ownership of fifty percent (50%) or more of the + outstanding shares, or (iii) beneficial ownership of such entity. + + "You" (or "Your") shall mean an individual or Legal Entity + exercising permissions granted by this License. + + "Source" form shall mean the preferred form for making modifications, + including but not limited to software source code, documentation + source, and configuration files. + + "Object" form shall mean any form resulting from mechanical + transformation or translation of a Source form, including but + not limited to compiled object code, generated documentation, + and conversions to other media types. + + "Work" shall mean the work of authorship, whether in Source or + Object form, made available under the License, as indicated by a + copyright notice that is included in or attached to the work + (an example is provided in the Appendix below). + + "Derivative Works" shall mean any work, whether in Source or Object + form, that is based on (or derived from) the Work and for which the + editorial revisions, annotations, elaborations, or other modifications + represent, as a whole, an original work of authorship. For the purposes + of this License, Derivative Works shall not include works that remain + separable from, or merely link (or bind by name) to the interfaces of, + the Work and Derivative Works thereof. + + "Contribution" shall mean any work of authorship, including + the original version of the Work and any modifications or additions + to that Work or Derivative Works thereof, that is intentionally + submitted to Licensor for inclusion in the Work by the copyright owner + or by an individual or Legal Entity authorized to submit on behalf of + the copyright owner. For the purposes of this definition, "submitted" + means any form of electronic, verbal, or written communication sent + to the Licensor or its representatives, including but not limited to + communication on electronic mailing lists, source code control systems, + and issue tracking systems that are managed by, or on behalf of, the + Licensor for the purpose of discussing and improving the Work, but + excluding communication that is conspicuously marked or otherwise + designated in writing by the copyright owner as "Not a Contribution." + + "Contributor" shall mean Licensor and any individual or Legal Entity + on behalf of whom a Contribution has been received by Licensor and + subsequently incorporated within the Work. + + 2. Grant of Copyright License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + copyright license to reproduce, prepare Derivative Works of, + publicly display, publicly perform, sublicense, and distribute the + Work and such Derivative Works in Source or Object form. + + 3. Grant of Patent License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + (except as stated in this section) patent license to make, have made, + use, offer to sell, sell, import, and otherwise transfer the Work, + where such license applies only to those patent claims licensable + by such Contributor that are necessarily infringed by their + Contribution(s) alone or by combination of their Contribution(s) + with the Work to which such Contribution(s) was submitted. If You + institute patent litigation against any entity (including a + cross-claim or counterclaim in a lawsuit) alleging that the Work + or a Contribution incorporated within the Work constitutes direct + or contributory patent infringement, then any patent licenses + granted to You under this License for that Work shall terminate + as of the date such litigation is filed. + + 4. Redistribution. You may reproduce and distribute copies of the + Work or Derivative Works thereof in any medium, with or without + modifications, and in Source or Object form, provided that You + meet the following conditions: + + (a) You must give any other recipients of the Work or + Derivative Works a copy of this License; and + + (b) You must cause any modified files to carry prominent notices + stating that You changed the files; and + + (c) You must retain, in the Source form of any Derivative Works + that You distribute, all copyright, patent, trademark, and + attribution notices from the Source form of the Work, + excluding those notices that do not pertain to any part of + the Derivative Works; and + + (d) If the Work includes a "NOTICE" text file as part of its + distribution, then any Derivative Works that You distribute must + include a readable copy of the attribution notices contained + within such NOTICE file, excluding those notices that do not + pertain to any part of the Derivative Works, in at least one + of the following places: within a NOTICE text file distributed + as part of the Derivative Works; within the Source form or + documentation, if provided along with the Derivative Works; or, + within a display generated by the Derivative Works, if and + wherever such third-party notices normally appear. The contents + of the NOTICE file are for informational purposes only and + do not modify the License. You may add Your own attribution + notices within Derivative Works that You distribute, alongside + or as an addendum to the NOTICE text from the Work, provided + that such additional attribution notices cannot be construed + as modifying the License. + + You may add Your own copyright statement to Your modifications and + may provide additional or different license terms and conditions + for use, reproduction, or distribution of Your modifications, or + for any such Derivative Works as a whole, provided Your use, + reproduction, and distribution of the Work otherwise complies with + the conditions stated in this License. + + 5. Submission of Contributions. Unless You explicitly state otherwise, + any Contribution intentionally submitted for inclusion in the Work + by You to the Licensor shall be under the terms and conditions of + this License, without any additional terms or conditions. + Notwithstanding the above, nothing herein shall supersede or modify + the terms of any separate license agreement you may have executed + with Licensor regarding such Contributions. + + 6. Trademarks. This License does not grant permission to use the trade + names, trademarks, service marks, or product names of the Licensor, + except as required for reasonable and customary use in describing the + origin of the Work and reproducing the content of the NOTICE file. + + 7. Disclaimer of Warranty. Unless required by applicable law or + agreed to in writing, Licensor provides the Work (and each + Contributor provides its Contributions) on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + implied, including, without limitation, any warranties or conditions + of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A + PARTICULAR PURPOSE. You are solely responsible for determining the + appropriateness of using or redistributing the Work and assume any + risks associated with Your exercise of permissions under this License. + + 8. Limitation of Liability. In no event and under no legal theory, + whether in tort (including negligence), contract, or otherwise, + unless required by applicable law (such as deliberate and grossly + negligent acts) or agreed to in writing, shall any Contributor be + liable to You for damages, including any direct, indirect, special, + incidental, or consequential damages of any character arising as a + result of this License or out of the use or inability to use the + Work (including but not limited to damages for loss of goodwill, + work stoppage, computer failure or malfunction, or any and all + other commercial damages or losses), even if such Contributor + has been advised of the possibility of such damages. + + 9. Accepting Warranty or Additional Liability. While redistributing + the Work or Derivative Works thereof, You may choose to offer, + and charge a fee for, acceptance of support, warranty, indemnity, + or other liability obligations and/or rights consistent with this + License. However, in accepting such obligations, You may act only + on Your own behalf and on Your sole responsibility, not on behalf + of any other Contributor, and only if You agree to indemnify, + defend, and hold each Contributor harmless for any liability + incurred by, or claims asserted against, such Contributor by reason + of your accepting any such warranty or additional liability. \ No newline at end of file diff --git a/README.md b/README.md index 1a87f810e67645077c06ac4c8bb35d4113755b75..c207c8267fe4d1e604d8b78dca97fe4706ce2d52 100644 --- a/README.md +++ b/README.md @@ -1,5 +1,5 @@ # swr-multiplatform-build-action -允许用户构建跨平台镜像,如linux平台,windows平台或macos平台,并可以直接推送到SWR等Docker镜像仓库上 +允许用户构建跨平台镜像,如linux平台,windows平台或macos平台,并可以直接推送到SWR等Docker镜像仓库上 目前支持的平台列表如下 ```yaml 'linux/amd64', @@ -7,9 +7,11 @@ 'linux/ppc64le', 'linux/s390x', 'linux/386', + 'linux/arm/v5', 'linux/arm/v7', 'linux/arm/v6', 'linux/arm64/v8', + 'linux/mips64le', 'windows/amd64', 'windows/arm64', 'darwin/amd64', @@ -17,76 +19,78 @@ ``` ## **前置工作** -(1).如果项目代码需要打包,需要提前完成打包动作,并修改Dockerfile -(2).如果需要推送到SWR等Docker registry上,需要添加一个docker login的action,添加好登录账号密码等信息 -(3).需要确定基础镜像支持的平台,可以登录dockerhub官网查看 +(1) 如果项目代码需要打包,需要提前完成打包动作,并修改Dockerfile +(2) 如果需要推送到SWR等Docker registry上,需要添加一个docker login的action,添加好登录账号密码等信息 +(3) 需要确定基础镜像支持的平台,可以登录dockerhub官网查看 如19-jdk,支持windows/amd64,linux/amd64,linux/arm64/v8 这三个平台, ![avatar](./images/20220509-165318.jpg) ## **参数说明:** -image_tag:需要打包的docker镜像标签,必填,如 swr.cn-north-4.myhuaweicloud.com/hcloudcli/jdkdemo:jdk19-v1.0.0.4 -platforms: 当前需要打包支持的平台,用逗号隔开,如 linux/amd64,linux/arm64/v8,windows/amd64,非必填,如果不填写的话,会默认打包当前环境所在的平台,如ubuntu-latest所在的linux/amd64 -file: Dockerfile路径,默认为Dockerfile,如果在其他目录,则填写相对路径或者绝对路径,如 ./dockerfiles/Dockerfile -use_latest_buildx: 是否需要使用最新版本的docker buildx来构建docker镜像,如果为true,会比较当前安装的buildx和官方发布的最新版本,有差异的话会安装最新版本 -push: 是否需要将构建好的镜像推送到docker镜像仓库,如果填true,需要再前面增加一个docker login的 action完成镜像仓库的登录,在构建完成之后会自动推送到华为云SWR +| Name | Require | Default | Description | +| ------------ | ------- | ------- | ----------- | +| image_tag | true | | 需要打包的docker镜像标签,如:swr.cn-north-4.myhuaweicloud.com/hcloudcli/jdkdemo:jdk19-v1.0.0.4| +| platforms | false | | 当前需要打包支持的平台,用逗号隔开。如 linux/amd64,linux/arm64/v8,windows/amd64。如果不填写的话,会默认打包当前环境所在的平台,如ubuntu-latest所在的linux/amd64| +| file | false | | Dockerfile路径,默认为Dockerfile,如果在其他目录,则填写相对路径或者绝对路径,如 ./dockerfiles/Dockerfile| +| use_latest_buildx | false | false | 是否需要使用最新版本的docker buildx来构建docker镜像,如果为true,会比较当前安装的buildx和官方发布的最新版本,有差异的话会安装最新版本| +| push | true | false | 是否需要将构建好的镜像推送到docker镜像仓库,如果填true,需要再前面增加一个docker login的 action完成镜像仓库的登录,在构建完成之后会自动推送到华为云SWR| ## **使用样例** -### 1、简单样例,只构建代码和打包镜像 +### 1、简单样例,只构建代码和打包镜像 步骤说明如下 -(1)、完成jdk安装和java项目打包 -(2)、填写image_tag参数,镜像会工具当前环境所在的平台,打包出一个 linux/amd64的镜像 +(1) 完成jdk安装和java项目打包 +(2) 填写image_tag参数,镜像会工具当前环境所在的平台,打包出一个 linux/amd64的镜像 ```yaml # 安装JDK和maven - - name: Set up JDK 19 for maven build + - name: Set up JDK 8 for Maven build uses: actions/setup-java@v1 with: - java-version: 19 + java-version: 8 # 完成java项目打包 - - name: build maven project + - name: Build Maven project run: mvn clean -U package -Dmaven.test.skip # 完成docker镜像打包 - - name: "build springcloud demo for linux/amd64" - uses: huaweicloud/swr-multiplatform-build-action@v1.0.0 + - name: Build Spring Cloud demo for linux/amd64 + uses: huaweicloud/swr-multiplatform-build-action@v1.1.0 with: image_tag: swr.cn-north-4.myhuaweicloud.com/hcloudcli/jdkdemo:jdk19-v1.0.0.4 ``` -详情可参考 ./github/workflow/build-local-for-test.yml +详情可参考 [./github/workflows/build-simple-demo.yml](.github/workflows/build-simple-demo.yml) -### 2、普通样例,完成镜像的windows和linux平台构建,并上传到swr +### 2、普通样例,完成镜像的windows和linux平台构建,并上传到swr 步骤说明如下 -(1)、完成jdk安装和java项目打包 -(2)、设置docker login,填写AK和SK,完成华为云SWR容器镜像服务的登录 -(3)、设置docker buildx,可以选配,插件会检查当前环境是否安装了docker buildx,如果没有的话,会自动安装 -(4)、登录doocker hub,查看openjdk镜像,可以看到openjdk:19-jdk 支持 linux/amd64,linux/arm64/v8,windows/amd64三个平台,因此platforms参数可以填写这三个中的一个或多个,也可以填写全部。push参数填写为true,即打包完之后就push到华为云SWR +(1) 完成jdk安装和java项目打包 +(2) 设置docker login,填写AK和SK,完成华为云SWR容器镜像服务的登录 +(3) 设置docker buildx,可以选配,插件会检查当前环境是否安装了docker buildx,如果没有的话,会自动安装 +(4) 登录doocker hub,查看openjdk镜像,可以看到openjdk:19-jdk 支持 linux/amd64,linux/arm64/v8,windows/amd64三个平台,因此platforms参数可以填写这三个中的一个或多个,也可以填写全部。push参数填写为true,即打包完之后就push到华为云SWR ![avatar](./images/20220509-165318.jpg) ```yaml # 安装JDK和maven - - name: Set up JDK 19 for maven build + - name: Set up JDK 8 for Maven build uses: actions/setup-java@v1 with: - java-version: 19 + java-version: 8 # 完成java项目打包 - - name: build maven project + - name: Build Maven project run: mvn clean -U package -Dmaven.test.skip # docker login,设置登陆到华为的swr - - name: Log in to HuaweiCloud SWR - uses: huaweicloud/swr-login@v1 + - name: Log in to Huawei Cloud SWR + uses: huaweicloud/swr-login@v2.0.0 with: - region: cn-north-4 - access-key-id: ${{ secrets.ACCESSKEY }} - access-key-secret: ${{ secrets.SECRETACCESSKEY }} + region: cn-north-4 + access-key-id: ${{ secrets.ACCESSKEY }} + access-key-secret: ${{ secrets.SECRETACCESSKEY }} # 设置 docker 环境 - name: Set up Docker Buildx id: buildx uses: docker/setup-buildx-action@v1 - # 完成docker镜像打包,支持linux/amd64,linux/arm64/v8,windows/amd64三个平台 - - name: "build springcloud demo for linux/amd64,linux/arm64/v8,windows/amd64" - uses: huaweicloud/swr-multiplatform-build-action@v1.0.0 + # 完成docker镜像打包,支持linux/amd64,linux/arm64/v8,windows/amd64三个平台 + - name: Build Spring Cloud demo for linux/amd64,linux/arm64/v8,windows/amd64 + uses: huaweicloud/swr-multiplatform-build-action@v1.1.0 with: image_tag: swr.cn-north-4.myhuaweicloud.com/hcloudcli/jdkdemo:jdk19-v1.0.0.4 platforms: linux/amd64,linux/arm64/v8,windows/amd64 @@ -94,25 +98,26 @@ push: 是否需要将构建好的镜像推送到docker镜像仓库,如果填tr push: true file: ./Dockerfile ``` -详情可参考 ./github/workflow/build-springclouddemo-for-multiplatform.yml -### 3、复杂样例,完成镜像的复杂多平台构建,并上传到swr +详情可参考 [.github/workflows/build-springclouddemo-for-multiplatform.yml](.github/workflows/build-springclouddemo-for-multiplatform.yml) + +### 3、复杂样例,完成镜像的复杂多平台构建,并上传到swr 步骤说明如下 -(1)、设置docker login,填写AK和SK,完成华为云SWR容器镜像服务的登录 -(2)、登录doocker hub,查看openjdk镜像,可以看到openjdk:19-jdk 支持 linux/386,linux/amd64,linux/arm/v5,linux/arm/v7,linux/arm64/v8,linux/mips64le,linux/ppc64le,linux/s390x 平台,因此platforms参数可以填写些平台中的一个或多个,也可以填写全部。push参数填写为true,即打包完之后就push到华为云SWR -(3)、file参数指定Dockerfile的路径,此处为./dockerfiles/Dockerfile-nginx +(1) 设置docker login,填写AK和SK,完成华为云SWR容器镜像服务的登录 +(2) 登录doocker hub,查看openjdk镜像,可以看到openjdk:19-jdk 支持 linux/386,linux/amd64,linux/arm/v5,linux/arm/v7,linux/arm64/v8,linux/mips64le,linux/ppc64le,linux/s390x 平台,因此platforms参数可以填写些平台中的一个或多个,也可以填写全部。push参数填写为true,即打包完之后就push到华为云SWR +(3) file参数指定Dockerfile的路径,此处为./dockerfiles/Dockerfile-nginx ![avatar](./images/nginx-multiplatform.png) ```yaml # docker login,设置登陆到华为的swr - - name: Log in to HuaweiCloud SWR - uses: huaweicloud/swr-login@v1 + - name: Log in to Huawei Cloud SWR + uses: huaweicloud/swr-login@v2.0.0 with: - region: cn-north-4 - access-key-id: ${{ secrets.ACCESSKEY }} - access-key-secret: ${{ secrets.SECRETACCESSKEY }} + region: cn-north-4 + access-key-id: ${{ secrets.ACCESSKEY }} + access-key-secret: ${{ secrets.SECRETACCESSKEY }} - # 完成docker镜像打包,支持多个平台 - - name: "build nginx image for linux/386,linux/amd64,linux/arm/v5,linux/arm/v7,linux/arm64/v8,linux/mips64le,linux/ppc64le,linux/s390x" - uses: huaweicloud/swr-multiplatform-build-action@v1.0.0 + # 完成docker镜像打包,支持多个平台 + - name: Build Nginx image for linux/386,linux/amd64,linux/arm/v5,linux/arm/v7,linux/arm64/v8,linux/mips64le,linux/ppc64le,linux/s390x + uses: huaweicloud/swr-multiplatform-build-action@v1.1.0 with: image_tag: swr.cn-north-4.myhuaweicloud.com/hcloudcli/nginx:nginx-12-v1.0.0.1 platforms: linux/386,linux/amd64,linux/arm/v5,linux/arm/v7,linux/arm64/v8,linux/mips64le,linux/ppc64le,linux/s390x @@ -120,11 +125,10 @@ push: 是否需要将构建好的镜像推送到docker镜像仓库,如果填tr push: true file: ./dockerfiles/Dockerfile-nginx ``` - 详情可参考 ./github/workflow/build-nginx-for-multiplatform.yml - + 详情可参考 [.github/workflows/build-nginx-for-multiplatform.yml](.github/workflows/build-nginx-for-multiplatform.yml) ## **打包查看结果** ### 1、jdkdemo:jdk19-v1.0.0.4镜像 -登录华为云SWR服务,查看hcloudcli/jdkdemo:jdk19-v1.0.0.4镜像的manifast内容 +登录华为云SWR服务,查看hcloudcli/jdkdemo:jdk19-v1.0.0.4镜像的manifast内容 ```yaml digest: sha256:e4090ef801d8240bf6dc0ff878a39cad98eaf1e811cf8a4307171588065d291c manifest详情: @@ -154,16 +158,16 @@ manifests: ![avatar](./images/20220509-194824.png) ### **镜像使用:** - 在linunx或者windows的x86-64平台或者linux的arm-64平台,直接docker pull这个镜像,docker会自动下载对应平台的镜像 -#### (1)、linux x86-64平台 + 在linunx或者windows的x86-64平台或者linux的arm-64平台,直接docker pull这个镜像,docker会自动下载对应平台的镜像 +#### (1) linux x86-64平台 ![avatar](./images/20220510-094740.png) -#### (2)、linux arm-64平台: +#### (2) linux arm-64平台: ![avatar](./images/20220509-195911.png) -#### (3)、windows x86-64平台 +#### (3) windows x86-64平台 ![avatar](./images/20220510-085854.png) ### 2、nginx:nginx-12-v1.0.0.1镜像 - 登录华为云SWR服务,查看hcloudcli/nginx:nginx-12-v1.0.0.1镜像的manifast内容 + 登录华为云SWR服务,查看hcloudcli/nginx:nginx-12-v1.0.0.1镜像的manifast内容 ```yaml manifest详情: mediaType: application/vnd.docker.distribution.manifest.list.v2+json