From 6b7033c3b8fa46892ad3ae94a0e9ff503a4b2769 Mon Sep 17 00:00:00 2001 From: lleans Date: Sun, 28 Jul 2024 10:34:20 +0700 Subject: [PATCH] =?UTF-8?q?=F0=9F=91=B7=20Fix=20build=20bug?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .github/workflows/build-image.yml | 100 ++++++++++++++++++------------ Dockerfile | 8 +-- 2 files changed, 64 insertions(+), 44 deletions(-) diff --git a/.github/workflows/build-image.yml b/.github/workflows/build-image.yml index 4f3870b..428b773 100644 --- a/.github/workflows/build-image.yml +++ b/.github/workflows/build-image.yml @@ -8,29 +8,38 @@ on: release: types: - published - tags: - - 'v*.*.*' + +env: + REGISTRY_IMAGE: ${{ secrets.DOCKERHUB_USERNAME }}/${{ secrets.DOCKERHUB_IMAGE }} + EVENT: ${{ github.event_name }} jobs: - build-dev: - if: github.event_name == 'push' + build: runs-on: ubuntu-latest - env: - DOCKER_IMAGE: ${{ secrets.DOCKERHUB_USERNAME }}/${{ secrets.DOCKERHUB_IMAGE }} - + strategy: + fail-fast: false + matrix: + platform: + - linux/amd64 + - linux/arm64 steps: - - name: Checkout to specific branch + - name: Checkout uses: actions/checkout@v4 with: - ref: "fast-api" + ref: fast-api + sparse-checkout: | + MuslimProScrapper + + - name: Prepare + run: | + platform=${{ matrix.platform }} + echo "PLATFORM_PAIR=${platform//\//-}" >> $GITHUB_ENV - name: Docker meta id: meta uses: docker/metadata-action@v5 with: - images: ${{ env.DOCKER_IMAGE }} - tags: | - type=raw,value=dev + images: ${{ env.REGISTRY_IMAGE }} - name: Set up QEMU uses: docker/setup-qemu-action@v3 @@ -38,43 +47,55 @@ jobs: - name: Set up Docker Buildx uses: docker/setup-buildx-action@v3 - - name: Login to Docker Hub | Stable + - name: Login to Docker Hub uses: docker/login-action@v3 with: username: ${{ secrets.DOCKERHUB_USERNAME }} password: ${{ secrets.DOCKERHUB_TOKEN }} - - name: Build and push | dev + - name: Build and push by digest + id: build uses: docker/build-push-action@v6 with: - context: . - platforms: linux/amd64,linux/arm64/v8 - push: true - tags: ${{ steps.meta.outputs.tags }} + platforms: ${{ matrix.platform }} labels: ${{ steps.meta.outputs.labels }} + outputs: type=image,name=${{ env.REGISTRY_IMAGE }},push-by-digest=true,name-canonical=true,push=true build-args: | INSTALL_BUILD_TOOLS=${{ matrix.platform == 'linux/arm64' && 'true' || 'false' }} - build-release: - if: github.event_name == 'release' - runs-on: ubuntu-latest - env: - DOCKER_IMAGE: ${{ secrets.DOCKERHUB_USERNAME }}/${{ secrets.DOCKERHUB_IMAGE }} + - name: Export digest + run: | + mkdir -p /tmp/digests + digest="${{ steps.build.outputs.digest }}" + touch "/tmp/digests/${digest#sha256:}" + + - name: Upload digest + uses: actions/upload-artifact@v4 + with: + name: digests-${{ env.PLATFORM_PAIR }} + path: /tmp/digests/* + if-no-files-found: error + retention-days: 1 + merge: + runs-on: ubuntu-latest + needs: + - build steps: - - name: Checkout to specific branch - uses: actions/checkout@v4 + - name: Download digests + uses: actions/download-artifact@v4 with: - ref: "fast-api" + path: /tmp/digests + pattern: digests-* + merge-multiple: true - name: Docker meta id: meta uses: docker/metadata-action@v5 with: - images: ${{ env.DOCKER_IMAGE }} + images: ${{ env.REGISTRY_IMAGE }} tags: | - type=semver,pattern={{version}} - type=semver,pattern={{major}}.{{minor}} + ${{ env.EVENT == 'release' && 'type=semver,pattern={{version}}\ntype=semver,pattern={{major}}.{{minor}}' || 'type=raw,value=dev' }} - name: Set up QEMU uses: docker/setup-qemu-action@v3 @@ -82,19 +103,18 @@ jobs: - name: Set up Docker Buildx uses: docker/setup-buildx-action@v3 - - name: Login to Docker Hub | Stable + - name: Login to Docker Hub uses: docker/login-action@v3 with: username: ${{ secrets.DOCKERHUB_USERNAME }} password: ${{ secrets.DOCKERHUB_TOKEN }} - - name: Build and push | Stable - uses: docker/build-push-action@v6 - with: - context: . - platforms: linux/amd64,linux/arm64/v8 - push: true - tags: ${{ steps.meta.outputs.tags }} - labels: ${{ steps.meta.outputs.labels }} - build-args: | - INSTALL_BUILD_TOOLS=${{ matrix.platform == 'linux/arm64' && 'true' || 'false' }} \ No newline at end of file + - name: Create manifest list and push + working-directory: /tmp/digests + run: | + docker buildx imagetools create $(jq -cr '.tags | map("-t " + .) | join(" ")' <<< "$DOCKER_METADATA_OUTPUT_JSON") \ + $(printf '${{ env.REGISTRY_IMAGE }}@sha256:%s ' *) + + - name: Inspect image and push + run: | + docker buildx imagetools inspect ${{ env.REGISTRY_IMAGE }}:${{ steps.meta.outputs.version }} diff --git a/Dockerfile b/Dockerfile index c4794f3..eaaf43a 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,5 +1,5 @@ # Stage 1: Build stage -FROM --platform=$BUILDPLATFORM python:3.12-alpine as builder +FROM python:3.12-alpine as builder # Define build argument ARG INSTALL_BUILD_TOOLS=false @@ -16,10 +16,10 @@ COPY requirements.txt . # Install Python dependencies RUN pip install --upgrade pip && \ - pip install --user -r requirements.txt + pip install --user -Ur requirements.txt --no-dependencies # Stage 2: Runtime stage -FROM --platform=$BUILDPLATFORM python:3.12-alpine +FROM python:3.12-alpine WORKDIR /app @@ -30,4 +30,4 @@ COPY . . # Update PATH to include pip-installed packages ENV PATH=/root/.local/bin:$PATH -ENTRYPOINT ["python3", "router.py"] +CMD ["python", "router.py"]