Nguyen Trung Nghia 6074e31003 init
2025-05-08 16:36:17 +07:00

64 lines
1.8 KiB
YAML

name: Build and Push Docker Image
on:
push:
branches: ["deploy"]
pull_request:
branches: ["deploy"]
env:
REGISTRY: docker.io
IMAGE_NAME: ${{ secrets.DOCKER_HUB_USERNAME }}/landing_929
DOCKERFILE_PATH: ./Dockerfile # Đặt Dockerfile ở thư mục gốc
CONTEXT: . # Đặt context là thư mục gốc
jobs:
build-and-push:
runs-on: ubuntu-latest
permissions:
contents: read
packages: write
steps:
- name: Checkout repository
uses: actions/checkout@v3
- name: Set up QEMU
uses: docker/setup-qemu-action@v2
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v2
- name: Login to Docker Hub
uses: docker/login-action@v2
with:
username: ${{ secrets.DOCKER_HUB_USERNAME }}
password: ${{ secrets.DOCKER_HUB_TOKEN }}
- name: Extract metadata (tags, labels) for Docker
id: meta
uses: docker/metadata-action@v4
with:
images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}
tags: |
type=raw,value=latest
type=raw,value=${{ github.sha }}
type=raw,value=${{ github.ref_name }}-${{ github.run_number }}
type=ref,event=branch
type=ref,event=pr
type=semver,pattern={{version}}
type=semver,pattern={{major}}.{{minor}}
type=semver,pattern={{major}}
type=sha
- name: Build and push Docker image
uses: docker/build-push-action@v4
with:
context: ${{ env.CONTEXT }}
file: ${{ env.DOCKERFILE_PATH }}
push: ${{ github.event_name != 'pull_request' }}
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
cache-from: type=gha
cache-to: type=gha,mode=max