| name: Build and Push to GHCR & ACR |
| |
|
|
| on: |
| push: |
| tags: |
| - 'v*' |
| workflow_dispatch: |
|
|
| jobs: |
| build-and-push: |
| runs-on: ubuntu-latest |
|
|
| steps: |
| - name: Checkout code |
| uses: actions/checkout@v3 |
|
|
| |
| - name: Set up Docker Buildx |
| uses: docker/setup-buildx-action@v3 |
|
|
| |
| - name: Set up QEMU |
| uses: docker/setup-qemu-action@v3 |
|
|
| |
| - name: Check if ACR registry is set |
| id: check-acr |
| run: | |
| if [ -n "${{ secrets.ACR_REGISTRY }}" ]; then |
| echo "acr_enabled=true" >> $GITHUB_OUTPUT |
| else |
| echo "acr_enabled=false" >> $GITHUB_OUTPUT |
| fi |
| |
| |
| - name: Log in to Aliyun ACR |
| if: steps.check-acr.outputs.acr_enabled == 'true' |
| uses: docker/login-action@v3 |
| with: |
| registry: ${{ secrets.ACR_REGISTRY }} |
| username: ${{ secrets.ACR_USERNAME }} |
| password: ${{ secrets.ACR_PASSWORD }} |
|
|
| |
| - name: Log in to GitHub Container Registry |
| uses: docker/login-action@v3 |
| with: |
| registry: ghcr.io |
| username: ${{ github.actor }} |
| password: ${{ secrets.GITHUB_TOKEN }} |
|
|
| |
| - name: Get lowercase repository owner |
| id: lowercase |
| run: echo "repository_owner_lowercase=$(echo '${{ github.repository_owner }}' | tr '[:upper:]' '[:lower:]')" >> $GITHUB_OUTPUT |
|
|
| |
| - name: Prepare tags |
| id: tags |
| run: | |
| REPO_LOWERCASE="ghcr.io/${{ steps.lowercase.outputs.repository_owner_lowercase }}/open-web-search" |
| VERSION_TAG="${GITHUB_REF##*/}" |
| TAGS="${REPO_LOWERCASE}:latest,${REPO_LOWERCASE}:${VERSION_TAG}" |
| |
| if [ "${{ steps.check-acr.outputs.acr_enabled }}" == "true" ] && [ -n "${{ secrets.ACR_IMAGE_NAME }}" ]; then |
| ACR_REPO="${{ secrets.ACR_REGISTRY }}/${{ secrets.ACR_IMAGE_NAME }}" |
| TAGS="${TAGS},${ACR_REPO}:latest,${ACR_REPO}:${VERSION_TAG}" |
| fi |
|
|
| |
| echo "tags<<EOF" >> $GITHUB_OUTPUT |
| echo "$TAGS" >> $GITHUB_OUTPUT |
| echo "EOF" >> $GITHUB_OUTPUT |
|
|
| |
| - name: Build and Push Multi-Platform Docker Image |
| uses: docker/build-push-action@v5 |
| with: |
| context: . |
| platforms: linux/amd64,linux/arm64 |
| push: true |
| tags: ${{ steps.tags.outputs.tags }} |
| cache-from: type=gha |
| cache-to: type=gha,mode=max |
|
|