From e65c2ca3c9da5c7c27e790cec3e4223e609dbf5f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=B6=B5=E6=9B=A6?= Date: Wed, 30 Oct 2024 19:51:10 +0800 Subject: [PATCH] =?UTF-8?q?build:=20=E9=95=9C=E5=83=8F=E7=BC=96=E8=AF=91?= =?UTF-8?q?=E4=BC=98=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .github/workflows/build-base-image.yml | 8 +-- .github/workflows/ci.yml | 71 ++++++++++++++------------ .github/workflows/release.yml | 7 +-- Dockerfile | 7 ++- 4 files changed, 44 insertions(+), 49 deletions(-) diff --git a/.github/workflows/build-base-image.yml b/.github/workflows/build-base-image.yml index ed2c67d..7b2223d 100644 --- a/.github/workflows/build-base-image.yml +++ b/.github/workflows/build-base-image.yml @@ -14,9 +14,6 @@ jobs: build-image: runs-on: ubuntu-latest if: github.event_name != 'pull_request' - strategy: - matrix: - platform: [linux/amd64, linux/arm64, linux/arm/v7] steps: - uses: actions/checkout@v4 - name: Set up QEMU @@ -37,8 +34,6 @@ jobs: platforms: linux/amd64, linux/arm64, linux/arm/v7 push: true tags: ${{ secrets.DOCKERHUB_USERNAME }}/xiaomusic:${{ github.ref_name }}, ${{ secrets.DOCKERHUB_USERNAME }}/xiaomusic:runtime - cache-from: type=local,src=/tmp/.buildx-cache - cache-to: type=local,dest=/tmp/.buildx-cache-new - name: Build and push builder uses: docker/build-push-action@v4 @@ -48,5 +43,4 @@ jobs: platforms: linux/amd64, linux/arm64, linux/arm/v7 push: true tags: ${{ secrets.DOCKERHUB_USERNAME }}/xiaomusic:${{ github.ref_name }}, ${{ secrets.DOCKERHUB_USERNAME }}/xiaomusic:builder - cache-from: type=local,src=/tmp/.buildx-cache - cache-to: type=local,dest=/tmp/.buildx-cache-new + diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index bc263f2..f79d6d3 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -10,12 +10,9 @@ jobs: build-test-publish: runs-on: ubuntu-latest if: github.event_name != 'pull_request' - strategy: - matrix: - platform: [linux/amd64, linux/arm64, linux/arm/v7] steps: - uses: actions/checkout@v4 - + - name: Set up QEMU uses: docker/setup-qemu-action@v3 @@ -28,54 +25,64 @@ jobs: username: ${{ secrets.DOCKERHUB_USERNAME }} password: ${{ secrets.DOCKERHUB_TOKEN }} - - name: Set tags name - id: gen_tag_name - env: - IMAGE_NAME: ${{ env.TEST_TAG }} - PLATFORM_NAME: ${{ matrix.platform }} - run: | - echo "TAGNAME=${IMAGE_NAME}-${PLATFORM_NAME//\//-}" >> $GITHUB_ENV - - - name: Build Docker image + - name: Build Docker image (linux/amd64) uses: docker/build-push-action@v6 with: - platforms: ${{ matrix.platform }} + platforms: linux/amd64 context: . - file: ./Dockerfile push: false load: true - tags: ${{ env.TAGNAME }} + tags: ${{ env.TEST_TAG }}-linux-amd64 cache-from: type=local,src=/tmp/.buildx-cache cache-to: type=local,dest=/tmp/.buildx-cache-new - - name: Test Docker image - run: docker run --rm ${{ env.TAGNAME }} -h + - name: Build Docker image (linux/arm64) + uses: docker/build-push-action@v6 + with: + platforms: linux/arm64 + context: . + push: false + load: true + tags: ${{ env.TEST_TAG }}-linux-arm64 + cache-from: type=local,src=/tmp/.buildx-cache + cache-to: type=local,dest=/tmp/.buildx-cache-new + - name: Build Docker image (linux/arm/v7) + uses: docker/build-push-action@v6 + with: + platforms: linux/arm/v7 + context: . + push: false + load: true + tags: ${{ env.TEST_TAG }}-linux-arm-v7 + cache-from: type=local,src=/tmp/.buildx-cache + cache-to: type=local,dest=/tmp/.buildx-cache-new + + # We test all the images on amd64 host here. This uses QEMU to emulate + # the other platforms. + - run: docker run --rm ${TEST_TAG}-linux-amd64 -h + - run: docker run --rm ${TEST_TAG}-linux-arm64 -h + - run: docker run --rm ${TEST_TAG}-linux-arm-v7 -h + + # This will only push the previously built images. - name: Publish to Docker Hub uses: docker/build-push-action@v6 with: - platforms: linux/amd64, linux/arm64, linux/arm/v7 + platforms: linux/amd64,linux/arm64,linux/arm/v7 context: . - file: ./Dockerfile push: true tags: ${{ env.TEST_TAG }} - cache-from: type=local,src=/tmp/.buildx-cache + cache-from: type=local,src=/tmp/.buildx-cache-new cache-to: type=local,dest=/tmp/.buildx-cache-new - publish-readme: - runs-on: ubuntu-latest - needs: build-test-publish - steps: - - uses: actions/checkout@v4 - - name: Login to Docker Hub - uses: docker/login-action@v3 - with: - username: ${{ secrets.DOCKERHUB_USERNAME }} - password: ${{ secrets.DOCKERHUB_TOKEN }} - - name: Docker Hub Description uses: peter-evans/dockerhub-description@v4 with: username: ${{ secrets.DOCKERHUB_USERNAME }} password: ${{ secrets.DOCKERHUB_TOKEN }} repository: hanxi/xiaomusic + + - name: Move cache to limit growth + run: | + rm -rf /tmp/.buildx-cache + mv /tmp/.buildx-cache-new /tmp/.buildx-cache diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index cc96b16..d508e22 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -40,9 +40,6 @@ jobs: runs-on: ubuntu-latest # run unless event type is pull_request if: github.event_name != 'pull_request' - strategy: - matrix: - platform: [linux/amd64, linux/arm64, linux/arm/v7] steps: - uses: actions/checkout@v3 - name: Set up QEMU @@ -58,8 +55,6 @@ jobs: uses: docker/build-push-action@v4 with: context: . - platforms: ${{ matrix.platform }} + platforms: linux/amd64, linux/arm64, linux/arm/v7 push: true tags: ${{ secrets.DOCKERHUB_USERNAME }}/xiaomusic:${{ github.ref_name }}, ${{ secrets.DOCKERHUB_USERNAME }}/xiaomusic:latest, ${{ secrets.DOCKERHUB_USERNAME }}/xiaomusic:stable - cache-from: type=local,src=/tmp/.buildx-cache - cache-to: type=local,dest=/tmp/.buildx-cache-new diff --git a/Dockerfile b/Dockerfile index 01978bb..84256b1 100644 --- a/Dockerfile +++ b/Dockerfile @@ -10,12 +10,11 @@ COPY xiaomusic.py . RUN pdm install --prod --no-editable FROM hanxi/xiaomusic:runtime - WORKDIR /app COPY --from=builder /app/.venv /app/.venv -COPY xiaomusic/ ./xiaomusic/ -COPY plugins/ ./plugins/ -COPY xiaomusic.py . +COPY --from=builder /app/xiaomusic/ ./xiaomusic/ +COPY --from=builder /app/plugins/ ./plugins/ +COPY --from=builder /app/xiaomusic.py . ENV XIAOMUSIC_HOSTNAME=192.168.2.5 ENV XIAOMUSIC_PORT=8090 VOLUME /app/conf