refactor: Update cd.yml workflow to checkout repository and ensure re… #65
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: Docker Build | |
on: | |
workflow_dispatch: | |
schedule: | |
- cron: "0 10 * * *" # Run every day at 10:00 UTC for `nightly` tag | |
push: | |
tags: | |
- "v*" # Run on version tags only | |
branches: | |
- main # Run on main branch pushes | |
pull_request: | |
branches: | |
- main # Run on main branch pull requests | |
jobs: | |
docker: | |
name: Build and Push Docker Image | |
runs-on: ubuntu-latest | |
permissions: | |
contents: read | |
packages: write | |
strategy: | |
matrix: | |
platform: [linux/amd64, linux/arm64] | |
steps: | |
- name: Checkout Repository | |
uses: actions/checkout@v4 | |
- name: Generate Docker Build Metadata | |
id: meta | |
uses: docker/metadata-action@v5 | |
with: | |
images: | | |
ghcr.io/mountaingod2/chaturbate_poller | |
docker.io/mountaingod2/chaturbate_poller | |
tags: | | |
type=schedule,pattern=nightly | |
type=ref,event=branch | |
type=ref,event=pr | |
type=semver,pattern={{version}} | |
type=semver,pattern={{major}}.{{minor}} | |
type=semver,pattern={{major}} | |
type=sha | |
- name: Set up QEMU | |
uses: docker/setup-qemu-action@v3 | |
- name: Set up Docker Buildx | |
uses: docker/setup-buildx-action@v3 | |
with: | |
driver-opts: network=host | |
- name: Login to Docker Hub | |
if: github.event_name == 'push' || github.event_name == 'schedule' | |
uses: docker/login-action@v3 | |
with: | |
username: ${{ secrets.DOCKERHUB_USERNAME }} | |
password: ${{ secrets.DOCKERHUB_TOKEN }} | |
- name: Login to GitHub Container Registry | |
if: github.event_name == 'push' || github.event_name == 'schedule' | |
uses: docker/login-action@v3 | |
with: | |
registry: ghcr.io | |
username: ${{ github.repository_owner }} | |
password: ${{ secrets.GITHUB_TOKEN }} | |
- name: Build and Push Docker Image | |
uses: docker/build-push-action@v6 | |
with: | |
push: ${{ github.event_name != 'pull_request' }} | |
tags: ${{ steps.meta.outputs.tags }} | |
labels: ${{ steps.meta.outputs.labels }} | |
platforms: linux/amd64,linux/arm64 | |
annotations: ${{ steps.meta.outputs.annotations }} | |
- name: Clean up Buildx | |
if: always() | |
run: docker buildx rm mybuilder || true |