|
|
name: Build and Push Docker Image |
|
|
|
|
|
on: |
|
|
push: |
|
|
branches: [ main ] |
|
|
pull_request: |
|
|
types: [ closed ] |
|
|
branches: [ main ] |
|
|
|
|
|
jobs: |
|
|
build-and-push: |
|
|
runs-on: ubuntu-latest |
|
|
|
|
|
if: github.event_name == 'push' || (github.event_name == 'pull_request' && github.event.pull_request.merged == true) |
|
|
|
|
|
steps: |
|
|
- name: Checkout code |
|
|
uses: actions/checkout@v4 |
|
|
|
|
|
- name: Set up QEMU |
|
|
uses: docker/setup-qemu-action@v3 |
|
|
|
|
|
- name: Set up Docker Buildx |
|
|
uses: docker/setup-buildx-action@v3 |
|
|
|
|
|
- name: Login to DockerHub |
|
|
uses: docker/login-action@v3 |
|
|
with: |
|
|
username: ${{ secrets.DOCKERHUB_USERNAME }} |
|
|
password: ${{ secrets.DOCKERHUB_TOKEN }} |
|
|
|
|
|
- name: Extract metadata for Docker |
|
|
id: meta |
|
|
uses: docker/metadata-action@v5 |
|
|
with: |
|
|
images: ${{ secrets.DOCKERHUB_USERNAME }}/duckai |
|
|
tags: | |
|
|
type=sha,format=short |
|
|
type=ref,event=branch |
|
|
type=raw,value=latest,enable=${{ github.ref == 'refs/heads/main' }} |
|
|
|
|
|
- name: Build and push Docker image |
|
|
uses: docker/build-push-action@v5 |
|
|
with: |
|
|
context: . |
|
|
push: true |
|
|
platforms: linux/amd64,linux/arm64 |
|
|
tags: ${{ steps.meta.outputs.tags }} |
|
|
labels: ${{ steps.meta.outputs.labels }} |
|
|
cache-from: type=registry,ref=${{ secrets.DOCKERHUB_USERNAME }}/duckai:buildcache |
|
|
cache-to: type=registry,ref=${{ secrets.DOCKERHUB_USERNAME }}/duckai:buildcache,mode=max |