feat: update Dockerfiles and add zod dependency for improved package … #381
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 ALL-in-ONE Docker Image | |
| on: | |
| push: | |
| branches: | |
| - main | |
| - dev | |
| tags: | |
| - "v*" | |
| pull_request: | |
| branches: | |
| - main | |
| - dev | |
| env: | |
| REGISTRY: ghcr.io | |
| IMAGE_NAME: ${{ github.repository_owner }}/anycrawl | |
| jobs: | |
| build: | |
| runs-on: ubuntu-latest | |
| strategy: | |
| fail-fast: false | |
| matrix: | |
| include: | |
| - platform: linux/amd64 | |
| enable_puppeteer: "true" | |
| suffix: "amd64" | |
| - platform: linux/arm64 | |
| enable_puppeteer: "false" | |
| suffix: "arm64" | |
| permissions: | |
| contents: read | |
| packages: write | |
| steps: | |
| - name: Checkout repository | |
| uses: actions/checkout@v4 | |
| - name: Set up Docker Buildx | |
| uses: docker/setup-buildx-action@v3 | |
| - name: Log in to Container Registry | |
| uses: docker/login-action@v3 | |
| with: | |
| registry: ${{ env.REGISTRY }} | |
| username: ${{ github.actor }} | |
| password: ${{ secrets.GITHUB_TOKEN }} | |
| - name: Extract version | |
| id: version | |
| run: | | |
| if [[ $GITHUB_REF == refs/tags/* ]]; then | |
| # Tag push: create version tags, and latest only for v* tags | |
| VERSION=${GITHUB_REF#refs/tags/} | |
| echo "VERSION=$VERSION" >> $GITHUB_OUTPUT | |
| if [[ $VERSION == v* ]]; then | |
| echo "TAGS=${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:latest-${{ matrix.suffix }},${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:${VERSION}-${{ matrix.suffix }}" >> $GITHUB_OUTPUT | |
| else | |
| echo "TAGS=${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:${VERSION}-${{ matrix.suffix }}" >> $GITHUB_OUTPUT | |
| fi | |
| elif [[ $GITHUB_REF == refs/heads/* ]]; then | |
| # Branch push: only create branch tags | |
| BRANCH=${GITHUB_REF#refs/heads/} | |
| echo "BRANCH=$BRANCH" >> $GITHUB_OUTPUT | |
| echo "TAGS=${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:${BRANCH}-${{ matrix.suffix }}" >> $GITHUB_OUTPUT | |
| else | |
| # PR: only create PR tags | |
| echo "TAGS=${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:pr-${{ github.event.number }}-${{ matrix.suffix }}" >> $GITHUB_OUTPUT | |
| fi | |
| - name: Build and push Docker image | |
| uses: docker/build-push-action@v5 | |
| with: | |
| context: . | |
| platforms: ${{ matrix.platform }} | |
| push: true | |
| tags: ${{ steps.version.outputs.TAGS }} | |
| build-args: | | |
| ENABLE_PUPPETEER=${{ matrix.enable_puppeteer }} | |
| cache-from: type=gha | |
| cache-to: type=gha,mode=max | |
| # Create multi-arch manifest | |
| manifest: | |
| runs-on: ubuntu-latest | |
| needs: build | |
| if: github.event_name == 'push' && (github.ref == 'refs/heads/main' || startsWith(github.ref, 'refs/tags/v')) | |
| permissions: | |
| contents: read | |
| packages: write | |
| steps: | |
| - name: Log in to Container Registry | |
| uses: docker/login-action@v3 | |
| with: | |
| registry: ${{ env.REGISTRY }} | |
| username: ${{ github.actor }} | |
| password: ${{ secrets.GITHUB_TOKEN }} | |
| - name: Extract version | |
| id: version | |
| run: | | |
| if [[ $GITHUB_REF == refs/tags/* ]]; then | |
| VERSION=${GITHUB_REF#refs/tags/} | |
| echo "VERSION=$VERSION" >> $GITHUB_OUTPUT | |
| if [[ $VERSION == v* ]]; then | |
| echo "TAG_TYPE=version" >> $GITHUB_OUTPUT | |
| echo "CREATE_LATEST=true" >> $GITHUB_OUTPUT | |
| else | |
| echo "TAG_TYPE=version" >> $GITHUB_OUTPUT | |
| echo "CREATE_LATEST=false" >> $GITHUB_OUTPUT | |
| fi | |
| elif [[ $GITHUB_REF == refs/heads/* ]]; then | |
| BRANCH=${GITHUB_REF#refs/heads/} | |
| echo "BRANCH=$BRANCH" >> $GITHUB_OUTPUT | |
| echo "TAG_TYPE=branch" >> $GITHUB_OUTPUT | |
| echo "CREATE_LATEST=false" >> $GITHUB_OUTPUT | |
| fi | |
| - name: Create and push multi-arch manifest | |
| run: | | |
| # Create latest manifest only for v* tags | |
| if [[ "${{ steps.version.outputs.CREATE_LATEST }}" == "true" ]]; then | |
| docker buildx imagetools create \ | |
| --tag ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:latest \ | |
| ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:latest-amd64 \ | |
| ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:latest-arm64 | |
| echo "Created multi-arch manifest: latest" | |
| fi | |
| # Create additional manifest based on tag type | |
| if [[ "${{ steps.version.outputs.TAG_TYPE }}" == "version" ]]; then | |
| # Create version manifest | |
| docker buildx imagetools create \ | |
| --tag ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:${{ steps.version.outputs.VERSION }} \ | |
| ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:${{ steps.version.outputs.VERSION }}-amd64 \ | |
| ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:${{ steps.version.outputs.VERSION }}-arm64 | |
| echo "Created multi-arch manifest: ${{ steps.version.outputs.VERSION }}" | |
| elif [[ "${{ steps.version.outputs.TAG_TYPE }}" == "branch" ]]; then | |
| # Create branch manifest | |
| docker buildx imagetools create \ | |
| --tag ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:${{ steps.version.outputs.BRANCH }} \ | |
| ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:${{ steps.version.outputs.BRANCH }}-amd64 \ | |
| ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:${{ steps.version.outputs.BRANCH }}-arm64 | |
| echo "Created multi-arch manifest: ${{ steps.version.outputs.BRANCH }}" | |
| fi |