83 lines
2.3 KiB
YAML
83 lines
2.3 KiB
YAML
# CI Image Builder Workflow
|
|
# Automatically builds and pushes CI images when dependencies change
|
|
# Uses GitHub Container Registry (GHCR) or any container registry
|
|
|
|
name: CI Image Builder
|
|
|
|
on:
|
|
push:
|
|
branches:
|
|
- main
|
|
paths:
|
|
- 'package.json'
|
|
- 'package-lock.json'
|
|
- 'Dockerfile.ci'
|
|
- '.gitea/workflows/ci-image-builder.yml'
|
|
workflow_dispatch:
|
|
inputs:
|
|
force_rebuild:
|
|
description: 'Force rebuild even if no changes detected'
|
|
required: false
|
|
default: 'false'
|
|
type: boolean
|
|
|
|
env:
|
|
# Use GHCR or your own registry
|
|
REGISTRY: ghcr.io
|
|
IMAGE_NAME: ${{ github.repository }}/ci-runner
|
|
|
|
jobs:
|
|
build-and-push:
|
|
runs-on: ubuntu-latest
|
|
permissions:
|
|
contents: read
|
|
packages: write
|
|
|
|
steps:
|
|
- name: Checkout code
|
|
uses: actions/checkout@v4
|
|
|
|
- name: Set up Docker Buildx
|
|
uses: docker/setup-buildx-action@v3
|
|
|
|
- name: Log in to Container Registry
|
|
uses: docker/login-action@v3
|
|
with:
|
|
registry: ${{ env.REGISTRY }}
|
|
username: ${{ github.actor }}
|
|
password: ${{ secrets.GITHUB_TOKEN }}
|
|
|
|
- name: Extract metadata
|
|
id: meta
|
|
uses: docker/metadata-action@v5
|
|
with:
|
|
images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}
|
|
tags: |
|
|
type=sha,prefix={{branch}}-
|
|
type=ref,event=branch
|
|
type=ref,event=pr
|
|
type=raw,value=latest,enable={{is_default_branch}}
|
|
|
|
- name: Build and push CI image
|
|
uses: docker/build-push-action@v5
|
|
with:
|
|
context: .
|
|
file: Dockerfile.ci
|
|
push: true
|
|
tags: ${{ steps.meta.outputs.tags }}
|
|
labels: ${{ steps.meta.outputs.labels }}
|
|
cache-from: type=gha
|
|
cache-to: type=gha,mode=max
|
|
|
|
- name: Update workflow documentation
|
|
run: |
|
|
echo "CI Image built and pushed successfully!"
|
|
echo ""
|
|
echo "Available tags:"
|
|
echo " - ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:latest"
|
|
echo " - ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:${{ github.sha }}"
|
|
echo ""
|
|
echo "To use in workflows:"
|
|
echo " container:"
|
|
echo " image: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:latest"
|