name: Build and Push Docker Image to Aliyun Registry on: push: branches: - main tags: - 'v*' pull_request: branches: - main workflow_dispatch: env: REGISTRY: ${{ secrets.ALIYUN_REGISTRY }} IMAGE_NAME: ${{ secrets.IMAGE_NAME || github.repository }} jobs: build-and-push: runs-on: ubuntu-latest steps: - name: Checkout code uses: actions/checkout@v4 - name: Set up Docker Buildx uses: docker/setup-buildx-action@v3 - name: Log in to Aliyun Container Registry uses: docker/login-action@v3 with: registry: ${{ env.REGISTRY }} username: ${{ secrets.ALIYUN_USERNAME }} password: ${{ secrets.ALIYUN_PASSWORD }} - name: Extract metadata id: meta uses: docker/metadata-action@v5 with: images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }} tags: | type=ref,event=branch type=ref,event=pr type=semver,pattern={{version}} type=semver,pattern={{major}}.{{minor}} type=semver,pattern={{major}} type=raw,value=latest,enable={{is_default_branch}} type=raw,value=alpine,enable={{is_default_branch}} labels: | org.opencontainers.image.title=Common Nginx PHP-FPM org.opencontainers.image.description=A common Nginx + PHP-FPM Docker image with Alpine Linux org.opencontainers.image.vendor=Common Docker Images - name: Build and push Docker image uses: docker/build-push-action@v5 id: build with: context: . file: ./Dockerfile push: true tags: ${{ steps.meta.outputs.tags }} labels: ${{ steps.meta.outputs.labels }} platforms: linux/amd64 cache-from: type=gha cache-to: type=gha,mode=max - name: Image digest run: echo ${{ steps.build.outputs.digest }} - name: Update deployment status if: github.event_name == 'push' && github.ref == 'refs/heads/main' run: | echo "✅ Docker image built and pushed successfully!" echo "🏷️ Tags: ${{ steps.meta.outputs.tags }}" echo "📦 Registry: ${{ env.REGISTRY }}" echo "🖼️ Image: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}"