From 8c67d3c58f2c44519284b08c88389c234bd9cbcf Mon Sep 17 00:00:00 2001 From: crosscc <37495419+q123458384@users.noreply.github.com> Date: Fri, 31 Mar 2023 16:22:20 +0800 Subject: [PATCH] Create build_docker_image.yml MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 利用github action 自动构建docker镜像: ## 1、 `workflow_dispatch:` 是需要作者在action手动点击进行构建 ``` release: types: [published] ``` 这个是发布release的时候自动构建镜像。根据作者需求启用或者删除注释掉 ## 2、 `tag: latest,${{ steps.get_version.outputs.VERSION }}`是可以镜像打标为latest和release发布的版本号 ## 3、 docker hub userid 在setting创建secrets, name=DOCKER_USERNAME value=dockerid docker hub password,在setting创建secrets, name=DOCKER_PASSWORD value=dockerpassword 这样作者就不用在自己机器上构建docker镜像,利用action 自动完成全平台镜像 速度也快。 --- .github/workflows/build_docker_image.yml | 29 ++++++++++++++++++++++++ 1 file changed, 29 insertions(+) create mode 100644 .github/workflows/build_docker_image.yml diff --git a/.github/workflows/build_docker_image.yml b/.github/workflows/build_docker_image.yml new file mode 100644 index 0000000..139add8 --- /dev/null +++ b/.github/workflows/build_docker_image.yml @@ -0,0 +1,29 @@ +name: Build Image +on: + #防止fork乱用action设置只能手动触发构建 + workflow_dispatch: + ## 发布release的时候会自动构建 + release: + types: [published] +jobs: + build: + runs-on: ubuntu-latest + name: Build image job + + steps: + - name: Checkout master + uses: actions/checkout@master + - name: Get version + id: get_version + if: startsWith(github.ref, 'refs/tags/') && startsWith(github.repository, 'RockChinQ/QChatGPT') + run: echo ::set-output name=VERSION::${GITHUB_REF/refs\/tags\//} + - name: Build and publish image + uses: ilteoood/docker_buildx@master + if: startsWith(github.ref, 'refs/tags/') && startsWith(github.repository, 'RockChinQ/QChatGPT') + with: + publish: true + imageName: mikumifa/qchatgpt-docker # dockerid/imageName + platform: linux/386,linux/arm64,linux/amd64,linux/arm/v6,linux/arm/v7 # 你准备构建的镜像平台 + tag: latest,${{ steps.get_version.outputs.VERSION }} + dockerUser: ${{ secrets.DOCKER_USERNAME }} # docker hub userid 在setting创建secrets name=DOCKER_USERNAME value=dockerid + dockerPassword: ${{ secrets.DOCKER_PASSWORD }} # docker hub password,在setting创建secrets name=DOCKER_PASSWORD value=dockerpassword