From b0a807b82c161f0baa2548b6935c25590aa2acc0 Mon Sep 17 00:00:00 2001 From: wy580477 <98247050+wy580477@users.noreply.github.com> Date: Sun, 30 Jun 2024 21:58:59 +0800 Subject: [PATCH] :construction_worker: CI: auto build (#81) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 为 Alpine 容器清空 pip cache 并自动构建 alpine 容器 --- .github/workflows/Docker-alpine.yml | 78 +++++++++++++++++++++++++++++ Dockerfile.alpine | 1 + 2 files changed, 79 insertions(+) create mode 100644 .github/workflows/Docker-alpine.yml diff --git a/.github/workflows/Docker-alpine.yml b/.github/workflows/Docker-alpine.yml new file mode 100644 index 0000000..8a4201d --- /dev/null +++ b/.github/workflows/Docker-alpine.yml @@ -0,0 +1,78 @@ +name: Docker_alpine + +# This workflow uses actions that are not certified by GitHub. +# They are provided by a third-party and are governed by +# separate terms of service, privacy policy, and support +# documentation. + +on: + push: + branches: [ development ] + +env: + # Use docker.io for Docker Hub if empty + REGISTRY: ghcr.io + # github.repository as / + IMAGE_NAME: ${{ github.repository }} + + +jobs: + build: + + runs-on: ubuntu-latest + permissions: + contents: read + packages: write + # This is used to complete the identity challenge + # with sigstore/fulcio when running outside of PRs. + id-token: write + + steps: + - name: Pull Repo + run: | + git clone --branch $GITHUB_REF_NAME --depth 1 https://github.com/${GITHUB_REPOSITORY} repo + + - name: Set up QEMU + uses: docker/setup-qemu-action@v3 + with: + platforms: all + + - name: Setup Docker buildx + uses: docker/setup-buildx-action@v3 + + # Login against a Docker registry except on PR + # https://github.com/docker/login-action + - name: Log into registry ${{ env.REGISTRY }} + if: github.event_name != 'pull_request' + uses: docker/login-action@v3 + with: + registry: ${{ env.REGISTRY }} + username: ${{ github.actor }} + password: ${{ secrets.GITHUB_TOKEN }} + + # Extract metadata (tags, labels) for Docker + # https://github.com/docker/metadata-action + - name: Extract Docker metadata + id: meta + uses: docker/metadata-action@v5 + with: + images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }} + flavor: | + latest=false + tags: | + type=edge,suffix=-alpine,branch=development + type=sha,suffix=-alpine + + # Build and push Docker image with Buildx (don't push on PR) + # https://github.com/docker/build-push-action + - name: Build and push Docker image + id: build-and-push + uses: docker/build-push-action@v6 + with: + builder: ${{ steps.buildx.outputs.name }} + context: ./repo + file: ./repo/Dockerfile.alpine + platforms: linux/amd64,linux/arm64 + push: true + tags: ${{ steps.meta.outputs.tags }} + labels: ${{ steps.meta.outputs.labels }} \ No newline at end of file diff --git a/Dockerfile.alpine b/Dockerfile.alpine index ae92f92..ba4b990 100644 --- a/Dockerfile.alpine +++ b/Dockerfile.alpine @@ -12,6 +12,7 @@ RUN apk add --no-cache git bash imagemagick libmagic curl tzdata neofetch libzba && apk add --no-cache --update --virtual .build-deps gcc python3-dev musl-dev linux-headers \ && git config --global pull.ff only \ && pip install -r requirements.txt \ + && pip cache purge \ && apk del .build-deps ENTRYPOINT ["tini","--","bash","utils/docker-config.sh"] \ No newline at end of file