构建镜像并推送 Docker Hub v0.1.2-dev (linux/amd64) #5
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| name: build-and-push | |
| run-name: 构建镜像并推送 Docker Hub ${{ github.event.inputs.dockerImageTag }} (${{ github.event.inputs.architecture }}) | |
| on: | |
| workflow_dispatch: | |
| inputs: | |
| dockerImageTag: | |
| description: 'Image Tag' | |
| default: 'v0.1.0-dev' | |
| required: true | |
| dockerImageTagWithLatest: | |
| description: '是否发布latest tag(正式发版时选择,测试版本切勿选择)' | |
| default: false | |
| required: true | |
| type: boolean | |
| architecture: | |
| description: 'Architecture' | |
| required: true | |
| default: 'linux/amd64' | |
| type: choice | |
| options: | |
| - linux/amd64 | |
| - linux/arm64 | |
| - linux/amd64,linux/arm64 | |
| dockerhubAccount: | |
| description: 'Docker Hub account' | |
| default: 'testing' | |
| required: true | |
| type: choice | |
| options: | |
| - testing | |
| - production | |
| env: | |
| CLAW_TEAM_BASE_IMAGE: ghcr.io/1panel-dev/claw-team-base:python3.12-20260401 | |
| jobs: | |
| build-and-push-to-dockerhub: | |
| runs-on: ubuntu-latest | |
| steps: | |
| - name: Clear Work Dir | |
| run: | | |
| ls -la | |
| rm -rf -- ./* ./.??* | |
| - name: Checkout | |
| uses: actions/checkout@v6 | |
| with: | |
| ref: ${{ github.ref_name }} | |
| - name: Prepare | |
| id: prepare | |
| run: | | |
| if [[ "${{ github.event.inputs.dockerhubAccount }}" == "testing" ]]; then | |
| DOCKER_NAMESPACE="${{ secrets.DOCKERHUB_USERNAME_PERSONAL }}" | |
| else | |
| DOCKER_NAMESPACE="${{ secrets.DOCKERHUB_USERNAME }}" | |
| fi | |
| DOCKER_IMAGE=${DOCKER_NAMESPACE}/claw-team | |
| DOCKER_PLATFORMS=${{ github.event.inputs.architecture }} | |
| TAG_NAME=${{ github.event.inputs.dockerImageTag }} | |
| TAG_NAME_WITH_LATEST=${{ github.event.inputs.dockerImageTagWithLatest }} | |
| if [[ ${TAG_NAME_WITH_LATEST} == 'true' ]]; then | |
| DOCKER_IMAGE_TAGS="--tag ${DOCKER_IMAGE}:${TAG_NAME} --tag ${DOCKER_IMAGE}:${TAG_NAME%%.*} --tag ${DOCKER_IMAGE}:latest" | |
| else | |
| DOCKER_IMAGE_TAGS="--tag ${DOCKER_IMAGE}:${TAG_NAME}" | |
| fi | |
| echo "buildx_args=--platform ${DOCKER_PLATFORMS} --memory-swap -1 \ | |
| --build-arg BASE_IMAGE=${CLAW_TEAM_BASE_IMAGE} \ | |
| --build-arg DOCKER_IMAGE_TAG=${{ github.event.inputs.dockerImageTag }} \ | |
| --build-arg BUILD_AT=$(TZ=Asia/Shanghai date +'%Y-%m-%dT%H:%M') \ | |
| --build-arg GITHUB_COMMIT=$(git rev-parse --short HEAD) \ | |
| --no-cache \ | |
| ${DOCKER_IMAGE_TAGS} ." >> "$GITHUB_OUTPUT" | |
| - name: Set up QEMU | |
| uses: docker/setup-qemu-action@v3 | |
| with: | |
| cache-image: false | |
| - name: Set up Docker Buildx | |
| uses: docker/setup-buildx-action@v3 | |
| - name: Login to GitHub Container Registry | |
| uses: docker/login-action@v3 | |
| with: | |
| registry: ghcr.io | |
| username: ${{ github.actor }} | |
| password: ${{ secrets.GH_TOKEN }} | |
| - name: Login to Docker Hub | |
| if: ${{ github.event.inputs.dockerhubAccount == 'testing' }} | |
| uses: docker/login-action@v3 | |
| with: | |
| username: ${{ secrets.DOCKERHUB_USERNAME_PERSONAL }} | |
| password: ${{ secrets.DOCKERHUB_TOKEN_PERSONAL }} | |
| - name: Login to Docker Hub (production) | |
| if: ${{ github.event.inputs.dockerhubAccount == 'production' }} | |
| uses: docker/login-action@v3 | |
| with: | |
| username: ${{ secrets.DOCKERHUB_USERNAME }} | |
| password: ${{ secrets.DOCKERHUB_TOKEN }} | |
| - name: Build Web | |
| run: | | |
| docker buildx build --no-cache --target web-build --output type=local,dest=./web-build-output . -f Dockerfile | |
| rm -rf ./web-client/dist | |
| mkdir -p ./web-client | |
| cp -r ./web-build-output/web-client/dist ./web-client/ | |
| rm -rf ./web-build-output | |
| - name: Docker Buildx (build-and-push) | |
| run: | | |
| sudo sync && echo 3 | sudo tee /proc/sys/vm/drop_caches && free -m | |
| docker buildx build --output "type=image,push=true" \ | |
| ${{ steps.prepare.outputs.buildx_args }} \ | |
| -f Dockerfile |