common-nginx-fpm/.github/workflows/docker-build-push.yml
Caijinglong 0f32a29a0b
Some checks failed
Build and Push Docker Image to Aliyun Registry / build-and-push (push) Has been cancelled
CI: 更新了构建,仅使用 github action 缓存
Signed-off-by: Caijinglong <cjl_spy@163.com>
2025-06-26 10:38:30 +08:00

103 lines
3.1 KiB
YAML

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 || 'common-nginx-fpm' }}
NAMESPACE: ${{ secrets.ALIYUN_NAMESPACE }}
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: Debug registry information
run: |
echo "Registry: ${{ env.REGISTRY }}"
echo "Image Name: ${{ env.IMAGE_NAME }}"
echo "Full Image: ${{ env.REGISTRY }}/${{ env.NAMESPACE }}/${{ env.IMAGE_NAME }}"
echo "Generated Tags:"
echo "${{ steps.meta.outputs.tags }}"
- name: Build Docker image
uses: docker/build-push-action@v5
id: build
with:
context: .
file: ./Dockerfile
push: false
load: 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: Push Docker image
uses: docker/build-push-action@v5
id: push
with:
context: .
file: ./Dockerfile
push: true
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
platforms: linux/amd64
cache-from: type=gha
- name: Build and Push Results
run: |
echo "✅ Build completed successfully!"
echo "Build digest: ${{ steps.build.outputs.digest }}"
echo "✅ Push completed successfully!"
echo "Push digest: ${{ steps.push.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 }}"