mirror of
https://github.com/smittix/intercept.git
synced 2026-04-24 22:59:59 -07:00
70 lines
1.9 KiB
YAML
70 lines
1.9 KiB
YAML
name: Build and Push Docker Image
|
|
|
|
on:
|
|
push:
|
|
branches: [main]
|
|
tags: ["v*"]
|
|
pull_request:
|
|
branches: [main]
|
|
|
|
# Set permissions for GITHUB_TOKEN
|
|
permissions:
|
|
contents: read
|
|
packages: write
|
|
|
|
jobs:
|
|
build:
|
|
runs-on: ubuntu-latest
|
|
|
|
steps:
|
|
# Step 1: Check out the repository code
|
|
- name: Checkout
|
|
uses: actions/checkout@v4
|
|
|
|
# Step 2: Set up QEMU for multi-arch builds
|
|
- name: Set up QEMU
|
|
uses: docker/setup-qemu-action@v3
|
|
|
|
# Step 3: Set up Docker Buildx for advanced features
|
|
- name: Set up Docker Buildx
|
|
uses: docker/setup-buildx-action@v3
|
|
|
|
# Step 4: Log in to GitHub Container Registry
|
|
- name: Log in to GHCR
|
|
uses: docker/login-action@v3
|
|
with:
|
|
registry: ghcr.io
|
|
username: ${{ github.actor }}
|
|
password: ${{ secrets.GITHUB_TOKEN }}
|
|
|
|
# Step 5: Generate tags and labels from Git metadata
|
|
- name: Extract metadata
|
|
id: meta
|
|
uses: docker/metadata-action@v5
|
|
with:
|
|
images: ghcr.io/${{ github.repository }}
|
|
tags: |
|
|
# Tag with branch name
|
|
type=ref,event=branch
|
|
# Tag with PR number
|
|
type=ref,event=pr
|
|
# Tag with semver from git tag
|
|
type=semver,pattern={{version}}
|
|
type=semver,pattern={{major}}.{{minor}}
|
|
# Tag with short SHA
|
|
type=sha,prefix=
|
|
|
|
# Step 6: Build and push the Docker image
|
|
- name: Build and push
|
|
uses: docker/build-push-action@v5
|
|
with:
|
|
context: .
|
|
platforms: linux/amd64,linux/arm64
|
|
# Only push on main branch and tags, not PRs
|
|
push: ${{ github.event_name != 'pull_request' }}
|
|
tags: ${{ steps.meta.outputs.tags }}
|
|
labels: ${{ steps.meta.outputs.labels }}
|
|
# Enable build cache for faster builds
|
|
cache-from: type=gha
|
|
cache-to: type=gha,mode=max
|